2019-01-09 00:13:40 +01:00
#!/bin/sh
2018-08-03 23:03:39 +02:00
# Luke's Auto Rice Boostrapping Script (LARBS)
# by Luke Smith <luke@lukesmith.xyz>
# License: GNU GPLv3
2018-08-03 01:23:18 +02:00
### OPTIONS AND VARIABLES ###
2019-05-19 01:35:31 +02:00
while getopts ":r:p:b:h" o; do case " ${ o } " in
2019-05-18 22:47:15 +02:00
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 ; ;
2018-08-27 18:40:33 +02:00
r) dotfilesrepo = ${ OPTARG } && git ls-remote " $dotfilesrepo " || exit ; ;
2019-05-18 22:47:15 +02:00
b) repobranch = ${ OPTARG } ; ;
2018-08-03 06:21:28 +02:00
p) progsfile = ${ OPTARG } ; ;
2019-01-09 00:13:40 +01:00
*) printf "Invalid option: -%s\\n" " $OPTARG " && exit ; ;
2018-08-03 06:21:28 +02:00
esac done
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
# DEFAULTS:
2019-05-19 00:48:14 +02:00
[ -z " $dotfilesrepo " ] && dotfilesrepo = "https://github.com/lukesmithxyz/voidrice.git" && repobranch = "voiddwm"
2019-05-19 01:15:38 +02:00
[ -z " $progsfile " ] && progsfile = "https://raw.githubusercontent.com/LukeSmithxyz/LARBS/master/voiddwm/vprogs.csv"
2019-05-18 22:47:15 +02:00
[ -z " $repobranch " ] && repobranch = "master"
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
### FUNCTIONS ###
2018-08-02 02:25:18 +02:00
2019-01-09 00:53:50 +01:00
error( ) { clear; printf "ERROR:\\n%s\\n" " $1 " ; exit; }
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
welcomemsg( ) { \
2019-05-18 21:47:39 +02:00
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
2018-08-03 01:23:18 +02:00
}
2018-08-02 02:25:18 +02:00
2019-05-28 20:59:48 +02:00
getuser( ) { \
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
2019-01-09 06:51:13 +01:00
while ! echo " $name " | grep " ^[a-z_][a-z0-9_-]* $" >/dev/null 2>& 1; do
2018-08-03 01:23:18 +02:00
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)
done
2019-05-28 20:59:48 +02:00
! ( id -u " $name " >/dev/null) 2>& 1 &&
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
2019-05-28 21:09:35 +02:00
return ; }
2018-08-02 02:25:18 +02:00
2019-01-09 00:13:40 +01:00
preinstallmsg( ) { \
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; }
}
maininstall( ) { # Installs all needed programs from main repo.
dialog --title "LARBS Installation" --infobox " Installing \` $1 \` ( $n of $total ). $1 $2 " 5 70
2019-05-18 21:47:39 +02:00
xbps-install -y " $1 " >/dev/null 2>& 1
2019-01-09 00:13:40 +01:00
}
2018-08-03 06:21:28 +02:00
gitmakeinstall( ) {
2019-05-18 21:47:39 +02:00
repo = " $( basename " $1 " ) "
repodir = " /home/ $name /repos/ $repo "
2018-12-11 22:19:30 +01:00
dialog --title "LARBS Installation" --infobox " Installing \` $( basename " $1 " ) \` ( $n of $total ) via \`git\` and \`make\`. $( basename " $1 " ) $2 " 5 70
2019-05-18 21:47:39 +02:00
sudo -u " $name " mkdir -p " $repodir "
sudo -u " $name " git clone --depth 1 " $1 " " /home/ $name /repos/ $repo " >/dev/null 2>& 1
cd " $repodir " || exit
2018-12-24 20:44:53 +01:00
make install >/dev/null 2>& 1
2018-12-11 22:19:30 +01:00
cd /tmp || return ; }
2018-08-03 06:21:28 +02:00
2019-03-03 00:09:47 +01:00
pipinstall( ) { \
dialog --title "LARBS Installation" --infobox " Installing the Python package \` $1 \` ( $n of $total ). $1 $2 " 5 70
command -v pip || pacman -S --noconfirm --needed python-pip >/dev/null 2>& 1
yes | pip install " $1 "
}
2018-08-03 06:21:28 +02:00
installationloop( ) { \
2018-12-20 17:54:26 +01:00
( [ -f " $progsfile " ] && cp " $progsfile " /tmp/progs.csv) || curl -Ls " $progsfile " | sed '/^#/d' > /tmp/progs.csv
2018-08-03 06:21:28 +02:00
total = $( wc -l < /tmp/progs.csv)
while IFS = , read -r tag program comment; do
2019-01-09 00:13:40 +01:00
n = $(( n+1))
echo " $comment " | grep " ^\".*\" $" >/dev/null 2>& 1 && comment = " $( echo " $comment " | sed " s/\(^\"\|\" $\)//g " ) "
case " $tag " in
2019-01-09 06:51:13 +01:00
"" ) maininstall " $program " " $comment " ; ;
"G" ) gitmakeinstall " $program " " $comment " ; ;
2019-03-03 00:09:47 +01:00
"P" ) pipinstall " $program " " $comment " ; ;
2019-01-09 00:13:40 +01:00
esac
2018-08-03 08:24:43 +02:00
done < /tmp/progs.csv ; }
2018-08-02 02:25:18 +02:00
2019-01-09 00:13:40 +01:00
putgitrepo( ) { # Downlods a gitrepo $1 and places the files in $2 only overwriting conflicts
2019-05-18 22:47:15 +02:00
[ -z " $3 " ] && branch = "master" || branch = " $repobranch "
2019-01-09 00:13:40 +01:00
dialog --infobox "Downloading and installing config files..." 4 60
dir = $( mktemp -d)
2019-02-09 22:45:22 +01:00
[ ! -d " $2 " ] && mkdir -p " $2 " && chown -R " $name :wheel " " $2 "
2019-01-27 22:03:50 +01:00
chown -R " $name :wheel " " $dir "
2019-05-18 22:47:15 +02:00
sudo -u " $name " git clone -b " $branch " --depth 1 " $1 " " $dir /gitrepo " >/dev/null 2>& 1 &&
2019-02-02 13:01:13 +01:00
sudo -u " $name " cp -rfT " $dir /gitrepo " " $2 "
2019-01-09 00:13:40 +01:00
}
2018-08-27 18:40:33 +02:00
serviceinit( ) { for service in " $@ " ; do
2018-08-03 01:23:18 +02:00
dialog --infobox " Enabling \" $service \"... " 4 40
2019-05-18 21:47:39 +02:00
ln -s " /etc/sv/ $service " /var/service/
sv start " $service "
2018-08-03 01:23:18 +02:00
done ; }
systembeepoff( ) { dialog --infobox "Getting rid of that retarded error beep sound..." 10 50
rmmod pcspkr
echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf ; }
finalize( ) { \
dialog --infobox "Preparing welcome message..." 4 50
2019-04-16 19:41:57 +02:00
echo "exec_always --no-startup-id notify-send -i ~/.scripts/larbs.png 'Welcome to LARBS:' 'Press Super+F1 for the manual.' -t 10000" >> " /home/ $name /.config/i3/config "
2018-12-11 22:33:39 +01:00
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
2018-08-03 01:23:18 +02:00
}
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
### THE ACTUAL SCRIPT ###
2018-12-24 20:44:53 +01:00
2018-08-03 01:23:18 +02:00
### This is how everything happens in an intuitive format and order.
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
# Check if user is root on Arch distro. Install dialog.
2019-05-19 01:07:55 +02:00
xbps-install -Syu dialog
2018-08-03 01:23:18 +02:00
# Welcome user.
2019-01-09 00:54:29 +01:00
welcomemsg || error "User exited."
2018-08-03 01:23:18 +02:00
# Get and verify username and password.
2019-05-28 20:59:48 +02:00
getuser || error "User exited."
2018-08-03 01:23:18 +02:00
# Last chance for user to back out before install.
2019-01-09 00:54:29 +01:00
preinstallmsg || error "User exited."
2018-08-03 01:23:18 +02:00
### The rest of the script requires no user input.
2019-01-09 00:54:29 +01:00
adduserandpass || error "Error adding username and/or password."
2018-08-03 01:23:18 +02:00
2019-01-09 00:54:29 +01:00
dialog --title "LARBS Installation" --infobox "Installing \`basedevel\` and \`git\` for installing other software." 5 70
2019-05-18 21:47:39 +02:00
xbps-install -y curl base-devel git >/dev/null 2>& 1
2018-08-03 01:23:18 +02:00
2018-08-03 06:21:28 +02:00
# The command that does all the installing. Reads the progs.csv file and
# installs each needed program the way required. Be sure to run this only after
# the user has been created and has priviledges to run sudo without a password
# and all build dependencies are installed.
installationloop
2018-08-03 01:23:18 +02:00
2018-08-03 20:11:16 +02:00
# Install the dotfiles in the user's home directory
2019-05-18 22:47:15 +02:00
putgitrepo " $dotfilesrepo " " /home/ $name " " $repobranch "
2019-03-15 21:34:52 +01:00
rm -f " /home/ $name /README.md " " /home/ $name /LICENSE "
2018-08-03 20:11:16 +02:00
2018-08-03 01:23:18 +02:00
# Enable services here.
2019-05-18 21:47:39 +02:00
serviceinit alsa NetworkManager wpa_supplicant
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
# Most important command! Get rid of the beep!
systembeepoff
2018-08-02 02:25:18 +02:00
2018-08-03 01:23:18 +02:00
# Last message! Install complete!
finalize
2018-08-02 02:25:18 +02:00
clear