Skip to content

Instantly share code, notes, and snippets.

@gabrieleara
Last active April 30, 2020 13:20
Show Gist options
  • Select an option

  • Save gabrieleara/a47bf20558ac7e46eaa8afe1e25e3b24 to your computer and use it in GitHub Desktop.

Select an option

Save gabrieleara/a47bf20558ac7e46eaa8afe1e25e3b24 to your computer and use it in GitHub Desktop.
Simple post installation script to install some stuff on Ubuntu 20.04+
#!/bin/bash
# First argument is the link to the deb file to download
function download_install_deb() {
wget -O /tmp/installer.deb "$1"
dpkg -i /tmp/installer.deb || apt install -f -y
rm /tmp/installer.deb
}
(
set -e
if [ "$EUID" -ne 0 ]; then
echo "Please run with sudo command."
echo "NOTICE: DO NOT RUN THIS IN LOG IN SHELL WHEN LOGGING IN AS ROOT!"
echo "YOUR \`logname\` OUTPUT MUST BE THE DESIRED USER PROGRAMS SHOULD BE INSTALLED FOR"
false
fi
USERNAME=$(logname)
# MACROS
APT_INSTALL="apt install -y"
APT_INSTALL_SUGGESTS="apt install --install-suggests -y"
APT_AUTOPURGE="apt autoremove --purge -y"
USERAPPDIR="/home/$USERNAME/.userapps"
USERBINDIR="/home/$USERNAME/.local/bin"
# Creating directories in home to host custom applications and commands
mkdir -p "$USERAPPDIR"
mkdir -p "$USERBINDIR"
# Updating repositories before starting
apt update
# Removing snap and installing gnome-software without snap support
# (exactly in this order, do not change)
$APT_AUTOPURGE snapd
$APT_INSTALL_SUGGESTS gnome-software
$APT_AUTOPURGE gnome-software-plugin-snap snapd
# Remove thunderbird, I just like evolution better
$APT_AUTOPURGE thunderbird
# Install some programs and utilities (NO SUGGESTIONS)
$APT_INSTALL htop mesa-utils mlocate tree build-essential git gnome-tweak-tool \
hwloc cpufrequtils stress gparted gnuplot grub-customizer module-assistant \
apt-file linux-headers-generic manpages-posix manpages-posix-dev colordiff \
valgrind curl vlc chrome-gnome-shell screen xclip
# Install some programs and utilities (SUGGESTIONS INCLUDED)
$APT_INSTALL_SUGGESTS evolution p7zip-full cmake gimp audacity peek
# Install Telegram Desktop
wget -O /tmp/telegram-desktop.tar.xz https://telegram.org/dl/desktop/linux
tar -xf /tmp/telegram-desktop.tar.xz --directory "$USERAPPDIR"
ln -fs "$USERAPPDIR/Telegram/Telegram" "$USERBINDIR/telegram"
# Otherwise Telegram is recognized automatically in the next reboot
echo ""
echo "Telegram Desktop installed as \`$USERBINDIR/telegram\`, to create corresponding desktop file run \`telegram\`"
echo "NOTICE: until your next logout/login there could be some problems if \`$USERBINDIR\` did not exist before running this utility!"
echo ""
# In order: Discord, Google Chrome, VSCode, Skype For Linux
download_install_deb "https://discordapp.com/api/download?platform=linux"
download_install_deb "https://go.microsoft.com/fwlink/?LinkID=760868"
download_install_deb "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
download_install_deb "https://go.skype.com/skypeforlinux-64.deb"
# Installing Spotify
# NOTICE: requires curl for some reason!
# TODO: test if using the following commented line works too when run as root
# wget -nv -O- "https://download.spotify.com/debian/pubkey.gpg" | apt-key add -
curl -sS "https://download.spotify.com/debian/pubkey.gpg" | apt-key add -
echo "deb http://repository.spotify.com stable non-free" | tee /etc/apt/sources.list.d/spotify.list
# Get Spotify repo info
apt update
$APT_INSTALL spotify-client
# Use this only if you have a high-resolution screen (works only after logout/login)
cat >"$USERBINDIR/spotify" <<EOF
#!/bin/sh
exec /usr/bin/spotify --force-device-scale-factor=1.5 "$@"
EOF
chmod +x "$USERBINDIR/spotify"
# Installing Calibre ebook library
wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sh /dev/stdin
# Remember to run:
# git config --global user.name "Gabriele Ara"
# git config --global user.email "[email protected]"
# git config --global user.signingKey #################
# git config --global commit.gpgsign true
# At the moment I'm writing this, Node.js 12.X is the recommended LTS version
curl -sL https://deb.nodesource.com/setup_12.x | bash -
$APT_INSTALL_SUGGESTS nodejs
npm install -g nativefier
# Download the webinstall script
git clone "https://gist.github.com/684882880c8c057858732b5e40032aa8.git" /tmp/webinstall
cp /tmp/webinstall/webinstall "$USERBINDIR/webinstall"
chmod +x "$USERBINDIR/webinstall"
rm -rf /tmp/webinstall/
# Very important, do not forget when done running as superuser!
chown -R $USERNAME:$USERNAME "$USERAPPDIR"
chown -R $USERNAME:$USERNAME "$USERBINDIR"
# Hopefully this will run as the desired user, installing in his home directory
runuser -l $USERNAME -c "$USERBINDIR/webinstall -n 'WhatsApp' --tray --single-instance --honest 'https://web.whatsapp.com'"
runuser -l $USERNAME -c "$USERBINDIR/webinstall -n 'Overleaf' --honest 'https://overleaf.com'"
# Updating software one last time
apt update
apt full-upgrade -y
echo "Software installed and updated!"
echo "I suggest rebooting your machine and run \`sudo $APT_AUTOPURGE\` AFTER rebooting your system"
# # Extra: if you want ZSH run this too, then logout and login:
# $APT_INSTALL_SUGGESTS zsh
# usermod -s $(which zsh) "$USER"
# # If you are already logged as yourself simply run `chsh -s $(which zsh)`, then logout/login
# # When inside ZSH for the first sime, press 2, then, as soon as you get a shell, type this:
# sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# # Well done, now you have ZSH and Oh-my-ZSH installed
# If you want to install LaTeX locally (requires about 5GB)
# $APT_INSTALL texlive-full
# $APT_INSTALL lyx
# If you want to install Rust and Cargo (works after logout/login)
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment