From 5b1c38405103298d4cf8a6cdef1ffcd832163ef7 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Thu, 27 Jun 2024 15:24:32 +0800 Subject: [PATCH] Update: System Setup scripts Add: dotfiles-setup.sh --- scripts/system-setup/dotfiles-setup.sh | 19 +++++++++++++ scripts/system-setup/git-setup.sh | 23 +++++++++++++++- scripts/system-setup/sources-setup.sh | 18 +++++------- scripts/system-setup/sudo-setup.sh | 38 +++++++++++++++++++++++++- system-setup.sh | 22 +++++++-------- 5 files changed, 96 insertions(+), 24 deletions(-) create mode 100755 scripts/system-setup/dotfiles-setup.sh diff --git a/scripts/system-setup/dotfiles-setup.sh b/scripts/system-setup/dotfiles-setup.sh new file mode 100755 index 0000000..0eed0c4 --- /dev/null +++ b/scripts/system-setup/dotfiles-setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +home_dir="/home/""$(ls /home/)" + +if [[ -d $home_dir ]]; then + echo "Has valid home directory" + while [[ true ]]; do + if [[ -d $home_dir/Repos ]]; then + echo "Has valid Repos directory" + read -p "Enter your dotfiles repo: " repo + echo "git clone $repo $home_dir/Repos" + break + else + mkdir $home_dir/Repos + fi + done +else + echo "no valid home directory" +fi diff --git a/scripts/system-setup/git-setup.sh b/scripts/system-setup/git-setup.sh index e5f897c..0c728ef 100755 --- a/scripts/system-setup/git-setup.sh +++ b/scripts/system-setup/git-setup.sh @@ -1,3 +1,24 @@ #!/bin/bash -echo "git-setup" +if [[ $1 == "Debian" ]]; then + + echo "$1 git-setup" + echo "apt-get install git" + +elif [[ $1 == "Arch" ]]; then + + echo "$1 git-setup" + echo "pacman -S git" + while [[ true ]]; do + read -p "Git Setup: Enter your full name: " name + read -p "Git Setup: Enter your email address: " email + if [[ ! -z $name && ! -z $email ]]; then + break + else + echo "Invalid name or address, Please re-enter" + fi + done + echo "git config --global user.name $name" + echo "git config --global user.email $email" + +fi diff --git a/scripts/system-setup/sources-setup.sh b/scripts/system-setup/sources-setup.sh index a484985..d62f09e 100755 --- a/scripts/system-setup/sources-setup.sh +++ b/scripts/system-setup/sources-setup.sh @@ -1,19 +1,15 @@ #!/bin/bash -APT_CMD=$(which apt-get) -PACMAN_CMD=$(which pacman) +if [[ $1 == "Debian" ]]; then -if [[ ! -z $APT_CMD ]]; then - - echo "System Identified: Debian" + echo "$1 Sources Setup" echo "apt-get update && apt-get -y upgrade" - while true;do read -rp "Would you like to use Debian Unstable? (y/n): " answer answer="${answer,,}" if [[ "$answer" = "y" ]]; then - echo "Change apt sources" - echo "cp -v ./debian-assets/debian-sid-sources.list /etc/sources.list" + echo "Changing apt sources" + echo "cp -v ./debian-assets/debian-sid-sources.list /etc/apt/sources.list" echo "apt-get update && apt-get -y dist-upgrade" break elif [[ "$answer" = "n" ]]; then @@ -23,7 +19,7 @@ if [[ ! -z $APT_CMD ]]; then echo "Invalid Input. Please enter 'y' or 'n'." fi done - -elif [[ ! -z $PACMAN_CMD ]]; then - echo "Arch" + +elif [[ $1 == "Arch" ]]; then + echo "$1 Sources Setup" fi diff --git a/scripts/system-setup/sudo-setup.sh b/scripts/system-setup/sudo-setup.sh index c191751..7753b30 100755 --- a/scripts/system-setup/sudo-setup.sh +++ b/scripts/system-setup/sudo-setup.sh @@ -1,3 +1,39 @@ #!/bin/bash -echo "sudo setup" +read -p "Enter the user to add to Sudo: " username + +if [[ $1 == "Debian" ]]; then + + echo "$1 Sudo Setup" + while [[ true ]]; do + if [[ ! -z $(grep $username /etc/passwd) ]]; then + echo "usermod -aG sudo $username" + if [[ -f /home/$username/ ]]; then + echo "Home exists" + else + echo "Home doesn't Exist" + fi + break + else + read -p "Invalid Username. Use an valid existing username." username + fi + done + +elif [[ $1 == "Arch" ]]; then + + echo "$1 Sudo Setup" + while [[ true ]]; do + if [[ ! -z $(grep $username /etc/passwd) ]]; then + echo "usermod -aG wheel $username" + if [[ -f /home/$username/ ]]; then + echo "Home exists" + else + echo "Home doesn't Exist" + fi + break + else + read -p "Invalid Username. Use a valid existing username:" username + fi + done + +fi diff --git a/system-setup.sh b/system-setup.sh index 8c64207..72b540b 100755 --- a/system-setup.sh +++ b/system-setup.sh @@ -2,24 +2,24 @@ # Parent installer for all System Setup Scripts. -APT_CMD=$(which apt-get) -PACMAN_CMD=$(which pacman) - -if [[ -z $APT_CMD ]]; then +if [[ ! -z $(which apt-get) ]]; then system=Debian - echo "System Identified: Debian" -elif [[ -z $PACMAN_CMD ]]; then + echo "System Identified: $system" +elif [[ ! -z $(which pacman) ]]; then system=Arch - echo "System Identified: Arch" + echo "System Identified: $system" else echo "System Misconfigured" break fi -systemsetup="./scripts/" +systemsetup="./scripts/system-setup" -bash $systemsetup/sources-setup.sh $system -bash $systemsetup/sudo-setup.sh $system -bash $systemsetup/git-setup.sh $system +for FILE in "$systemsetup"/* +do + if [[ -f "$FILE" ]]; then + bash $FILE $system + fi +done echo "done"