From 11bc672f971639a5790eaad9f8fe6adac76c8fc6 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Sat, 29 Jun 2024 03:13:14 +0800 Subject: [PATCH] Complete system setup part of script --- debian-assets/debian-stable-sources.list | 8 + scripts/system-setup/audio-setup.sh | 15 ++ scripts/system-setup/dotfiles-setup.sh | 47 ++++-- scripts/system-setup/git-setup.sh | 17 +-- scripts/system-setup/gpu-setup.sh | 27 ++++ scripts/system-setup/neovim-setup.sh | 15 ++ scripts/system-setup/sources-setup.sh | 2 + scripts/system-setup/sudo-setup.sh | 49 +++--- scripts/system-setup/ufw-setup.sh | 13 ++ system-setup.sh | 180 ++++++++++++++++------- 10 files changed, 260 insertions(+), 113 deletions(-) create mode 100644 debian-assets/debian-stable-sources.list create mode 100755 scripts/system-setup/audio-setup.sh create mode 100755 scripts/system-setup/gpu-setup.sh create mode 100755 scripts/system-setup/neovim-setup.sh create mode 100755 scripts/system-setup/ufw-setup.sh diff --git a/debian-assets/debian-stable-sources.list b/debian-assets/debian-stable-sources.list new file mode 100644 index 0000000..da0735e --- /dev/null +++ b/debian-assets/debian-stable-sources.list @@ -0,0 +1,8 @@ +deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware +deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware + +deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware +deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware + +deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware +deb-src http://deb.debian.org/debian bookworm-updates main contrib nonfree non-free-firmware diff --git a/scripts/system-setup/audio-setup.sh b/scripts/system-setup/audio-setup.sh new file mode 100755 index 0000000..a6e9b4c --- /dev/null +++ b/scripts/system-setup/audio-setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Setup Audio Drivers +if [[ $1 == "Debian" ]]; then + if [[ $2 == "pipewire" ]]; then + echo "apt-get -y install pipewire-audio" + fi + if [[ $2 == "pulseaudio" ]]; then + echo "Skipping: No further action required" + fi +fi + +if [[ $1 == "Arch" ]]; then + echo "audio setup" +fi diff --git a/scripts/system-setup/dotfiles-setup.sh b/scripts/system-setup/dotfiles-setup.sh index 0eed0c4..66d4443 100755 --- a/scripts/system-setup/dotfiles-setup.sh +++ b/scripts/system-setup/dotfiles-setup.sh @@ -1,19 +1,36 @@ #!/bin/bash -home_dir="/home/""$(ls /home/)" +# Set Home directory for the current user +repos_dir=/home/$1/Repos -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" +if [[ ! -d $repos_dir ]]; then + echo "mkdir $repos_dir" fi +if [[ ! -d /home/$1/.config ]]; then + echo "mkdir /home/$1/.config" +fi + +while true; do + read -p "Do you have a dotfiles repository you would like to clone? (y/n): " answer + answer="${answer,,}" + if [[ $answer == "y" ]]; then + while true; do + read -p "Enter your dotfiles repo ( ): " repo + echo "git clone -b $repo $repos_dir/dotfiles" + if [[ $? = 0 ]]; then + for file in $repos_dir/dotfiles/*; do + echo "ln -s $file /home/$1/.config/" + done + break + else + echo "Invalid Repo or Authentication" + fi + done + break + elif [[ $answer == "n" ]]; then + echo "Skipping dotfiles setup..." + break + else + echo "Invalid Input. Please enter 'y' or 'n'" + fi +done diff --git a/scripts/system-setup/git-setup.sh b/scripts/system-setup/git-setup.sh index 0c728ef..2ea976c 100755 --- a/scripts/system-setup/git-setup.sh +++ b/scripts/system-setup/git-setup.sh @@ -1,24 +1,9 @@ #!/bin/bash if [[ $1 == "Debian" ]]; then - echo "$1 git-setup" - echo "apt-get install git" - + echo "apt-get -y 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/gpu-setup.sh b/scripts/system-setup/gpu-setup.sh new file mode 100755 index 0000000..c5f7bab --- /dev/null +++ b/scripts/system-setup/gpu-setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [[ $1 == "Debian" ]]; then + if cat /etc/apt/sources.list | grep -E "sid|unstable"; then + if [[ $3 == "xorg" ]]; then + echo "apt-get -y install xorg" + fi + if [[ $3 == "wayland" ]]; then + echo "Error: Wayland not available on Debian" + exit 2 + fi + if [[ $2 == "vm" ]]; then + echo "Skipping: No further action required" + fi + if [[ $2 == "nvidia" ]]; then + echo "apt-get -y install nvidia-driver firmware-misc-nonfree" + fi + else + if [[$2 == "nvidia" ]]; then + echo "apt-get -y install nvidia-driver firmware-misc-nonfree" + fi + fi +fi + +if [[ $1 == "Arch" ]]; then + echo "gpu setup" +fi diff --git a/scripts/system-setup/neovim-setup.sh b/scripts/system-setup/neovim-setup.sh new file mode 100755 index 0000000..ebc8666 --- /dev/null +++ b/scripts/system-setup/neovim-setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [[ ! -d /home/$2/Software ]]; then + echo "mkdir /home/$2/Software" +fi + +if [[ $1 == "Debian" ]]; then + echo "sudo apt-get -y install fzf ripgrep ninja-build gettext cmake unzip curl build-essential" + echo "git clone -b stable https://github.com/neovim/neovim /home/$2/Software" + echo "cd /home/$2/Software/neovim/ && make CMAKE_BUILD_TYPE=RelWithDebInfo && cd build && cpack -G DEB && sudo dpkg -i nvim-linux64.deb" +fi + +if [[ $1 == "Arch" ]]; then + echo "pacman -S neovim" +fi diff --git a/scripts/system-setup/sources-setup.sh b/scripts/system-setup/sources-setup.sh index d62f09e..a5abc8f 100755 --- a/scripts/system-setup/sources-setup.sh +++ b/scripts/system-setup/sources-setup.sh @@ -14,6 +14,8 @@ if [[ $1 == "Debian" ]]; then break elif [[ "$answer" = "n" ]]; then echo "Proceeding with Debian Stable" + echo "cp -v ./debian-assets/debian-stable-sources.list /etc/apt/sources.list" + echo "apt-get update && apt-get -y dist-upgrade" break else echo "Invalid Input. Please enter 'y' or 'n'." diff --git a/scripts/system-setup/sudo-setup.sh b/scripts/system-setup/sudo-setup.sh index 62fcf03..b707e7e 100755 --- a/scripts/system-setup/sudo-setup.sh +++ b/scripts/system-setup/sudo-setup.sh @@ -2,36 +2,23 @@ if [[ $1 == "Debian" ]]; then - echo "$1 Sudo Setup" - while [[ true ]]; do - if [[ ! -z $(grep $2 /etc/passwd) ]]; then - echo "usermod -aG sudo $2" - if [[ -f /home/$2/ ]]; 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 $2 /etc/passwd) ]]; then - echo "usermod -aG wheel $2" - if [[ -f /home/$2/ ]]; 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 + if [[ ! -z $(grep $2 /etc/passwd) ]]; then + echo "usermod -aG sudo $2" + else + echo "Username is Invalid" + exit 1 + fi + +fi + +if [[ $1 == "Arch" ]]; then + + if [[ ! -z $(grep $2 /etc/passwd) ]]; then + echo "usermod -aG wheel $2" + break + else + echo "Username is Invalid" + exit 1 + fi fi diff --git a/scripts/system-setup/ufw-setup.sh b/scripts/system-setup/ufw-setup.sh new file mode 100755 index 0000000..d19c667 --- /dev/null +++ b/scripts/system-setup/ufw-setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ $1 == "Debian" ]];then + echo "apt-get -y install ufw" +fi + +if [[$1 == "Arch" ]];then + echo "ufw setup" +fi + +echo "ufw default deny incoming" +echo "ufw default allow outgoing" +echo "ufw allow ssh" diff --git a/system-setup.sh b/system-setup.sh index fcceac6..5a2db7c 100755 --- a/system-setup.sh +++ b/system-setup.sh @@ -1,70 +1,148 @@ #!/bin/bash -# Parent installer for all System Setup Scripts. +#{{{### Pre-Setup ### -# Select Window Manager -while true; do - printf %"s\n\n" "Window Manager Selection(1-3):" - printf %"s\n" "1) i3wm" - printf %"s\n" "2) AwesomeWM" - printf %"s\n\n" "3) Hyprland" - read -p "Enter your Selection: " answer +# User Identification +username=$(whoami) +if [[ $username == "root" ]]; then + echo "Do not run this script as root" + exit 2 +fi - case $answer in - 1) windowmanager=i3wm && break;; - 2) windowmanager=awesomewm && break;; - 3) windowmanager=hyprland && break;; - *) echo "invalid option";; - esac -done +# Verify Home Directory +home_dir=/home/$username +if [[ ! -d /home/$username ]]; then + echo "Error: No valid home directory for $username" + exit 2 +fi -# Select Graphics Drivers -while true; do - printf %"s\n\n" "Select Graphics Environment(1-6):" - printf %"s\n" "1) Nvidia GPU Proprietary" - printf %"s\n" "2) Nvidia GPU Nouveau" - printf %"s\n" "3) AMD GPU" - printf %"s\n" "4) Integrated Intel GPU" - printf %"s\n" "5) Integrated AMD GPU" - printf %"s\n\n" "6) Virtual Box" - read -p "Enter your Selection: " answer - - case $answer in - 1) GPUDriver=hyprland && break;; - 2) GPUDriver=hyprland && break;; - 3) GPUDriver=hyprland && break;; - 4) GPUDriver=hyprland && break;; - 5) GPUDriver=hyprland && break;; - 6) GPUDriver=hyprland && break;; - *) echo "invalid option";; - esac -done - -echo "$GPUDriver" - -if [[ ! -z $(which apt-get) ]]; then +# System Identification +if [[ -d /etc/apt/ ]]; then system=Debian echo "System Identified: $system" elif [[ ! -z $(which pacman) ]]; then system=Arch echo "System Identified: $system" else - echo "System Misconfigured" - break + echo "System could not Identified" + exit 2 fi +script_path="$(pwd)/scripts" +# Window Manager Selection +if [[ $system == "Debian" ]]; then + echo -ne " + Window Manager Selection: -script_path="$(pwd)/scripts/system-setup/" -username=$(whoami) + " + printf %"s\n" "1) i3wm" + printf %"s\n\n" "2) AwesomeWM" + while true; do + read -p "Enter your Selection (1-2): " answer -if [ $username == "root" ]; then - echo "Error: Do not run script as root." - break + case $answer in + 1) windowmanager=i3wm && displayserver=xorg && break;; + 2) windowmanager=awesomewm && displayserver=xorg && break;; + *) echo "invalid option";; + esac + done fi -echo "su - -c "$script_path/install-pkgs.sh $system $username"" -echo "su - -c "$script_path/sources-setup.sh $system && $script_path/sudo-setup.sh $system $username && $script_path/git-setup.sh $system"" -echo "bash $script_path/dotfiles-setup.sh $system" +if [[ $system == "Arch" ]]; then + echo -ne " + Window Manager Selection: -echo "done" + " + printf %"s\n" "1) i3wm" + printf %"s\n" "2) AwesomeWM" + printf %"s\n\n" "3) Hyprland" + while true; do + read -p "Enter your Selection (1-3): " answer + + case $answer in + 1) windowmanager=i3wm && displayserver=xorg && break;; + 2) windowmanager=awesomewm && displayserver=xorg && break;; + 3) windowmanager=hyprland && displayserver=wayland && break;; + *) echo "invalid option";; + esac + done +fi + +# GPU Driver Identification +echo -ne " +GPU Drivers Selection: + +" +printf %"s\n" "1) Virtual Machine" +#printf %"s\n" "1) Integrated Intel Graphics" +#printf %"s\n" "2) Integrated AMD Graphics" +printf %"s\n\n" "2) Nvidia GPU" +#printf %"s\n" "5) AMD GPU" +#printf %"s\n\n" "6) Intel GPU" +while true; do + read -p "Enter your Selection (1-2): " answer + + case $answer in + 1) gpu=vm && break;; + 2) gpu=nvidia && break;; + *) echo "invalid option";; + esac +done + +# Select Audio Server +echo -ne " +Audio Drivers Selection: + +" +printf %"s\n" "1) Pipewire" +printf %"s\n\n" "2) PulseAudioGPU" +while true; do + read -p "Enter your Selection (1-2): " answer + case $answer in + 1) audioserver=pipewire && break;; + 1) audioserver=pulseaudio && break;; + *) echo "invalid option";; + esac +done +echo -e " +" +#}}} + +#{{{### Sudo Setup ### + +echo -e "Sudo Setup + +Enter your Root Accout Password:" +su - -c "bash $script_path/system-setup/sudo-setup.sh $system $username" +if [[ $? != 0 ]]; then + exit 2 +fi +echo -e " +" +#}}} + +#{{{### System Setup ### + +echo -e "System Setup + +Enter $username's Password:" +sudo bash "$script_path/system-setup/git-setup.sh" $system +if [[ $? != 0 ]]; then + exit 2 +fi +sudo bash "$script_path/system-setup/gpu-setup.sh" $system $gpu $server +sudo bash "$script_path/system-setup/audio-setup.sh" $system $audioserver +sudo bash "$script_path/system-setup/ufw-setup.sh" $system +bash "$script_path/system-setup/dotfiles-setup.sh" $username +bash "$script_path/system-setup/neovim-setup.sh" $system $username + +echo " + +System Setup Done +" +#}}} + +# {{{### Desktop Environment Setup ### + +# }}}