Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # Based off Luke Smith's LARBS - https://github.com/LukeSmithxyz/LARBS
  5. # Gauge's Auto Rice Boostrapping Script (GARBS)
  6. # by Gauge Krahe
  7.  
  8. ## Luke's Auto Rice Boostrapping Script (LARBS)
  9. ## by Luke Smith <luke@lukesmith.xyz>
  10. # License: GNU GPLv3
  11.  
  12. # You can provide a custom repository with -r or a custom programs csv with -p.
  13. # Otherwise, the script will use my defaults.
  14.  
  15. ### DEPENDENCIES: git and make. Make sure these either are among the first in the progs.csv file or installed manually beforehand.
  16.  
  17. ###
  18. ### OPTIONS AND VARIABLES ###
  19. ###6
  20.  
  21. while getopts ":a:r:p:h" o; do case "${o}" in
  22.     h) echo -e "Optional arguments for custom use:\\n  -r: Dotfiles repository (local file or url)\\n  -p: Dependencies and programs csv (local file or url)\\n  -a: AUR helper (must have pacman-like syntax)\\n  -h: Show this message" && exit ;;
  23.     r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit ;;
  24.     p) progsfile=${OPTARG} ;;
  25.     a) aurhelper=${OPTARG} ;;
  26.     *) echo "-$OPTARG is not a valid option." && exit ;;
  27. esac done
  28.  
  29. # DEFAULTS:
  30. [ -z ${dotfilesrepo+x} ] && dotfilesrepo="https://gitlab.com/GaugeK/dots.git"
  31. [ -z ${progsfile+x} ] && progsfile="https://gitlab.com/GaugeK/dots/raw/master/garbs/progs.csv"
  32. [ -z ${aurhelper+x} ] && aurhelper="yay"
  33.  
  34. ###
  35. ### FUNCTIONS ###
  36. ###
  37.  
  38. initialcheck() { pacman -S --noconfirm --needed dialog || { echo "Are you sure you're running this as the root user? Does the root user have sudoers permissions? Are you sure you're using an Arch-based distro? ;-) Are you sure you have an internet connection?"; exit; } ;}
  39.  
  40. #ins_ls_extended() { # Installs ls_extended manually if not installed.
  41. #   [[ -f /usr/bin/ls_extended ]] || (
  42. #   dialog --infobox "Installing ls_extended, (ls with icons and colours...)" 8 50
  43. #   cd /tmp
  44. #   rm -rf /tmp/ls_extended*
  45. #   git clone https://aur.archlinux.org/ls_extended.git &>/dev/null &&
  46. #   chmod a+rw /tmp/ls_extended
  47. #   cd "ls_extended" &&
  48. #   sed -i '16,$d' .SRCINFO &&
  49. #   sudo -u $name makepkg --noconfirm -si &>/dev/null
  50. #   cd /tmp) ;}
  51.  
  52. preinstallmsg() { \
  53.     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; }
  54.     }
  55.  
  56. welcomemsg() { \
  57.     dialog --title "Welcome!" --msgbox "Welcome to Gauge's Auto-Rice Bootstrapping Script!\\n\\nThis script will automatically install a fully-featured openbox Arch Linux desktop, which I use as my main machine.\\n\\n-Gauge" 10 60
  58.     }
  59.  
  60. refreshkeys() { \
  61.     dialog --infobox "Refreshing Arch Keyring..." 4 40
  62.     pacman --noconfirm -Sy archlinux-keyring  &>/dev/null
  63.     }
  64.  
  65. getuserandpass() { \
  66.     # Prompts user for new username an password.
  67.     # Checks if username is valid and confirms passwd.
  68.     name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit
  69.     namere="^[a-z_][a-z0-9_-]*$"
  70.     while ! [[ "${name}" =~ ${namere} ]]; do
  71.         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)
  72.     done
  73.     pass1=$(dialog --no-cancel --passwordbox "Enter a password for that user." 10 60 3>&1 1>&2 2>&3 3>&1)
  74.     pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1)
  75.     while ! [[ ${pass1} == ${pass2} ]]; do
  76.         unset pass2
  77.         pass1=$(dialog --no-cancel --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1)
  78.         pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1)
  79.     done ;}
  80.  
  81. usercheck() { \
  82.     ! (id -u $name &>/dev/null) ||
  83.     dialog --colors --title "WARNING!" --yes-label "CONTINUE" --no-label "No wait..." --yesno "The user \`$name\` already exists on this system. GARBS can install for a user already existing, but it will \\Zboverwrite\\Zn any conflicting settings/dotfiles on the user account.\\n\\nGARBS will \\Zbnot\\Zn overwrite your user files, documents, videos, etc., so don't worry about that, but only click <CONTINUE> if you don't mind your settings being overwritten.\\n\\nNote also that GARBS will change $name's password to the one you just gave." 14 70
  84.     }
  85.  
  86. adduserandpass() { \
  87.     # Adds user `$name` with password $pass1.
  88.     dialog --infobox "Adding user \"$name\"..." 4 50
  89.     useradd -m -g wheel -s /bin/bash "$name" &>/dev/null ||
  90.     usermod -a -G wheel "$name" && mkdir -p /home/"$name" && chown "$name":wheel /home/"$name"
  91.     echo "$name:$pass1" | chpasswd
  92.     unset pass1 pass2 ;}
  93.  
  94. gitmakeinstall() {
  95.     dir=$(mktemp -d)
  96.     dialog --title "GARBS Installation" --infobox "Installing \`$(basename $1)\` ($n of $total) via \`git\` and \`make\`. $(basename $1) $2." 5 70
  97.     git clone --depth 1 "$1" "$dir" &>/dev/null
  98.     cd "$dir" || exit
  99.     make &>/dev/null
  100.     make install &>/dev/null
  101.     cd /tmp ;}
  102.  
  103. maininstall() { # Installs all needed programs from main repo.
  104.     dialog --title "GARBS Installation" --infobox "Installing \`$1\` ($n of $total). $1 $2." 5 70
  105.     pacman --noconfirm --needed -S "$1" &>/dev/null
  106.     }
  107.  
  108. aurinstall() { \
  109.     dialog --title "GARBS Installation" --infobox "Installing \`$1\` ($n of $total) from the AUR. $1 $2." 5 70
  110.     grep "^$1$" <<< "$aurinstalled" && return
  111.     sudo -u $name $aurhelper -S --noconfirm "$1" &>/dev/null
  112.     }
  113.  
  114. installationloop() { \
  115.     ([ -f "$progsfile" ] && cp "$progsfile" /tmp/progs.csv) || curl -Ls "$progsfile" > /tmp/progs.csv
  116.     total=$(wc -l < /tmp/progs.csv)
  117.     aurinstalled=$(pacman -Qm | awk '{print $1}')
  118.     while IFS=, read -r tag program comment; do
  119.     n=$((n+1))
  120.     case "$tag" in
  121.     "") maininstall "$program" "$comment" ;;
  122.     "A") aurinstall "$program" "$comment" ;;
  123.     "G") gitmakeinstall "$program" "$comment" ;;
  124.     esac
  125.     done < /tmp/progs.csv ;}
  126.  
  127. serviceinit() { for service in "$@"; do
  128.     dialog --infobox "Enabling \"$service\"..." 4 40
  129.     systemctl enable "$service"
  130.     systemctl start "$service"
  131.     done ;}
  132.  
  133. newperms() { # Set special sudoers settings for install (or after).
  134.     sed -i "/#GARBS/d" /etc/sudoers
  135.     echo -e "$@ #GARBS" >> /etc/sudoers ;}
  136.  
  137. systembeepoff() { dialog --infobox "Getting rid of that retarded error beep sound..." 10 50
  138.     rmmod pcspkr
  139.     echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf ;}
  140.  
  141. putgitrepo() { # Downlods a gitrepo $1 and places the files in $2 only overwriting conflicts
  142.     dialog --infobox "Downloading and installing config files..." 4 60
  143.     dir=$(mktemp -d)
  144.     chown -R "$name":wheel "$dir"
  145.     sudo -u "$name" git clone --depth 1 "$1" "$dir"/gitrepo &>/dev/null &&
  146.     sudo -u "$name" mkdir -p "$2" &&
  147.     sudo -u "$name" cp -rT "$dir"/gitrepo "$2"
  148.     }
  149.  
  150. resetpulse() { dialog --infobox "Reseting Pulseaudio..." 4 50
  151.     killall pulseaudio
  152.     sudo -n "$name" pulseaudio --start ;}
  153.  
  154. manualinstall() { # Installs $1 manually if not installed. Used only for AUR helper here.
  155.     [[ -f /usr/bin/$1 ]] || (
  156.     dialog --infobox "Installing \"$1\", an AUR helper..." 8 50
  157.     cd /tmp
  158.     rm -rf /tmp/"$1"*
  159.     curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/"$1".tar.gz &&
  160.     sudo -u "$name" tar -xvf "$1".tar.gz &>/dev/null &&
  161.     cd "$1" &&
  162.     sudo -u $name makepkg --noconfirm -si &>/dev/null
  163.     cd /tmp) ;}
  164.  
  165. finalize(){ \
  166.     dialog --infobox "Preparing welcome message..." 4 50
  167.     echo "exec_always --no-startup-id notify-send -i ~/.scripts/larbs.png '<b>Welcome to LARBS:</b> Press Super+F1 for the manual.' -t 10000"  >> /home/$name/.config/i3/config
  168.     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.\\n\\n-Gauge" 12 80
  169.     }
  170.  
  171. ###
  172. ### THE ACTUAL SCRIPT ###
  173. ###
  174. ### This is how everything happens in an intuitive format and order.
  175. ###
  176.  
  177. # Check if user is root on Arch distro. Install dialog.
  178. initialcheck
  179.  
  180. # Welcome user.
  181. welcomemsg || { clear; exit; }
  182.  
  183. # Get and verify username and password.
  184. getuserandpass
  185.  
  186. # Give warning if user already exists.
  187. usercheck || { clear; exit; }
  188.  
  189. # Last chance for user to back out before install.
  190. preinstallmsg || { clear; exit; }
  191.  
  192. ### The rest of the script requires no user input.
  193.  
  194. adduserandpass
  195.  
  196. # Refresh Arch keyrings.
  197. refreshkeys
  198.  
  199. # Allow user to run sudo without password. Since AUR programs must be installed
  200. # in a fakeroot environment, this is required for all builds with AUR.
  201. newperms "%wheel ALL=(ALL) NOPASSWD: ALL"
  202.  
  203. manualinstall $aurhelper
  204.  
  205. # The command that does all the installing. Reads the progs.csv file and
  206. # installs each needed program the way required. Be sure to run this only after
  207. # the user has been created and has priviledges to run sudo without a password
  208. # and all build dependencies are installed.
  209. installationloop
  210.  
  211. # Install the dotfiles in the user's home directory
  212. putgitrepo "$dotfilesrepo" "/home/$name"
  213.  
  214. #Agnoster ZSH theme
  215. curl https://gitlab.com/GaugeK/dots/raw/master/bin/agnoster.zsh-theme -o /usr/share/oh-my-zsh/themes/agnoster.zsh-theme &>/dev/null
  216.  
  217. #Sauce Code Pro font
  218. rm /tmp/SauceCodePro.zip &>/dev/null
  219. curl -Ls https://github.com/ryanoasis/nerd-fonts/releases/download/v2.0.0/SourceCodePro.zip > /tmp/SauceCodePro.zip &>/dev/null
  220. unzip -o /tmp/SauceCodePro.zip -d /usr/share/fonts/TTF/ &>/dev/null
  221.  
  222. #Iosevka font
  223. rm /tmp/02-iosevka-term-2.0.1.zip &>/dev/null
  224. curl -Ls https://github.com/be5invis/Iosevka/releases/download/v2.0.1/02-iosevka-term-2.0.1.zip > /tmp/02-iosevka-term-2.0.1.zip &>/dev/null
  225. unzip -o /tmp/02-iosevka-term-2.0.1.zip -d /usr/share/fonts/TTF/ &>/dev/null
  226.  
  227. fc-cache -f
  228.  
  229. #ls with icons and colours
  230. if [ ! -f /usr/bin/ls_extended ]; then
  231. curl -L "https://gitlab.com/GaugeK/dots/raw/master/bin/ls_extended?inline=false" -o "/usr/bin/ls_extended"
  232. chmod a+x "/usr/bin/ls_extended"
  233. fi
  234.  
  235. #Hibernate (for rofi)
  236. if [ ! -f /usr/bin/hibernate ]; then
  237. echo "#\!/usr/bin/bash
  238.  
  239. systemctl hibernate" >> /usr/bin/hibernate
  240. fi
  241.  
  242. #Hibernate and lock
  243. if [ ! -f /usr/bin/hib ]; then
  244. echo "#\!/usr/bin/bash
  245.  
  246. systemctl hibernate && lock" >> /usr/bin/hib
  247. fi
  248.  
  249. #Disable mouse acceleration
  250. if [ ! -f /etc/X11/xorg.conf.d/50-mouse-acceleration.conf ]; then
  251. echo 'Section "InputClass"
  252.    Identifier "My Mouse"
  253.    MatchIsPointer "yes"
  254.    Option "AccelerationProfile" "-1"
  255.    Option "AccelerationScheme" "none"
  256.    Option "AccelSpeed" "-0.75"
  257. EndSection' >> /etc/X11/xorg.conf.d/50-mouse-acceleration.conf
  258. fi
  259.  
  260. #Touchpad stuff
  261. if [ ! -f /etc/X11/xorg.conf.d/70-synaptics.conf ]; then
  262. echo 'Section "InputClass"
  263.    Identifier "touchpad"
  264.    Driver "synaptics"
  265.    MatchIsTouchpad "on"
  266.        Option "TapButton1" "1"
  267.        Option "TapButton2" "3"
  268.        Option "TapButton3" "2"
  269.        Option "VertEdgeScroll" "on"
  270.        Option "VertTwoFingerScroll" "on"
  271.        Option "HorizEdgeScroll" "on"
  272.        Option "HorizTwoFingerScroll" "on"
  273.        Option "CircularScrolling" "on"
  274.        Option "CircScrollTrigger" "2"
  275.        Option "EmulateTwoFingerMinZ" "40"
  276.        Option "EmulateTwoFingerMinW" "8"
  277.        Option "CoastingSpeed" "0"
  278.        Option "FingerLow" "30"
  279.        Option "FingerHigh" "50"
  280.        Option "MaxTapTime" "125"
  281. EndSection' >> /etc/X11/xorg.conf.d/70-synaptics.conf
  282. fi
  283.  
  284.  
  285. # Install the LARBS Firefox profile in ~/.mozilla/firefox/
  286. #putgitrepo "https://github.com/LukeSmithxyz/mozillarbs.git" "/home/$name/.mozilla/firefox"
  287.  
  288. # Pulseaudio, if/when initially installed, often needs a restart to work immediately.
  289. [[ -f /usr/bin/pulseaudio ]] && resetpulse
  290.  
  291. # Enable services here.
  292. serviceinit NetworkManager cronie
  293. systemctl enable sddm
  294.  
  295. # Most important command! Get rid of the beep!
  296. systembeepoff
  297.  
  298. # This line, overwriting the `newperms` command above will allow the user to run
  299. # serveral important commands, `shutdown`, `reboot`, updating, etc. without a password.
  300. newperms "%wheel ALL=(ALL) ALL\\n%wheel 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/pacman -Syu,/usr/bin/pacman -Syyu,/usr/bin/packer -Syu,/usr/bin/packer -Syyu,/usr/bin/systemctl restart NetworkManager,/usr/bin/rc-service NetworkManager restart,/usr/bin/pacman -Syyu --noconfirm,/usr/bin/loadkeys,/usr/bin/yay"
  301.  
  302. # Make pacman and yay colorful because why not.
  303. sed -i "s/^#Color/Color/g" /etc/pacman.conf
  304.  
  305. #One line per pkg pacman
  306. sed -i "s/^#VerbosePkgLists/VerbosePkgLists/g" /etc/pacman.conf
  307.  
  308. #Pacman-like loading bar in pacman
  309. if grep -q ILoveCandy "/etc/pacman.conf"; then
  310.     else
  311.     sed -i '/# Misc options/a ILoveCandy' /etc/pacman.conf
  312. fi
  313.  
  314. #Make sudo as normal user request the root user's password instead of that user's
  315. if grep -q "Defaults rootpw" "/etc/sudoers"; then
  316.     else
  317.     sed -i '/## Defaults specification/a Defaults rootpw' /etc/pacman.conf
  318. fi
  319.  
  320. #Screenshot folder
  321. if [ ! -f /home/$name/Stuff/Screenshots/scrot/ ]; then
  322.     mkdir /home/$name/Stuff
  323.     mkdir /home/$name/Stuff/Screenshots/
  324.     mkdir /home/$name/Stuff/Screenshots/scrot/
  325. fi
  326.  
  327. #Make wifi faster on my card
  328. sh -c 'echo "options iwlwifi bt_coex_active=0 swcrypto=1 11n_disable=8" > /etc/modprobe.d/iwlwifi.conf'
  329.  
  330. #Shorter timeout for systemd init
  331. sed -i "s/^#DefaultTimeoutStartSec=90s/DefaultTimeoutStartSec=15s/g" /etc/systemd/system.conf
  332. sed -i "s/^#DefaultTimeoutstopSec=90s/DefaultTimeoutstopSec=10s/g" /etc/systemd/system.conf
  333.  
  334. # Last message! Install complete!
  335. finalize
  336. clear
  337.  
  338. #Start the display manager
  339. #systemctl start sddm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement