diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2020-06-08 22:22:02 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2020-06-08 22:22:02 +0100 |
| commit | 1f421eab346cf3abdc06af4032cdd293c31ecfe9 (patch) | |
| tree | badd542e7d11cbe815325a52d6d9e11792e2a9bc | |
| parent | 3131ab72a6c62c2514eafc1a433df2830571fca5 (diff) | |
Tidy up
| -rw-r--r-- | gohan.sh | 120 |
1 files changed, 49 insertions, 71 deletions
@@ -1,90 +1,68 @@ #!/bin/sh -# My Arch Linux installation script +# My Arch Linux installation script # by David T. Sadler <davidtsadler@googlemail.com> # License: GNU GPLv3 -### OPTIONS AND VARIABLES ### - -while getopts ":b:p:h" o; do case "${o}" in - h) printf "Optional arguments for custom use:\\n -p: Dependencies and programs csv (local file or url)\\n -h: Show this message\\n" && exit ;; - b) repobranch=${OPTARG} ;; - p) progsfile=${OPTARG} ;; - *) printf "Invalid option: -%s\\n" "$OPTARG" && exit ;; -esac done - -[ -z "$progsfile" ] && progsfile="https://raw.githubusercontent.com/davidtsadler/gohan/master/progs.csv" -[ -z "$repobranch" ] && repobranch="master" - ### FUNCTIONS ### -installpkg(){ pacman --noconfirm --needed -S "$1" >/dev/null 2>&1 ;} +install_pkg() { + pacman --noconfirm --needed -S "$1" >/dev/null 2>&1 +} -error() { clear; printf "ERROR:\\n%s\\n" "$1"; exit;} +error() { + clear + printf "ERROR:\\n%s\\n" "$1" + exit +} -welcomemsg() { \ +welcome_msg() { dialog --title "Welcome!" --msgbox "Welcome to my Arch Linux installation script!\\n\\nThis script will automatically install a fully-featured Linux desktop, which I use as my main machine.\\n\\n-David" 10 60 - - dialog --colors --title "Important Note!" --yes-label "All ready!" --no-label "Return..." --yesno "Be sure the computer you are using has current pacman updates and refreshed Arch keyrings.\\n\\nIf it does not, the installation of some programs might fail." 8 70 - } - -getuserandpass() { \ - # Prompts user for new username an password. - name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit - while ! echo "$name" | grep "^[a-z_][a-z0-9_-]*$" >/dev/null 2>&1; do - 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 - pass1=$(dialog --no-cancel --passwordbox "Enter a password for that user." 10 60 3>&1 1>&2 2>&3 3>&1) - pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) - while ! [ "$pass1" = "$pass2" ]; do - unset pass2 - pass1=$(dialog --no-cancel --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1) - pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) - done ;} - -usercheck() { \ - ! (id -u "$name" >/dev/null) 2>&1 || - dialog --colors --title "WARNING!" --yes-label "CONTINUE" --no-label "No wait..." --yesno "The user \`$name\` already exists on this system. Gohan can install for a user already existing, but it will \\Zboverwrite\\Zn any conflicting settings/dotfiles on the user account.\\n\\nGohan 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 Gohan will change $name's password to the one you just gave." 14 70 - } - -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; } - } - -adduserandpass() { \ - # Adds user `$name` with password $pass1. - dialog --infobox "Adding user \"$name\"..." 4 50 - useradd -m -G wheel -s /bin/bash "$name" >/dev/null 2>&1 || - mkdir -p /home/"$name" && chown "$name":"$name" /home/"$name" - repodir="/home/$name/.local/src"; mkdir -p "$repodir"; chown -R "$name":"$name" $(dirname "$repodir") - echo "$name:$pass1" | chpasswd - unset pass1 pass2 ;} + dialog --colors --title "Important Note!" --yes-label "All ready!" --no-label "Return..." --yesno "Be sure the computer you are using has current pacman updates.\\n\\nIf it does not, the installation of some programs might fail." 8 70 +} + +get_username_and_password() { + # Prompts user for new username and password. + name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit + while ! echo "$name" | grep "^[a-z_][a-z0-9_-]*$" >/dev/null 2>&1; do + 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 + pass1=$(dialog --no-cancel --passwordbox "Enter a password for that user." 10 60 3>&1 1>&2 2>&3 3>&1) + pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) + while ! [ "$pass1" = "$pass2" ]; do + unset pass2 + pass1=$(dialog --no-cancel --passwordbox "Passwords do not match.\\n\\nEnter password again." 10 60 3>&1 1>&2 2>&3 3>&1) + pass2=$(dialog --no-cancel --passwordbox "Retype password." 10 60 3>&1 1>&2 2>&3 3>&1) + done +} + +user_check() { + ! (id -u "$name" >/dev/null) 2>&1 || dialog --colors --title "WARNING!" --yes-label "CONTINUE" --no-label "No wait..." --yesno "The user \`$name\` already exists on this system. GOHAN can install for a user already existing, but it will \\Zboverwrite\\Zn any conflicting settings/dotfiles on the user account.\\n\\nGOHAN 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 GOHAN will change $name's password to the one you just gave." 14 70 +} + +preinstall_msg() { + dialog --title "Last chance!" --yes-label "Let's go!" --no-label "No, nevermind!" --yesno "Just press <Let's go!> and the system will begin installation!" 13 60 || { clear; exit; } +} + +add_user() { + # Adds user `$name` with password $pass1. + dialog --infobox "Adding user \"$name\"..." 4 50 + useradd -m -s /bin/bash "$name" >/dev/null 2>&1 || mkdir -p /home/"$name" && chown "$name":"$name" /home/"$name" + echo "$name:$pass1" | chpasswd + unset pass1 pass2 +} ### THE ACTUAL SCRIPT ### -### This is how everything happens in an intuitive format and order. - -# Check if user is root on Arch distro. Install dialog. -installpkg dialog || error "Are you sure you're running this as the root user and have an internet connection?" - -# Welcome user. -welcomemsg || error "User exited." - -# Get and verify username and password. -getuserandpass || error "User exited." +install_pkg dialog || error "Are you sure you're running this as the root user and have an internet connection?" -# Give warning if user already exists. -usercheck || error "User exited." +welcome_msg || error "User exited." -# Last chance for user to back out before install. -preinstallmsg || error "User exited." +get_username_and_password || error "User exited." -### The rest of the script requires no user input. +user_check || error "User exited." -adduserandpass || error "Error adding username and/or password." +preinstall_msg || error "User exited." -dialog --title "Gohan Installation" --infobox "Installing \`basedevel\` and \`git\` for installing other software required for the installation of other programs." 5 70 -installpkg curl -installpkg base-devel -installpkg git +add_user || error "Error adding username and/or password." clear |
