Last active
May 4, 2024 02:26
-
-
Save thaddeusc1/4793e8db75ccaa3bb953cf41da0cab03 to your computer and use it in GitHub Desktop.
Setup account on Ubuntu 22.04 LTS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/jammy/en/man1/bash.1.html#shell%20builtin%20commands | |
return "$INVALID_NAME" | |
fi | |
} | |
assertContinueOnSuccess() # $1=line number of--and/or a comment about--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 | |
} | |
# Early package install | |
# --------------------- | |
# i.e., installs that occur _before_ distribution-specifc provisioning. | |
# These are packages that are supported on all distros, and required to complete | |
# installation of items later in this script. | |
sudo apt update; assertContinueOnSuccess $LINENO | |
sudo apt install --assume-yes apt-utils curl coreutils; assertContinueOnSuccess $LINENO | |
# Configure storage for downloads... | |
# ---------------------------------- | |
# ...in the temporary area of the file-system. | |
# - See also: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s18.html | |
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" | |
if source /etc/os-release | |
then | |
echo "Found distribution ID: '${ID}'" | |
else | |
ID='warn-source-failed'; assertContinueOnSuccess $LINENO | |
fi | |
case "$ID" in | |
"ubuntu") | |
#-------- | |
# Choose a local Ubuntu repository mirror | |
software-properties-gtk | |
sudo apt install --assume-yes epiphany-browser; assertContinueOnSuccess $LINENO | |
sudo apt remove --assume-yes gnome-characters gnome-logs deja-dup; assertContinueOnSuccess $LINENO | |
sudo snap refresh | |
sudo snap install htop 1password chromium gnome-dictionary gnome-logs gnome-characters; assertContinueOnSuccess "$LINENO" | |
sudo snap install --classic deja-dup; assertContinueOnSuccess "$LINENO" | |
# 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 -; assertContinueOnSuccess $LINENO | |
curl --location 'https://go.microsoft.com/fwlink?linkid=2149051' --output "${DL_STORAGE}/microsoft-edge.deb"; assertContinueOnSuccess $LINENO | |
sudo apt install --assume-yes "${DL_STORAGE}/microsoft-edge.deb"; assertContinueOnSuccess $LINENO | |
;; | |
"pop") | |
#----- | |
sudo apt install htop; assertContinueOnSuccess $LINENO | |
readonly lineno_pop_flatpak_start=$LINENO; flatpak install --assumeyes \ | |
org.chromium.Chromium \ | |
org.gnome.Boxes \ | |
org.gnome.Characters \ | |
org.gnome.Dictionary \ | |
org.gnome.Epiphany \ | |
org.gnome.Logs \ | |
org.gnome.Weather \ | |
org.gnome.World.PikaBackup \ | |
com.microsoft.Edge \ | |
com.system76.Popsicle | |
assertContinueOnSuccess $lineno_pop_flatpak_start | |
flatpak install --user --assumeyes --from 'https://downloads.1password.com/linux/flatpak/1Password.flatpakref'; assertContinueOnSuccess $LINENO | |
;; | |
"warn-source-failed") | |
#-------------------- | |
echo 'Warning: Failed to `source` variables from "/etc/os-release".' | |
;; | |
*) | |
# Default case | |
# ------------ | |
echo "Info: No distribution specific actions found for os-release ID '${ID}'." | |
;; | |
esac | |
readonly lineno_any_distro_apt_start=$LINENO; sudo apt install --assume-yes \ | |
moreutils \ | |
mesa-utils \ | |
mesa-utils-extra \ | |
clinfo \ | |
vulkan-tools \ | |
nautilus-admin \ | |
gedit-plugins \ | |
nano \ | |
synaptic \ | |
s-tui \ | |
lm-sensors \ | |
sensible-utils \ | |
build-essential \ | |
gcc-10 \ | |
g++-10 \ | |
gcc-12 \ | |
g++-12 \ | |
clang-15 \ | |
cmake-gui \ | |
git \ | |
unzip \ | |
nvme-cli \ | |
wireshark \ | |
ethtool \ | |
net-tools | |
assertContinueOnSuccess $lineno_any_distro_apt_start | |
sudo dpkg-reconfigure wireshark-common; assertContinueOnSuccess $LINENO # Packet capture for non-root users must be manually enabled. | |
setupEnvVar 'EDITOR' "\"`which nano`\""; assertContinueOnSuccess $LINENO | |
setupEnvVar 'VISUAL' "\"`which gedit` --wait\""; assertContinueOnSuccess $LINENO | |
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-12 50; assertContinueOnSuccess $LINENO | |
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-11 100; assertContinueOnSuccess $LINENO | |
sudo update-alternatives --remove-all g++ | |
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 50; assertContinueOnSuccess $LINENO | |
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++-11 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 | |
#curl --location 'https://discord.com/api/download?platform=linux&format=deb' --output "${DL_STORAGE}/discord.deb"; assertContinueOnSuccess $LINENO | |
#sudo apt install --assume-yes "${DL_STORAGE}/discord.deb"; assertContinueOnSuccess $LINENO | |
curl --location 'https://phoronix-test-suite.com/releases/repo/pts.debian/files/phoronix-test-suite_10.8.4_all.deb' --output "${DL_STORAGE}/pts.deb"; assertContinueOnSuccess $LINENO | |
sudo apt install --assume-yes "${DL_STORAGE}/pts.deb"; assertContinueOnSuccess $LINENO | |
readonly lineno_any_distro_pts_start=$LINENO; sudo apt install --assume-yes \ | |
php-sqlite3 \ | |
php-curl \ | |
php-bz2 \ | |
cryptsetup \ | |
steam-installer | |
assertContinueOnSuccess $lineno_any_distro_pts_start | |
cd ~/Documents; assertContinueOnSuccess $LINENO | |
phoronix-test-suite help # ~/.phoronix-test-suite is provisioned upon first run | |
ln -s ../.phoronix-test-suite ./Phoronix\ Test\ Suite | |
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 | |
groups | grep --quiet video | |
if [ "$?" -eq "${status_grep_no_lines_selected}" ] | |
then | |
sudo usermod --append --groups video "$LOGNAME"; assertContinueOnSuccess $LINENO | |
fi | |
groups | grep --quiet render | |
if [ "$?" -eq "${status_grep_no_lines_selected}" ] | |
then | |
sudo usermod --append --groups render "$LOGNAME"; assertContinueOnSuccess $LINENO | |
fi | |
groups | grep --quiet wireshark | |
if [ "$?" -eq "${status_grep_no_lines_selected}" ] | |
then | |
sudo usermod --append --groups wireshark "$LOGNAME"; assertContinueOnSuccess $LINENO | |
fi | |
echo 'ADD_EXTRA_GROUPS=1' | sudo tee --append /etc/adduser.conf; assertContinueOnSuccess $LINENO | |
echo 'EXTRA_GROUPS="video render wireshark"' | sudo tee --append /etc/adduser.conf; assertContinueOnSuccess $LINENO | |
echo "Manual installations" | |
echo "--------------------" | |
echo "sensors-detect" | |
echo "Add non-standard sensor kernel modules to /usr/local/lib/modules-load.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