larbs

Luke's Auto-Rice Bootstrapping Scripts: Auto-Setup & Configure Arch Linux
Log | Files | Refs | README | LICENSE

vlarbs.sh (6470B)


      1 #!/bin/sh
      2 # Luke's Auto Rice Boostrapping Script (LARBS)
      3 # by Luke Smith <luke@lukesmith.xyz>
      4 # License: GNU GPLv3
      5 
      6 ### OPTIONS AND VARIABLES ###
      7 
      8 while getopts ":r:p:b:h" o; do case "${o}" in
      9 	h) printf "Optional arguments for custom use:\\n  -r: Dotfiles repository (local file or url)\\n  -b: Dotfiles branch (master is assumed otherwise)\\n  -p: Dependencies and programs csv (local file or url)\\n  -h: Show this message\\n" && exit ;;
     10 	r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit ;;
     11 	b) repobranch=${OPTARG} ;;
     12 	p) progsfile=${OPTARG} ;;
     13 	*) printf "Invalid option: -%s\\n" "$OPTARG" && exit ;;
     14 esac done
     15 
     16 # DEFAULTS:
     17 [ -z "$dotfilesrepo" ] && dotfilesrepo="https://github.com/lukesmithxyz/voidrice.git" && repobranch="voiddwm"
     18 [ -z "$progsfile" ] && progsfile="https://raw.githubusercontent.com/LukeSmithxyz/LARBS/master/voiddwm/vprogs.csv"
     19 [ -z "$repobranch" ] && repobranch="master"
     20 
     21 ### FUNCTIONS ###
     22 
     23 error() { clear; printf "ERROR:\\n%s\\n" "$1"; exit;}
     24 
     25 welcomemsg() { \
     26 	dialog --title "Welcome!" --msgbox "Welcome to Luke's Auto-Rice Bootstrapping Script!\\n\\nThis script will automatically install a fully-featured i3wm Void Linux desktop, which I use as my main machine.\\n\\n-Luke" 10 60
     27 	}
     28 
     29 getuser() { \
     30 	name=$(dialog --inputbox "First, please enter a name for the user account for which you'd like to install LARBS." 10 60 3>&1 1>&2 2>&3 3>&1) || exit
     31 	while ! echo "$name" | grep "^[a-z_][a-z0-9_-]*$" >/dev/null 2>&1; do
     32 		name=$(dialog --no-cancel --inputbox "Username not valid. Give a username beginning with a letter, with only lowercase letters, - or _." 10 60 3>&1 1>&2 2>&3 3>&1)
     33 	done
     34 	! (id -u "$name" >/dev/null) 2>&1 &&
     35 		dialog --title "Create user first then re-run script" --msgbox "Please create your user and password before running LARBS. Note that you can use the user you created in the Void Linux installation process.\\n\\nIf you want to make a new user, you will want to run a command like this, adding your user to all the needed groups and creating a home directory:\\n\\n$ useradd -m -G wheel,users,audio,video,cdrom,input -s /bin/bash <user>\\n$ passwd <user>" 14 75 && exit
     36 	return 0 ;}
     37 
     38 preinstallmsg() { \
     39 	dialog --title "Let's get this party started!" --yes-label "Let's go!" --no-label "No, nevermind!" --yesno "The rest of the installation will now be totally automated, so you can sit back and relax.\\n\\nIt will take some time, but when done, you can relax even more with your complete system.\\n\\nNow just press <Let's go!> and the system will begin installation!" 13 60 || { clear; exit; }
     40 	}
     41 
     42 maininstall() { # Installs all needed programs from main repo.
     43 	dialog --title "LARBS Installation" --infobox "Installing \`$1\` ($n of $total). $1 $2" 5 70
     44 	xbps-install -y "$1" >/dev/null 2>&1
     45 	}
     46 
     47 gitmakeinstall() {
     48 	repo="$(basename "$1")"
     49 	repodir="/home/$name/repos/$repo"
     50 	dialog --title "LARBS Installation" --infobox "Installing \`$(basename "$1")\` ($n of $total) via \`git\` and \`make\`. $(basename "$1") $2" 5 70
     51 	sudo -u "$name" mkdir -p "$repodir"
     52 	sudo -u "$name" git clone --depth 1 "$1" "/home/$name/repos/$repo" >/dev/null 2>&1
     53 	cd "$repodir" || exit
     54 	make install >/dev/null 2>&1
     55 	cd /tmp || return ;}
     56 
     57 pipinstall() { \
     58 	dialog --title "LARBS Installation" --infobox "Installing the Python package \`$1\` ($n of $total). $1 $2" 5 70
     59 	command -v pip || pacman -S --noconfirm --needed python-pip >/dev/null 2>&1
     60 	yes | pip install "$1"
     61 	}
     62 
     63 installationloop() { \
     64 	([ -f "$progsfile" ] && cp "$progsfile" /tmp/progs.csv) || curl -Ls "$progsfile" | sed '/^#/d' > /tmp/progs.csv
     65 	total=$(wc -l < /tmp/progs.csv)
     66 	while IFS=, read -r tag program comment; do
     67 		n=$((n+1))
     68 		echo "$comment" | grep "^\".*\"$" >/dev/null 2>&1 && comment="$(echo "$comment" | sed "s/\(^\"\|\"$\)//g")"
     69 		case "$tag" in
     70 			"") maininstall "$program" "$comment" ;;
     71 			"G") gitmakeinstall "$program" "$comment" ;;
     72 			"P") pipinstall "$program" "$comment" ;;
     73 		esac
     74 	done < /tmp/progs.csv ;}
     75 
     76 putgitrepo() { # Downlods a gitrepo $1 and places the files in $2 only overwriting conflicts
     77 	[ -z "$3" ] && branch="master" || branch="$repobranch"
     78 	dialog --infobox "Downloading and installing config files..." 4 60
     79 	dir=$(mktemp -d)
     80 	[ ! -d "$2" ] && mkdir -p "$2" && chown -R "$name:wheel" "$2"
     81 	chown -R "$name:wheel" "$dir"
     82 	sudo -u "$name" git clone -b "$branch" --depth 1 "$1" "$dir/gitrepo" >/dev/null 2>&1 &&
     83 	sudo -u "$name" cp -rfT "$dir/gitrepo" "$2"
     84 	}
     85 
     86 serviceinit() { for service in "$@"; do
     87 	dialog --infobox "Enabling \"$service\"..." 4 40
     88 	ln -s "/etc/sv/$service" /var/service/
     89 	sv start "$service"
     90 	done ;}
     91 
     92 systembeepoff() { dialog --infobox "Getting rid of that retarded error beep sound..." 10 50
     93 	rmmod pcspkr
     94 	echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf ;}
     95 
     96 finalize(){ \
     97 	dialog --infobox "Preparing welcome message..." 4 50
     98 	dialog --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 Luke" 12 80
     99 	}
    100 
    101 ### THE ACTUAL SCRIPT ###
    102 
    103 ### This is how everything happens in an intuitive format and order.
    104 
    105 # Check if user is root on Arch distro. Install dialog.
    106 xbps-install -Syu dialog
    107 
    108 # Welcome user.
    109 welcomemsg || error "User exited."
    110 
    111 # Get and verify username and password.
    112 getuser || error "User exited."
    113 
    114 # Last chance for user to back out before install.
    115 preinstallmsg || error "User exited."
    116 
    117 ### The rest of the script requires no user input.
    118 
    119 dialog --title "LARBS Installation" --infobox "Installing \`basedevel\` and \`git\` for installing other software." 5 70
    120 xbps-install -y curl base-devel git >/dev/null 2>&1
    121 
    122 # The command that does all the installing. Reads the progs.csv file and
    123 # installs each needed program the way required. Be sure to run this only after
    124 # the user has been created and has priviledges to run sudo without a password
    125 # and all build dependencies are installed.
    126 installationloop
    127 
    128 # Install the dotfiles in the user's home directory
    129 putgitrepo "$dotfilesrepo" "/home/$name" "$repobranch"
    130 rm -f "/home/$name/README.md" "/home/$name/LICENSE"
    131 
    132 # Enable services here.
    133 serviceinit alsa wpa_supplicant dbus
    134 
    135 # Most important command! Get rid of the beep!
    136 systembeepoff
    137 
    138 # Last message! Install complete!
    139 finalize
    140 clear