summaryrefslogtreecommitdiff
path: root/static/thesiah-debian.sh
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2024-04-29 10:16:09 -0400
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2024-04-29 10:16:09 -0400
commit2cd42b9d71238abc14748566134ead380d5f0969 (patch)
tree03b479b0d92781add4c196bb515886f0b981e842 /static/thesiah-debian.sh
Init
Diffstat (limited to 'static/thesiah-debian.sh')
-rwxr-xr-xstatic/thesiah-debian.sh175
1 files changed, 175 insertions, 0 deletions
diff --git a/static/thesiah-debian.sh b/static/thesiah-debian.sh
new file mode 100755
index 0000000..ac2ef96
--- /dev/null
+++ b/static/thesiah-debian.sh
@@ -0,0 +1,175 @@
+#!/bin/sh
+
+# Soomin's Auto Rice Bootstrapping Script (THESIAH) adapted for debian
+# Adaptation by: Soomin Im <si@thesiah.xyz>
+# License: GNU GPLv3
+
+
+### VARIABLES ###
+dotfilesrepo="https://github.com/thesiah/.dotfiles.git"
+progsfile="https://raw.githubusercontent.com/thesiah/THESIAH/main/static/debianprogs.csv"
+repobranch="master"
+export TERM=ansi
+
+
+### FUNCTIONS ###
+installpkg() {
+ DEBIAN_FRONTEND=noninteractive apt-get install -y "$1" >/dev/null 2>&1 || error "Failed to install $1"
+}
+
+error() {
+ whiptail --title "Error" --msgbox "An error occurred: $1" 8 78
+ exit 1
+}
+
+welcomemsg() {
+ whiptail --title "Welcome!" \
+ --msgbox "Welcome to Soomin's Auto-Rice Bootstrapping Script for Debian! This script will automatically install a fully-featured Linux desktop, which I use as my main machine." 12 60
+}
+
+getuserandpass() {
+ name=$(whiptail --inputbox "Please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || error "User exited."
+ pass=$(whiptail --passwordbox "Enter a password for the user." 10 60 3>&1 1>&2 2>&3 3>&1) || error "User exited."
+ pass2=$(whiptail --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) || error "User exited."
+ while ! [ "$pass" = "$pass2" ]; do
+ pass=$(whiptail --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1)
+ pass2=$(whiptail --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1)
+ done
+}
+
+usercheck() {
+ if id "$name" &>/dev/null; then
+ whiptail --yesno "The user $name already exists. Do you want to continue?" 8 78 || error "User exited."
+ fi
+}
+
+preinstallmsg() {
+ whiptail --title "Ready to start?" --yesno "The rest of the installation will now be totally automated. Press Yes to continue." 8 78 || error "User exited."
+}
+
+adduserandpass() {
+ whiptail --infobox "Adding user \"$name\"..." 7 50
+ adduser --disabled-password --gecos "" "$name" || error "Failed to add user $name"
+ echo "$name:$pass1" | chpasswd
+ usermod -aG sudo "$name"
+
+ export repodir="/home/$name/.local/src"
+ mkdir -p "$repodir"
+ chown -R "$name": "$repodir"
+
+ unset pass1 pass2
+
+ trap 'rm -f /etc/sudoers.d/thesiah-temp' HUP INT QUIT TERM PWR EXIT
+ echo "$name ALL=(ALL) NOPASSWD: ALL Defaults:$name runcwd=*" >/etc/sudoers.d/thesiah-temp
+}
+
+installationloop() {
+ ([ -f "$progsfile" ] && cp "$progsfile" /tmp/progs.csv) || curl -Ls "$progsfile" | sed '/^#/d' >/tmp/progs.csv
+ total=$(wc -l </tmp/progs.csv)
+ while IFS=, read -r tag program comment; do
+ case "$tag" in
+ "G") gitcloneinstall "$program" "$comment" ;;
+ "P") pipinstall "$program" ;;
+ *) installpkg "$program" ;;
+ esac
+ done </tmp/progs.csv
+}
+
+putgitrepo() {
+ whiptail --infobox "Downloading and installing config files..." 7 60
+ [ -z "$3" ] && branch="main" || branch="$3"
+ dir=$(mktemp -d)
+ [ ! -d "$2" ] && mkdir -p "$2"
+ sudo -u "$name" git -C "$repodir" clone --depth 1 \
+ --single-branch --no-tags -q --recursive -b "$branch" \
+ --recurse-submodules "$1" "$dir"
+ sudo -u "$name" cp -rfT "$dir" "$2"
+}
+
+pipinstall() {
+ whiptail --title "SI Installation" \
+ --infobox "Installing the Python package \`$1\` ($n of $total). $1 $2" 9 70
+ [ -x "$(command -v "pip")" ] || installpkg python-pip >/dev/null 2>&1
+ yes | pip install "$1"
+}
+
+vimplugininstall() {
+ # Installs vim plugins.
+ whiptail --infobox "Installing vim plugins..." 7 60
+ mkdir -p "/home/$name/.vim/autoload"
+ curl -Ls "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" >"/home/$name/.vim/autoload/plug.vim"
+ chown -R "$name:$name" "/home/$name/.vim" # Changed to use user's group
+ sudo -u "$name" vim -c "PlugInstall|q|q"
+}
+
+addsudo() {
+ echo "$name ALL=(ALL:ALL) ALL" >/etc/sudoers.d/00-thesiah-user-can-sudo
+ echo "$name ALL=(ALL:ALL) NOPASSWD: /usr/bin/shutdown,/usr/bin/reboot,/usr/bin/systemctl suspend,/usr/bin/wifi-menu,/usr/bin/mount,/usr/bin/umount,/usr/bin/apt update,/usr/bin/apt upgrade,/usr/bin/apt upgrade -y,/usr/bin/loadkeys,/usr/bin/apt-get --download-only upgrade" >/etc/sudoers.d/01-thesiah-cmds-without-password
+ echo "Defaults editor=/usr/bin/nvim" >/etc/sudoers.d/02-thesiah-visudo-editor
+ mkdir -p /etc/sysctl.d
+ echo "kernel.dmesg_restrict = 0" >/etc/sysctl.d/dmesg.conf
+}
+
+finalize() {
+ whiptail --title "All done!" \
+ --msgbox "Congrats! Provided there were no hidden errors, the script completed successfully and all the programs and configuration files should be in place.\\n\\nTo run the new graphical environment, log out and log back in as your new user, then run the command \"startx\" to start the graphical environment (it will start automatically in tty1).\\n\\n.t Soomin" 13 80
+}
+
+
+### MAIN SCRIPT ###
+if [ "$(id -u)" -ne 0 ]; then
+ echo "This script must be run as root." >&2
+ exit 1
+fi
+
+essential_packages="curl ca-certificates build-essential git ntp zsh"
+whiptail --title "SI Installation" --infobox "Installing essential packages required to install and configure other programs." 8 70
+for package in $essential_packages; do
+ installpkg $package || error "Failed to install $package"
+done
+
+welcomemsg || error "User exited."
+
+getuserandpass || error "User exited."
+
+usercheck || error "User exited."
+
+preinstallmsg || error "User exited."
+
+adduserandpass || error "Error adding username and/or password."
+
+installationloop
+
+putgitrepo "$dotfilesrepo" "/home/$name" "$repobranch"
+rm -rf "/home/$name/.git/" "/home/$name/README.md" "/home/$name/LICENSE" "/home/$name/FUNDING.yml"
+
+[ ! -f "/home/$name/.vim/autoload/plug.vim" ] && vimplugininstall
+
+rmmod pcspkr
+echo "blacklist pcspkr" >/etc/modprobe.d/nobeep.conf
+
+chsh -s /bin/zsh "$name" >/dev/null 2>&1
+sudo -u "$name" mkdir -p "/home/$name/.cache/zsh/"
+sudo -u "$name" mkdir -p "/home/$name/.config/mpd/playlists/"
+
+# dbus UUID must be generated for Artix runit.
+dbus-uuidgen >/var/lib/dbus/machine-id
+
+# Use system notifications for Brave on Artix
+echo "export \$(dbus-launch)" >/etc/profile.d/dbus.sh
+
+# Enable tap to click
+[ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && printf 'Section "InputClass"
+ Identifier "libinput touchpad catchall"
+ MatchIsTouchpad "on"
+ MatchDevicePath "/dev/input/event*"
+ Driver "libinput"
+ # Enable left mouse button by tapping
+ Option "Tapping" "on"
+EndSection' >/etc/X11/xorg.conf.d/40-libinput.conf
+
+# Allow wheel users to sudo with password and allow several system commands
+# (like `shutdown` to run without password).
+addsudo
+
+finalize