summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2020-06-03 22:09:23 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2020-06-03 22:09:23 +0100
commit9d7357fdc79e6860c4fd1a32032cc82fa90727a4 (patch)
tree5985aca5368f3233b6f0c25661b3dea7ea3a2ba1
parent6473bd03ee8e9a5799ed991c5da92013a5c7e2d6 (diff)
Create user
-rw-r--r--gohan.sh38
-rw-r--r--progs.csv1
2 files changed, 39 insertions, 0 deletions
diff --git a/gohan.sh b/gohan.sh
index 3125aee..c54a611 100644
--- a/gohan.sh
+++ b/gohan.sh
@@ -27,10 +27,38 @@ welcomemsg() { \
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 -s /bin/bash "$name" >/dev/null 2>&1 ||
+ usermod -a -G wheel "$name" && 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 ;}
+
### THE ACTUAL SCRIPT ###
### This is how everything happens in an intuitive format and order.
@@ -41,12 +69,22 @@ installpkg dialog || error "Are you sure you're running this as the root user an
# Welcome user.
welcomemsg || error "User exited."
+# Get and verify username and password.
+getuserandpass || error "User exited."
+
+# Give warning if user already exists.
+usercheck || error "User exited."
+
# Last chance for user to back out before install.
preinstallmsg || error "User exited."
### The rest of the script requires no user input.
+adduserandpass || error "Error adding username and/or password."
+
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
+
+clear
diff --git a/progs.csv b/progs.csv
new file mode 100644
index 0000000..b09a3f9
--- /dev/null
+++ b/progs.csv
@@ -0,0 +1 @@
+G,https://github.com/davidtsadler/st.git,"is my clone of the suckless simple terminal (st)."