Fixed color formatting

main
Graham Helton 2 years ago
parent 5b9e61d570
commit 2a0d3194d1

@ -28,10 +28,10 @@ selected_config=$HOST_CONFIG_PATH
usage() { usage() {
echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR echo -e $GREEN"-------------------------------------------------------------------"$ENDCOLOR
echo $GREEN"*** $BLUE AutoDeploy - A pure bash configuration management tool$GREEN ***"$ENDCOLOR echo -e $GREEN"*** $BLUE AutoDeploy - A pure bash configuration management tool$GREEN ***"$ENDCOLOR
echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR echo -e $GREEN"-------------------------------------------------------------------"$ENDCOLOR
echo " echo -e "
$BLUE Usage: $BLUE Usage:
autodeploy -h autodeploy -h
autodeploy -e [apps|config|files] autodeploy -e [apps|config|files]
@ -63,16 +63,16 @@ first_setup(){
# It handles creating the configuration directory, establishing the git repository for configuration files, and initializing # It handles creating the configuration directory, establishing the git repository for configuration files, and initializing
# the ~/.config/autodeploy/ as a git repository # the ~/.config/autodeploy/ as a git repository
echo $TICK$GREEN"Running first time setup"$ENDCOLOR echo -e $TICK$GREEN"Running first time setup"$ENDCOLOR
echo $TICK$GREEN"Creating Configuration Files in $BLUE~/.config/autodeploy/ "$ENDCOLOR echo -e $TICK$GREEN"Creating Configuration Files in $BLUE~/.config/autodeploy/ "$ENDCOLOR
mkdir -p ~/.config/autodeploy/ mkdir -p ~/.config/autodeploy/
echo $TICK$GREEN"Enter your remote git repository URL"$ENDCOLOR echo -e $TICK$GREEN"Enter your remote git repository URL"$ENDCOLOR
echo $TICK$GREEN"For example: $BLUE"https://github.com/grahamhelton/DotFiles""$ENDCOLOR echo -e $TICK$GREEN"For example: $BLUE"https://github.com/grahamhelton/DotFiles""$ENDCOLOR
echo -n $TICK_INPUT$GREEN"Enter Remote Repository URL: $YELLOW" echo -e -n $TICK_INPUT$GREEN"Enter Remote Repository URL: $YELLOW"
read remote_repo read remote_repo
echo $NOCOLOR$TICK$GREEN"Setting Remote Repository to: $YELLOW$remote_repo " echo -e $NOCOLOR$TICK$GREEN"Setting Remote Repository to: $YELLOW$remote_repo "
#. ~/.config/autodeploy/autodeploy_config.conf #. ~/.config/autodeploy/autodeploy_config.conf
cd $CONFIG_PATH cd $CONFIG_PATH
@ -87,18 +87,18 @@ get_posture(){
# Change to wget -q --spider $remote_repo then check for return code with $? # Change to wget -q --spider $remote_repo then check for return code with $?
if ping -c 1 8.8.8.8 > /dev/null 2>&1; then if ping -c 1 8.8.8.8 > /dev/null 2>&1; then
echo $TICK"Internet Connectivity Detected"$ENDCOLOR echo -e $TICK"Internet Connectivity Detected"$ENDCOLOR
internet=True internet=True
else else
echo $RED"Internet Connectivity Not Detected"$ENDCOLOR echo -e $RED"Internet Connectivity Not Detected"$ENDCOLOR
internet=false internet=false
fi fi
if apt help install -h > /dev/null 2>&1; then if apt help install -h > /dev/null 2>&1; then
echo $TICK"APT is installed"$ENDCOLOR echo -e $TICK"APT is installed"$ENDCOLOR
apt=true apt=true
else else
echo $RED"APT is NOT installed"$ENDCOLOR echo -e $RED"APT is NOT installed"$ENDCOLOR
apt=false apt=false
fi fi
@ -106,24 +106,24 @@ get_posture(){
install_apps(){ install_apps(){
# This function is responsible for installing any applications (using apt) defined in ~/.config/autodeploy/autodeploy_apps.conf # This function is responsible for installing any applications (using apt) defined in ~/.config/autodeploy/autodeploy_apps.conf
echo $TICK$BLUE"Please input SUDO password"$ENDCOLOR echo -e $TICK$BLUE"Please input SUDO password"$ENDCOLOR
# Runs sudo apt update and upgrade # Runs sudo apt update and upgrade
echo $TICK$GREEN"Running apt update and apt upgrade..."$ENDCOLOR ; sudo apt update > /dev/null 2>&1 && sudo apt upgrade -y > /dev/null 2>&1 echo -e $TICK$GREEN"Running apt update and apt upgrade..."$ENDCOLOR ; sudo apt update > /dev/null 2>&1 && sudo apt upgrade -y > /dev/null 2>&1
echo $TICK$GREEN"Installing applications from $BLUE$CONFIG_PATH/autodeploy_apps.conf"$ENDCOLOR echo -e $TICK$GREEN"Installing applications from $BLUE$CONFIG_PATH/autodeploy_apps.conf"$ENDCOLOR
# Install each application listed in $CONFIG_PATH/autodeploy_apps # Install each application listed in $CONFIG_PATH/autodeploy_apps
grep -v '^#' $CONFIG_PATH/autodeploy_apps.conf | while read -r line; do grep -v '^#' $CONFIG_PATH/autodeploy_apps.conf | while read -r line; do
echo $TICK$GREEN"Installing $BLUE$line"$ENDCOLOR echo -e $TICK$GREEN"Installing $BLUE$line"$ENDCOLOR
sudo apt install $line -y > /dev/null 2>&1 #| grep -A 1 "NEW packages" | grep -v "NEW packages" sudo apt install $line -y > /dev/null 2>&1 #| grep -A 1 "NEW packages" | grep -v "NEW packages"
done done
echo $TICK$GREEN"Applications installed."$ENDCOLOR echo -e $TICK$GREEN"Applications installed."$ENDCOLOR
} }
list_configs(){ list_configs(){
# Lists the config files found in ~/.config/autodeploy/*.conf # Lists the config files found in ~/.config/autodeploy/*.conf
echo $TICK$GREEN"Listing configs found in $BLUE$CONFIG_PATH"$ENDCOLOR echo -e $TICK$GREEN"Listing configs found in $BLUE$CONFIG_PATH"$ENDCOLOR
echo -n $BLUE echo -e -n $BLUE
ls $CONFIG_PATH | grep "_config$" ls $CONFIG_PATH | grep "_config$"
} }
@ -133,12 +133,12 @@ collect_files(){
git -C $CONFIG_PATH pull origin main --allow-unrelated-histories > /dev/null 2>&1 git -C $CONFIG_PATH pull origin main --allow-unrelated-histories > /dev/null 2>&1
# Check if the configuration path already exists # Check if the configuration path already exists
echo $TICK$GREEN"Moving files"$ENDCOLOR echo -e $TICK$GREEN"Moving files"$ENDCOLOR
if test -d $HOST_CONFIG_PATH;then if test -d $HOST_CONFIG_PATH;then
echo $TICK$GREEN"Creating files in$BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR echo -e $TICK$GREEN"Creating files in$BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR
else else
mkdir -p $HOST_CONFIG_PATH mkdir -p $HOST_CONFIG_PATH
echo $TICK$GREEN"Creating files in$BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR echo -e $TICK$GREEN"Creating files in$BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR
fi fi
# Copy each line in $CONFIG_PATH/autodeploy_files.conf to $HOST_CONFIG_PATH # Copy each line in $CONFIG_PATH/autodeploy_files.conf to $HOST_CONFIG_PATH
@ -147,12 +147,12 @@ collect_files(){
# Copies all files listed in $HOST_CONFIG_PATH/autodeploy_files.conf recursively, verbosely, and forcefully to the staging area. Filters out un-needed lines, and logs them to $hostname_files.log # Copies all files listed in $HOST_CONFIG_PATH/autodeploy_files.conf recursively, verbosely, and forcefully to the staging area. Filters out un-needed lines, and logs them to $hostname_files.log
cp -rvf --parents $line $HOST_CONFIG_PATH | grep "^'" | awk '{print $1}' | sed "s/'//g" | sed 's@'"$HOME"'@$HOME@' >> $HOST_CONFIG_PATH/$(hostname)_files.log cp -rvf --parents $line $HOST_CONFIG_PATH | grep "^'" | awk '{print $1}' | sed "s/'//g" | sed 's@'"$HOME"'@$HOME@' >> $HOST_CONFIG_PATH/$(hostname)_files.log
# Going to need to add sorting somewhere in here because this log will keep growing # Going to need to add sorting somewhere in here because this log will keep growing
echo $TICK_MOVE$GREEN" Copied $BLUE$line$GREEN to $BLUE$HOST_CONFIG_PATH"$ENDCOLOR echo -e $TICK_MOVE$GREEN" Copied $BLUE$line$GREEN to $BLUE$HOST_CONFIG_PATH"$ENDCOLOR
done < $HOST_CONFIG_PATH/autodeploy_files.conf | grep -v "^#" done < $HOST_CONFIG_PATH/autodeploy_files.conf | grep -v "^#"
cd $CONFIG_PATH cd $CONFIG_PATH
echo $TICK$GREEN"Configuration files saved to $BLUE$HOST_CONFIG_PATH$GREEN. Files can be pushed to $BLUE$remote_repo$GREEN with$BLUE autodeploy -p$GREEN"$ENDCOLOR echo -e $TICK$GREEN"Configuration files saved to $BLUE$HOST_CONFIG_PATH$GREEN. Files can be pushed to $BLUE$remote_repo$GREEN with$BLUE autodeploy -p$GREEN"$ENDCOLOR
} }
@ -170,7 +170,7 @@ edit_files() {
} }
move_dev(){ move_dev(){
if [ -z "$2" ];then if [ -z "$2" ];then
echo $TICK$GREEN"No arguments supplied, using configuration in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR echo -e $TICK$GREEN"No arguments supplied, using configuration in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR
collect_files collect_files
else else
select_config "$@" select_config "$@"
@ -179,10 +179,10 @@ move_dev(){
} }
select_config(){ select_config(){
echo $TICK_ERROR$YELLOW"Please specify the name of the config file you wish to use"$ENDCOLOR echo -e $TICK_ERROR$YELLOW"Please specify the name of the config file you wish to use"$ENDCOLOR
selected_config=$2 selected_config=$2
if test -d "$CONFIG_PATH/$selected_config";then if test -d "$CONFIG_PATH/$selected_config";then
echo $TICK$GREEN"$selected_config selected" echo -e $TICK$GREEN"$selected_config selected"
distribute_files distribute_files
else else
list_configs list_configs
@ -193,17 +193,17 @@ select_config(){
check_git(){ check_git(){
# Check if the autodeploy configuration files are are in the current repo. If not, creates them # Check if the autodeploy configuration files are are in the current repo. If not, creates them
if ! test -f "$CONFIG_PATH/autodeploy_files.conf";then if ! test -f "$CONFIG_PATH/autodeploy_files.conf";then
echo $TICK$GREEN"Config file not found, generating base configuration..."$ENDCOLOR echo -e $TICK$GREEN"Config file not found, generating base configuration..."$ENDCOLOR
echo "config_name=$(hostname)" > $CONFIG_PATH/autodeploy_config.conf echo -e "config_name=$(hostname)" > $CONFIG_PATH/autodeploy_config.conf
# Add $remote_repo to autodeploy_config # Add $remote_repo to autodeploy_config
echo "$remote_repo" >> $CONFIG_PATH/autodeploy_config.conf echo -e "$remote_repo" >> $CONFIG_PATH/autodeploy_config.conf
# Add default applications to autodeploy_apps # Add default applications to autodeploy_apps
echo "curl\nneovim\nzsh" > $CONFIG_PATH/autodeploy_apps.conf echo -e "curl\nneovim\nzsh" > $CONFIG_PATH/autodeploy_apps.conf
# Add default dot files to autodeploy_files.conf # Add default dot files to autodeploy_files.conf
echo ".tmux.conf" > $CONFIG_PATH/autodeploy_files.conf echo -e ".tmux.conf" > $CONFIG_PATH/autodeploy_files.conf
fi fi
} }
@ -212,18 +212,18 @@ get_files(){
cd $CONFIG_PATH cd $CONFIG_PATH
git -C $CONFIG_PATH pull origin main --allow-unrelated-histories # > /dev/null 2>&1; # Figure out how to check if repo exists git -C $CONFIG_PATH pull origin main --allow-unrelated-histories # > /dev/null 2>&1; # Figure out how to check if repo exists
check_git check_git
echo $TICK$GREEN"Pull complete"$ENDCOLOR echo -e $TICK$GREEN"Pull complete"$ENDCOLOR
} }
remote_push(){ remote_push(){
# Commit and push files to $remote_repo # Commit and push files to $remote_repo
cd $CONFIG_PATH cd $CONFIG_PATH
echo $TICK$GREEN"Adding Files"$ENDCOLOR echo -e $TICK$GREEN"Adding Files"$ENDCOLOR
git add . git add .
echo $TICK$GREEN"Commiting"$ENDCOLOR echo -e $TICK$GREEN"Commiting"$ENDCOLOR
git commit -m "Autodeploy from $(hostname) on $(date)" git commit -m "Autodeploy from $(hostname) on $(date)"
echo $TICK$GREEN"Pushing"$ENDCOLOR echo -e $TICK$GREEN"Pushing"$ENDCOLOR
git push -u origin main git push -u origin main
} }
@ -232,7 +232,7 @@ backup_old(){
# Backs up all the files that will be overwritten by autodeploy # Backs up all the files that will be overwritten by autodeploy
mkdir -p $HOST_CONFIG_PATH"backup" mkdir -p $HOST_CONFIG_PATH"backup"
while read line; do while read line; do
echo $TICK_BACKUP$GREEN"Backing up $BLUE$line$GREEN to $BLUE$BACKUP_DIR" echo -e $TICK_BACKUP$GREEN"Backing up $BLUE$line$GREEN to $BLUE$BACKUP_DIR"
cp -rf $HOME/$line $BACKUP_DIR > /dev/null 2>&1; cp -rf $HOME/$line $BACKUP_DIR > /dev/null 2>&1;
done < $CONFIG_PATH/autodeploy_files.conf # Fix done < $CONFIG_PATH/autodeploy_files.conf # Fix
} }
@ -251,18 +251,18 @@ distribute_files(){
# Need an odd for loop syntax because zsh handles file globs differently than bash # Need an odd for loop syntax because zsh handles file globs differently than bash
for f in .[!.]* *; do for f in .[!.]* *; do
echo $TICK_MOVE$GREEN"Copying $BLUE$f$GREEN to $BLUE$HOME" echo -e $TICK_MOVE$GREEN"Copying $BLUE$f$GREEN to $BLUE$HOME"
cp -rf $f $HOME # Going to need to figure out a way to move all files except for the backup folder cp -rf $f $HOME # Going to need to figure out a way to move all files except for the backup folder
done done
} }
main(){ main(){
# Check if this is the first time autodeploy is being ran # Check if this is the first time autodeploy is being ran
echo $selected_config echo -e $selected_config
if !(test -d $CONFIG_PATH);then if !(test -d $CONFIG_PATH);then
first_setup first_setup
echo $NOCOLOR$TICK$GREEN"First time setup complete, use$BLUE autodeploy -f $GREEN to rerun first time setup" echo -e $NOCOLOR$TICK$GREEN"First time setup complete, use$BLUE autodeploy -f $GREEN to rerun first time setup"
fi fi
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
@ -274,61 +274,61 @@ main(){
case "${o}" in case "${o}" in
l) l)
c=${OPTARG} c=${OPTARG}
echo $TICK$GREEN$TITLE"Listing available configuration files"$ENDCOLOR echo -e $TICK$GREEN$TITLE"Listing available configuration files"$ENDCOLOR
list_configs list_configs
;; ;;
e) e)
e=${OPTARG} e=${OPTARG}
echo $TICK$GREEN$TITLE"Editing Files"$ENDCOLOR echo -e $TICK$GREEN$TITLE"Editing Files"$ENDCOLOR
edit_files edit_files
;; ;;
p) p)
c=${OPTARG} c=${OPTARG}
echo $TICK$BLUE"Push config to $remote_repo"$ENDCOLOR echo -e $TICK$BLUE"Push config to $remote_repo"$ENDCOLOR
remote_push remote_push
;; ;;
g) g)
g=${OPTARG} g=${OPTARG}
echo $TICK$GREEN"Getting config from $BLUE$remote_repo"$ENDCOLOR echo -e $TICK$GREEN"Getting config from $BLUE$remote_repo"$ENDCOLOR
get_files get_files
;; ;;
c) c)
c=${OPTARG} c=${OPTARG}
echo $TICK$GREEN"Collecting config files and storing them in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR echo -e $TICK$GREEN"Collecting config files and storing them in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR
collect_files collect_files
;; ;;
f) f)
f=${OPTARG} f=${OPTARG}
echo $TICK$BLUE"Re-running first time setup"$ENDCOLOR echo -e $TICK$BLUE"Re-running first time setup"$ENDCOLOR
;; ;;
a) a)
a=${OPTARG} a=${OPTARG}
echo $TICK$BLUE"Installing applications"$ENDCOLOR echo -e $TICK$BLUE"Installing applications"$ENDCOLOR
install_apps install_apps
;; ;;
b) b)
b=${OPTARG} b=${OPTARG}
echo $TICK$BLUE"Backing up current dotfiles to $BACKUP_DIR"$ENDCOLOR echo -e $TICK$BLUE"Backing up current dotfiles to $BACKUP_DIR"$ENDCOLOR
backup_old backup_old
;; ;;
m) m)
m=${OPTARG} m=${OPTARG}
echo $BOLD$BLUE"Move files to correct locations"$ENDCOLOR echo -e $BOLD$BLUE"Move files to correct locations"$ENDCOLOR
echo $GREEN$BOLD"---------------------------------------"$ENDCOLOR echo -e $GREEN$BOLD"---------------------------------------"$ENDCOLOR
distribute_files distribute_files
;; ;;
n) n)
n=${OPTARG} n=${OPTARG}
echo $BOLD$BLUE"Running full new client install"$ENDCOLOR echo -e $BOLD$BLUE"Running full new client install"$ENDCOLOR
echo $GREEN$BOLD"---------------------------------------"$ENDCOLOR echo -e $GREEN$BOLD"---------------------------------------"$ENDCOLOR
new_client new_client
;; ;;
d) d)
d=${OPTARG} d=${OPTARG}
echo $BOLD$BLUE"Running move dev"$ENDCOLOR echo -e $BOLD$BLUE"Running move dev"$ENDCOLOR
echo $OPTARG echo -e $OPTARG
echo $GREEN$BOLD"---------------------------------------"$ENDCOLOR echo -e $GREEN$BOLD"---------------------------------------"$ENDCOLOR
move_dev "$@" move_dev "$@"
;; ;;
?) ?)

Loading…
Cancel
Save