Skip to content

Instantly share code, notes, and snippets.

@thaddeusc1
Last active June 23, 2023 01:45
Show Gist options
  • Save thaddeusc1/5facee9cb7cb08ab155d6f5a75a737ca to your computer and use it in GitHub Desktop.
Save thaddeusc1/5facee9cb7cb08ab155d6f5a75a737ca to your computer and use it in GitHub Desktop.
Provision my commonly-used applications on new Ubuntu 20 installs/accounts
#!/usr/bin/env bash
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
readonly ERROR_ASSERT_FAIL=1
readonly status_grep_lines_selected=0
readonly status_grep_no_lines_selected=1
readonly CLI_PROFILE="${HOME}/.bashrc"
setupEnvVar() # $1=name $2=value
{
local -r ENV_VAR_SETUP_OK=0
local -r INVALID_NAME=1
local -r INVALID_VALUE=2
local -r NAME_CURRENTLY_IN_USE=3
local -r SAVE_TO_PROFILE_FAIL=4
if [ -z "$1" ]
then
return "$INVALID_NAME"
fi
if [ -z "$2" ]
then
return "$INVALID_VALUE"
fi
if [ -v "$1" ]
then
return "$NAME_CURRENTLY_IN_USE"
fi
export "${1}=${2}"; if [ "$?" -eq 0 ]
then
echo "export ${1}=${2}" | tee --append "$CLI_PROFILE"; if [ "$?" -eq 0 ]
then
# Assume `echo` is always successful
return "$ENV_VAR_SETUP_OK"
else
return "$SAVE_TO_PROFILE_FAIL"
fi
else
# For more about why `export` fails, see: https://manpages.ubuntu.com/manpages/focal/en/man1/bash.1.html#shell%20builtin%20commands
return "$INVALID_NAME"
fi
}
assertContinueOnSuccess() # $1=line number of the command that is being asserted to have completed successfully.
{
local -r OUTCOME="$?"
local LOCATION="<unknown>"
if [ -n "$1" ]
then
LOCATION="$1"
fi
if [ "$OUTCOME" -ne 0 ]
then
echo "The operation at line ${LOCATION} failed with result ${OUTCOME}"
exit "$ERROR_ASSERT_FAIL"
else
return 0
fi
}
# Choose a local Ubuntu repository mirror
software-properties-gtk
sudo apt install --assume-yes \
curl \
mesa-utils \
mesa-utils-extra \
clinfo \
nano \
synaptic \
gnome-dictionary \
s-tui \
lm-sensors \
sensible-utils \
epiphany-browser \
build-essential \
gcc-10 \
g++-10 \
clang \
cmake-gui \
git \
unzip \
nvme-cli
assertContinueOnSuccess "$((${LINENO} - (${LINENO} - 70)))"
setupEnvVar 'EDITOR' "\"`which nano`\""; assertContinueOnSuccess "$LINENO"
gtk-launch org.gnome.Epiphany
sudo update-alternatives --remove-all cc
sudo update-alternatives --remove-all c++
sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 75; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 75; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 100; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --set gcc /usr/bin/gcc-10; assertContinueOnSuccess "$LINENO"
sudo update-alternatives --set g++ /usr/bin/g++-10; assertContinueOnSuccess "$LINENO"
# Work-around `snap install` defect where `snap` can only install multiple apps when invoked with a list of multiple app IDs if and only if *none* of the apps are installed.
# See also: https://askubuntu.com/questions/1232034/problem-when-trying-to-install-multiple-apps-with-snap
SNAP_APPS="htop 1password chromium teams"
sudo snap refresh
for snapApp in $SNAP_APPS
do
sudo snap install $snapApp; assertContinueOnSuccess "${LINENO} (snapApp=${snapApp})"
done
gtk-launch 1password_1password
sudo snap install --beta steam
sudo snap install --classic code; assertContinueOnSuccess "$LINENO"
setupEnvVar 'VISUAL' "\"`which code` -w\""; assertContinueOnSuccess "$LINENO"
xdg-mime default code_code.desktop text/plain; assertContinueOnSuccess "$LINENO"
readonly ORIGINAL_IFS="$IFS"
IFS='/'
SCRIPT_NAME=''
for i in $0
do
SCRIPT_NAME=$i
done
IFS="$ORIGINAL_IFS"
DL_STORAGE=`mktemp --directory --tmpdir "${SCRIPT_NAME}-XXXXXXXXXX"`; assertContinueOnSuccess "$LINENO"
chmod a+rx "$DL_STORAGE"
# Microsoft's Edge package does **not** install signing keys required for future updates via `apt`
# See also: https://docs.microsoft.com/en-us/windows-server/administration/linux-package-repository-for-microsoft-software#configuring-the-repositories
curl --location https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl --location 'https://go.microsoft.com/fwlink?linkid=2149051&brand=M022' --output "${DL_STORAGE}/microsoft-edge.deb"; assertContinueOnSuccess "$LINENO"
sudo apt install -y "${DL_STORAGE}/microsoft-edge.deb"; assertContinueOnSuccess "$LINENO"
curl --location 'https://discord.com/api/download?platform=linux&format=deb' --output "${DL_STORAGE}/discord.deb"; assertContinueOnSuccess "$LINENO"
sudo apt install -y "${DL_STORAGE}/discord.deb"; assertContinueOnSuccess "$LINENO"
mkdir "${HOME}/.local"
mkdir "${HOME}/.local/bin"
sudo mkdir "/usr/local/etc"
sudo mkdir "/usr/local/etc/systemd"
sudo mkdir "/usr/local/etc/systemd/system"
sudo mkdir "/usr/local/etc/tlp.d"
sudo mkdir "/usr/local/etc/sensors.d"
sudo mkdir "/usr/local/lib/modules-load.d"
curl --location 'https://gist.github.com/thaddeusc1/b4eebd7ab9f0b5b58d8ba7915437362d/archive/0d4632a77daf2668bbf06a476dee11b28e3c3f5d.zip' --output "${DL_STORAGE}/provision-istat-server.zip"; assertContinueOnSuccess "$LINENO"
unzip "${DL_STORAGE}/provision-istat-server.zip" 'b4eebd7ab9f0b5b58d8ba7915437362d-0d4632a77daf2668bbf06a476dee11b28e3c3f5d/provision-istat-server.sh' -d "$DL_STORAGE"; assertContinueOnSuccess "$LINENO"
cp "${DL_STORAGE}/b4eebd7ab9f0b5b58d8ba7915437362d-0d4632a77daf2668bbf06a476dee11b28e3c3f5d/provision-istat-server.sh" "${HOME}/.local/bin/provision-istat-server.sh"; assertContinueOnSuccess "$LINENO"
chmod a+x "${HOME}/.local/bin/provision-istat-server.sh"; assertContinueOnSuccess "$LINENO"
lsmod | grep --max-count=1 --quiet amdgpu
if [ "$?" -eq "${status_grep_lines_selected}" ]
then
groups | grep --quiet video
if [ "$?" -eq "${status_grep_no_lines_selected}" ]
then
sudo usermod -a -G video "${LOGNAME}"
echo 'ADD_EXTRA_GROUPS=1' | sudo tee --append /etc/adduser.conf
echo 'EXTRA_GROUPS=video' | sudo tee --append /etc/adduser.conf
fi
groups | grep --quiet render
if [ "$?" -eq "${status_grep_no_lines_selected}" ]
then
sudo usermod -a -G render "${LOGNAME}"
echo 'EXTRA_GROUPS=render' | sudo tee --append /etc/adduser.conf
fi
fi
# Manual installations
# --------------------
# PWA/Web apps in Gnome Web
# iCloud URI elements
# -------------------
# These elements appear to be static values.
icloudBaseUri='https://www.icloud.com/system/cloudos2'
icloudLocale='en-us'
icloudAppIconPrefix='r$__'
icloudAppIconType='png'
# These elements appear to change over time.
icloudProject='2213Project42'
driveAppIconId=31
notesAppIconId=40
remindersAppIconId=18
pagesAppIconId=22
numbersAppIconId=51
keynoteAppIconId=26
icloudAppIconBaseUri="${icloudBaseUri}/${icloudProject}/${icloudLocale}"
mkdir "${HOME}/iCloud"
gtk-launch org.gnome.Epiphany
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${notesAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/Notes.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/notes/'
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${driveAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/iCloud Drive.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/iclouddrive/'
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${remindersAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/Reminders.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/reminders/'
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${pagesAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/Pages.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/pages/'
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${numbersAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/Numbers.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/numbers/'
curl "${icloudAppIconBaseUri}/${icloudAppIconPrefix}${keynoteAppIconId}.${icloudAppIconType}" --output "${HOME}/Pictures/Keynote.png"; assertContinueOnSuccess "$LINENO"
epiphany 'https://www.icloud.com/keynote/'
# PWA/Web apps in Microsoft Edge
gtk-launch microsoft-edge 'https://www.outlook.com/'
gtk-launch microsoft-edge 'https://www.pandora.com/'
echo "Manual installations"
echo "--------------------"
echo "Install the latest version of the Phoronix Test Suite (PTS)"
epiphany 'https://www.phoronix-test-suite.com/?k=downloads'
echo "sensors-detect"
echo "Add non-standard sensor kernel modules to /usr/local/etc/load-modules.d"
echo "Configure sensor names (if needed) to /usr/local/etc/sensors.d"
echo "Build and install istat-server with ${HOME}/.local/bin/provision-istat-server.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment