summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2023-12-30 12:36:06 +0000
committerDavid T. Sadler <davidtsadler@googlemail.com>2023-12-30 12:36:06 +0000
commitf70c64d401768660c925ac3c038168c90884b843 (patch)
tree74e3574e80f1cf0d992d6495d7725172052ee76f
parent49b7600813c2261916250bf37f0e22df612cec26 (diff)
Refactor
-rwxr-xr-xgohan.sh48
1 files changed, 35 insertions, 13 deletions
diff --git a/gohan.sh b/gohan.sh
index db9bfec..58a14f1 100755
--- a/gohan.sh
+++ b/gohan.sh
@@ -14,9 +14,17 @@ install_from_pacman() {
pacman --noconfirm --needed -S "$1" >/dev/null 2>&1
}
+install_from_repo() {
+ progname="$(basename "$1" .git)"
+ dir="$3/$progname"
+
+ [ -d "$dir" ] || git clone "$1" "$dir" >/dev/null 2>&1
+}
+
# Install packages required by GOHAN.
install_dependancies() {
echo "Installing dependancies ..."
+
install_from_pacman base-devel
install_from_pacman git
install_from_pacman go
@@ -24,11 +32,18 @@ install_dependancies() {
add_user() {
get_username_and_password
- [ -d "/home/$name" ] && echo "Skipping adding of user as $name already exists." && return
- useradd -m -s /bin/zsh "$name" >/dev/null 2>&1 || mkdir -p /home/"$name" && chown "$name":"$name" /home/"$name"
- usermod -aG wheel "$name"
- echo "$name:$pass1" | chpasswd
+ if [ -d "/home/$name" ]; then
+ echo "Skipping adding of user as $name already exists."
+ else
+ echo "Adding user $name ..."
+ useradd -m -s /bin/zsh "$name" >/dev/null 2>&1
+ mkdir -p /home/"$name"
+ chown "$name":"$name" /home/"$name"
+ usermod -aG wheel "$name"
+ echo "$name:$pass1" | chpasswd
+ fi
+
unset pass1 pass2
}
@@ -71,10 +86,12 @@ get_username_and_password() {
printf "Enter a name for the user account: "
read name
done
+
read_password "Enter a password for that user: "
pass1=$PASSWORD
read_password "Retype password: "
pass2=$PASSWORD
+
while ! [ "$pass1" = "$pass2" ]; do
unset pass2
echo "Passwords do not match."
@@ -83,6 +100,7 @@ get_username_and_password() {
read_password "Retype password: "
pass2=$PASSWORD
done
+
unset PASSWORD
}
@@ -94,6 +112,7 @@ configure_sudo() {
# Sets up the home directory for the user account.
setup_user_home_directory() {
echo "Setting up user home directory ..."
+
clean_user_home_directory
}
@@ -105,7 +124,6 @@ clean_user_home_directory() {
[ -f "/home/$name/.bashrc" ] && rm /home/$name/.bashrc
}
-
install_yay() {
[ -f "/usr/bin/yay" ] || (
echo "Installing yay ..."
@@ -114,7 +132,7 @@ install_yay() {
cd /tmp
rm -rf /tmp/yay
git clone https://aur.archlinux.org/yay.git
- chown -R "$name":"$name" yay
+ chown -R "$name":"$name" yay
cd yay
sudo -u "$name" makepkg --noconfirm -si >/dev/null 2>&1
cd /tmp
@@ -130,7 +148,7 @@ install_packages() {
echo "$comment" | grep "^\".*\"$" >/dev/null 2>&1 && comment="$(echo "$comment" | sed "s/\(^\"\|\"$\)//g")"
case "$tag" in
"A") install_from_aur "$program" "$comment" ;;
- "G") install_from_github "$program" "$comment" ;;
+ "G") install_repo "$program" "$comment" "/usr/local/src" ;;
"#Tag") ;;
*) install_package "$program" "$comment" ;;
esac
@@ -148,14 +166,18 @@ install_from_aur() {
sudo -u "$name" yay -S --noconfirm "$1" >/dev/null 2>&1
}
-install_from_github() {
+install_repo() {
progname="$(basename "$1" .git)"
- repodir="/usr/local/src"
- dir="$repodir/$progname"
+ dir="$3/$progname"
+
printf "Installing \`$progname\` ($n of $total) via \`git\` and \`make\`. $(basename "$1") $2\n"
- git clone "$1" "$dir" >/dev/null 2>&1
- cd "$dir" || exit
- make clean install >/dev/null 2>&1
+
+ install_from_repo $1 $2 $3
+
+ [ -d "$dir" ] || (
+ cd "$dir
+ make clean install >/dev/null 2>&1
+ )
}
### THE ACTUAL SCRIPT ###