diff --git a/00-Checking_Dependencies.sh b/00-Checking_Dependencies.sh index c13f04c..c10f6f2 100644 --- a/00-Checking_Dependencies.sh +++ b/00-Checking_Dependencies.sh @@ -2,6 +2,7 @@ ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" ## Start File Loop @@ -9,25 +10,30 @@ source "$SCRIPTDIR/common/functions.sh" DEPENDENCIESALL="$SCRIPTDIR/dependencies/*.dep" for f in $DEPENDENCIESALL do + ## Name Of Package DEPENDENCYCOMMAND=$(echo "`basename $f | cut -f 1 -d '.'`") + ## Actual Package DEPENDENCYPACKAGE=`cat $f` - echo "* Checking For command $DEPENDENCYCOMMAND with package name $DEPENDENCYPACKAGE" + + printf "$COL_LIGHT_BLUE" "* Checking For command $DEPENDENCYCOMMAND with package name $DEPENDENCYPACKAGE" if is_command $DEPENDENCYCOMMAND; then - echo "** $DEPENDENCYCOMMAND Is Already Installed." + printf "$COL_YELLOW" "** $DEPENDENCYCOMMAND Is Already Installed." + else - echo "** Installing $DEPENDENCYCOMMAND" + printf "$COL_YELLOW" "** Installing $DEPENDENCYCOMMAND" install_pkg $DEPENDENCYPACKAGE - fi - if is_command $DEPENDENCYCOMMAND; - then - : - else - echo "** Error Installing $DEPENDENCYCOMMAND" + if is_command $DEPENDENCYCOMMAND; + then + printf "$COL_GREEN" "** $DEPENDENCYCOMMAND Installation Success" + else + printf "$COL_RED" "** Error Installing $DEPENDENCYCOMMAND" + fi + fi ## End Of loop done diff --git a/01-Updating_Custom_MOTD.sh b/01-Updating_Custom_MOTD.sh index 701ab02..23fac02 100644 --- a/01-Updating_Custom_MOTD.sh +++ b/01-Updating_Custom_MOTD.sh @@ -2,6 +2,7 @@ ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" ## Start File Loop @@ -10,15 +11,20 @@ MOTDDIR="/etc/update-motd.d/" MOTDALL="$SCRIPTDIR/motd/*" for f in $MOTDALL do - ## Name Of Package + + ## Name Of MOTD file MOTDNAME=$(echo "`basename $f | cut -f 1 -d '.'`") - echo "* Checking For $MOTDNAME motd file" + + printf "$COL_LIGHT_BLUE" "* Checking For $MOTDNAME motd file" + FILEBASENAME=$(echo "`basename $f`") + if [ ! -f "$FILEBASENAME" ]; then - echo "** $FILEBASENAME motd file Missing, copying" + printf "$COL_YELLOW" "** $FILEBASENAME motd file Missing, copying" cp "$f" $MOTDDIR else - echo "** $FILEBASENAME motd exists" + printf "$COL_YELLOW" "** $FILEBASENAME motd exists" fi + ## End Of loop done diff --git a/02-Checking_Topgrade_Installation_Status.sh b/02-Checking_Topgrade_Installation_Status.sh index 23fcb91..83852de 100644 --- a/02-Checking_Topgrade_Installation_Status.sh +++ b/02-Checking_Topgrade_Installation_Status.sh @@ -2,46 +2,48 @@ ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" -echo "* Checking for topgrade directory" +printf "$COL_LIGHT_BLUE" "* Checking for topgrade directory" topgrade_install_directory="/opt/topgrade" if [ ! -d "$topgrade_install_directory" ]; then - echo "** creating topgrade installation directory" + printf "$COL_YELLOW" "** creating topgrade installation directory" mkdir $topgrade_install_directory fi -echo "* Checking for topgrade binary" +printf "$COL_LIGHT_BLUE" "* Checking for topgrade binary" topgrade_binary="/opt/topgrade/topgrade" topgrade_tar="/opt/topgrade/topgrade.tar.gz" topgrade_git_owner="r-darwish" topgrade_git_repo="topgrade" if [ ! -f "$topgrade_binary" ]; then - echo "** topgrade binary missing, installing now" + printf "$COL_YELLOW" "** topgrade binary missing, installing now" newest_release_url=$(curl -sL https://api.github.com/repos/$topgrade_git_owner/$topgrade_git_repo/releases/latest | jq -r ".assets[].browser_download_url" | grep x86_64-unknown-linux-gnu.tar.gz) wget $newest_release_url -q -O "$topgrade_tar" tar -xvf $topgrade_tar -C $topgrade_install_directory rm $topgrade_tar chmod +x $topgrade_binary else - echo "** topgrade binary exists" -fi -if [ ! -f "$topgrade_binary" ]; then - echo "** topgrade binary not present at $topgrade_binary" -else - current_version=$($topgrade_binary --version | sed 's/[A-Za-z]*//g') - echo "** Locally installed topgrade version: $current_version" - newest_release=$(curl -sL https://api.github.com/repos/$topgrade_git_owner/$topgrade_git_repo/releases/latest | jq -r ".tag_name" | sed 's/[A-Za-z]*//g') - echo "** Online topgrade version: $newest_release" + printf "$COL_YELLOW" "** topgrade binary exists" fi -echo "checking for topgrade confs" +if [ ! -f "$topgrade_binary" ]; then + printf "$COL_RED" "** topgrade binary not present at $topgrade_binary" +else + current_version=$($topgrade_binary --version | sed 's/[A-Za-z]*//g') + printf "$COL_GREEN" "** Locally installed topgrade version: $current_version" + newest_release=$(curl -sL https://api.github.com/repos/$topgrade_git_owner/$topgrade_git_repo/releases/latest | jq -r ".tag_name" | sed 's/[A-Za-z]*//g') + printf "$COL_GREEN" "** Online topgrade version: $newest_release" +fi + +printf "$COL_LIGHT_BLUE" "checking for topgrade confs" custom_topgrade_confs_path="/etc/topgrade" custom_topgrade_confs_git="https://git.deathbybandaid.net/deathbybandaid/topgrade.git" git_update "topgrade" "$custom_topgrade_confs_path" "$custom_topgrade_confs_git" ## Update if [ -f "$topgrade_binary" ]; then - echo "* Running topgrade" + printf "$COL_CYAN" "* Running topgrade" $topgrade_binary fi diff --git a/03-Checking_Custom_Bash_Aliases.sh b/03-Checking_Custom_Bash_Aliases.sh index a0f41bf..860c2f7 100644 --- a/03-Checking_Custom_Bash_Aliases.sh +++ b/03-Checking_Custom_Bash_Aliases.sh @@ -2,6 +2,7 @@ ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" BASHRCFILE="$HOME/.bashrc" @@ -10,9 +11,9 @@ custom_bash_aliases_path="/etc/bash_aliases" custom_bash_aliases_git="https://git.deathbybandaid.net/deathbybandaid/bash_aliases.git" git_update "topgrade" "$custom_bash_aliases_path" "$custom_bash_aliases_git" -echo "* Checking if bash aliases are setup in ~/.bashrc" +printf "$COL_LIGHT_BLUE" "* Checking if bash aliases are setup in ~/.bashrc" if [[ $(grep -L "$custom_bash_aliases_path" $BASHRCFILE) ]]; then - echo "** Linking bash aliases" + printf "$COL_YELLOW" "** Linking bash aliases" cat <> $BASHRCFILE # Aliases @@ -21,8 +22,8 @@ if [ -f $custom_bash_aliases_path/main.aliases ]; then fi EOT else - echo "** bash aliases already linked" + printf "$COL_YELLOW" "** bash aliases already linked" fi -echo "* Importing Bash Aliases" +printf "$COL_LIGHT_BLUE" "* Importing Bash Aliases" source $BASHRCFILE diff --git a/04-Checking_IPA_Realm_Join_Status.sh b/04-Checking_IPA_Realm_Join_Status.sh index 4af5d4b..3ed9627 100644 --- a/04-Checking_IPA_Realm_Join_Status.sh +++ b/04-Checking_IPA_Realm_Join_Status.sh @@ -2,19 +2,20 @@ ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" # TODO setup /etc/hosts with FQDN and FreeIPA servers -echo "* Checking if system already contains Membership to FreeIPA Realm" +printf "$COL_LIGHT_BLUE" "* Checking if system already contains Membership to FreeIPA Realm" realm_join=0 if [[ ! -f /var/lib/ipa-client/sysrestore/sysrestore.state ]] then - echo "** $HOSTNAME appears to not be joined to FreeIPA Server Realm" + printf "$COL_YELLOW" "** $HOSTNAME appears to not be joined to FreeIPA Server Realm" realm_join=1 else - echo "** $HOSTNAME appears to already be joined to FreeIPA Server Realm" + printf "$COL_GREEN" "** $HOSTNAME appears to already be joined to FreeIPA Server Realm" fi ## FreeIPA Realm Join @@ -23,17 +24,17 @@ if [ "$realm_join" == 1 ]; then then if [[ $HOSTNAME == *template* ]]; then - echo "** Hostname $HOSTNAME contains the word 'template', skipping realm joining" + printf "$COL_RED" "** Hostname $HOSTNAME contains the word 'template', skipping realm joining" realm_join=0 fi if [ "$realm_join" == 1 ]; then - echo "** Setting up ipa-client to join FreeIPA Server Realm" + printf "$COL_YELLOW" "** Setting up ipa-client to join FreeIPA Server Realm" freeipa_admin=$(whiptail --passwordbox "Please enter the user authorized to join FreeIPA realm: $freeipa_admin" 8 78 --title "FreeIPA Admin User Prompt" 3>&1 1>&2 2>&3) freeipa_password=$(whiptail --passwordbox "Please enter the password for the FreeIPA admin user: $freeipa_admin" 8 78 --title "FreeIPA Password Prompt" 3>&1 1>&2 2>&3) ipa-client-install --mkhomedir --no-ntp --principal="$freeipa_admin" --password="$freeipa_password" --enable-dns-updates --unattended fi else - echo "** Skipping realm joining" + printf "$COL_CYAN" "** Skipping realm joining" fi fi diff --git a/common/colors.sh b/common/colors.sh new file mode 100644 index 0000000..4c80dad --- /dev/null +++ b/common/colors.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +## These are the colors used throughout the script. +COL_RED='\e[1;31m%s\e[0m\n' +COL_GREEN='\e[1;32m%s\e[0m\n' +COL_YELLOW='\e[1;33m%s\e[0m\n' +COL_BLUE='\e[1;34m%s\e[0m\n' +COL_MAGENTA='\e[1;35m%s\e[0m\n' +COL_CYAN='\e[1;36m%s\e[0m\n' +COL_ORANGE='\e[38;5;166m%s\e[0m\n' +COL_LIGHT_BLUE='\e[38;5;111m%s\e[0m\n' diff --git a/common/functions.sh b/common/functions.sh index b8c1509..49666b2 100644 --- a/common/functions.sh +++ b/common/functions.sh @@ -10,10 +10,10 @@ git_update() { local git_path="$2" local git_repo="$3" if [ ! -d "$git_path" ]; then - echo "* Installing $git_name" + printf "$COL_YELLOW" "* Installing $git_name" git clone --quiet $git_repo $git_path else - echo "* Updating $git_name" + printf "$COL_YELLOW" "* Updating $git_name" git -C $git_path pull fi } diff --git a/install/install.sh b/install/install.sh index cbf18cf..4a27d25 100644 --- a/install/install.sh +++ b/install/install.sh @@ -1,4 +1,14 @@ #!/bin/bash +s +## These are the colors used throughout the script. +COL_RED='\e[1;31m%s\e[0m\n' +COL_GREEN='\e[1;32m%s\e[0m\n' +COL_YELLOW='\e[1;33m%s\e[0m\n' +COL_BLUE='\e[1;34m%s\e[0m\n' +COL_MAGENTA='\e[1;35m%s\e[0m\n' +COL_CYAN='\e[1;36m%s\e[0m\n' +COL_ORANGE='\e[38;5;166m%s\e[0m\n' +COL_LIGHT_BLUE='\e[38;5;111m%s\e[0m\n' is_command() { local check_command="$1" @@ -10,10 +20,10 @@ git_update() { local git_path="$2" local git_repo="$3" if [ ! -d "$git_path" ]; then - echo "* Installing $git_name" + printf "$COL_YELLOW" "* Installing $git_name" git clone --quiet $git_repo $git_path else - echo "* Updating $git_name" + printf "$COL_YELLOW" "* Updating $git_name" git -C $git_path pull fi } @@ -66,19 +76,19 @@ install_pkg() { "${PKG_INSTALL[@]}" "${pkg_to_install}" } -echo "Checking For git" +printf "$COL_LIGHT_BLUE" "Checking For git" if is_command git; then - echo "* git Is Already Installed." + printf "$COL_YELLOW" "* git Is Already Installed." else - echo "* Installing git" + printf "$COL_YELLOW" "* Installing git" install_pkg git fi -echo "Checking for installation script" +printf "$COL_LIGHT_BLUE" "Checking for installation script" template_setup_path="/etc/template_setup" template_setup_git="https://git.deathbybandaid.net/deathbybandaid/template_setup.git" git_update "template_setup" "$template_setup_path" "$template_setup_git" -echo "Running installation" +printf "$COL_LIGHT_BLUE" "Running installation" bash "$template_setup_path/template_setup.sh" diff --git a/template_setup.sh b/template_setup.sh index fe56505..5175ded 100644 --- a/template_setup.sh +++ b/template_setup.sh @@ -1,30 +1,19 @@ #!/bin/bash echo "Setting up template environment" -# TODO list -# * colors # * dbb avatar -## These are the colors used throughout the script. -red='\e[1;31m%s\e[0m\n' -COL_GREEN='\e[1;32m%s\e[0m\n' -yellow='\e[1;33m%s\e[0m\n' -blue='\e[1;34m%s\e[0m\n' -magenta='\e[1;35m%s\e[0m\n' -cyan='\e[1;36m%s\e[0m\n' -orange='\e[38;5;166m%s\e[0m\n' -lightblue='\e[38;5;111m%s\e[0m\n' - - ## Script Location SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" git -C $SCRIPTDIR pull echo "" for scriptfile in "$SCRIPTDIR"/[0-9]*.sh do - TOPLEVELSUBDIRNAME=$(echo "`basename $TOPLEVELSUBDIRPATH | cut -f 1 -d '.' | sed 's/[0-9]/ /g; s/[\-]/ /; s/^[[:space:]]*//'`") - printf "${COL_GREEN}" "$TOPLEVELSUBDIRNAME" + + TOPLEVELSUBDIRSCRIPTTEXT=$(echo "`basename $scriptfile | cut -f 1 -d '.' | sed 's/[0-9]/ /g; s/[\-]/ /; s/^[[:space:]]*//'`") + printf "${COL_CYAN}" "$TOPLEVELSUBDIRSCRIPTTEXT" /bin/bash $scriptfile