From a6996720b4a98bfa3cc34abad928e57ba149f6b1 Mon Sep 17 00:00:00 2001 From: Graham Helton Date: Sun, 2 Oct 2022 17:54:17 -0400 Subject: [PATCH] Added usage statement --- autodeploy.sh | 110 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/autodeploy.sh b/autodeploy.sh index 1e45bf2..5165186 100755 --- a/autodeploy.sh +++ b/autodeploy.sh @@ -1,5 +1,6 @@ #/bin/bash # Preamble +BOLD="\e[1m" RED="\e[31m" BLUE="\e[94m" GREEN="\e[32m" @@ -7,7 +8,7 @@ YELLOW="\e[33m" ENDCOLOR="\e[0m" TITLE="\e[4m" TICK="[$GREEN+$ENDCOLOR] " -TICK_MOVE="[$GREEN~>$ENDCOLOR] " +TICK_MOVE="[$GREEN~>$ENDCOLOR]" TICK_BACKUP="[$GREEN<~~$ENDCOLOR] " TICK_INPUT="[$YELLOW!$ENDCOLOR] " TAB="--" @@ -18,19 +19,14 @@ FILE_LOG=$HOST_CONFIG_PATH$(hostname)_files.log remote_repo="http://iroh.int/Graham/ConfigFiles.git" user=$(hostname) usage() { echo "Usage: $0 [-s <45|90>] [-p ]" 1>&2; exit 1; } # Copy and pasted, need to update +clear -echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR -echo $GREEN"*** $BLUE AutoDeploy - A pure bash configuration management tool$GREEN ***"$ENDCOLOR -echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR -echo $TICK$GREEN"Autodeploy config path is located at $BLUE$CONFIG_PATH" -echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR first_setup(){ echo $TICK$GREEN"Running first time setup"$ENDCOLOR echo $TICK$GREEN"Creating Configuration Files in $BLUE~/.config/autodeploy/ "$ENDCOLOR mkdir -p ~/.config/autodeploy/ - echo $TICK$GREEN"Welcome to first time setup"$ENDCOLOR echo $TICK$GREEN"Enter your remote git repository URL"$ENDCOLOR echo $TICK$GREEN"For example: $BLUE"https://github.com/grahamhelton/DotFiles""$ENDCOLOR @@ -75,7 +71,7 @@ get_posture(){ install_apt(){ echo $TICK$BLUE"Please input SUDO password"$ENDCOLOR 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 $TICK$GREEN"Installing applications from $CONFIG_PATH/global_applications.conf"$ENDCOLOR && temp_output=$(xargs sudo apt install -y < $CONFIG_PATH/global_applications.conf) + echo $TICK$GREEN"Installing applications from $CONFIG_PATH/global_apps.conf"$ENDCOLOR && temp_output=$(xargs sudo apt install -y < $CONFIG_PATH/global_apps.conf) echo $temp_output } list_configs(){ @@ -106,38 +102,37 @@ stage_files(){ } +edit_files() { + +"${EDITOR:-vi}" $CONFIG_PATH/$OPTARG + +} check_git(){ # Check if global_dotFiles.conf is in the current repo - if test -f "$CONFIG_PATH/global_dotFiles.conf";then - echo $RED"-------DEBUG--------" - echo $TICK$GREEN"Config file already found"$ENDCOLOR - else - echo $RED"-------DEBUG--------" + if ! test -f "$CONFIG_PATH/global_dotFiles.conf";then echo $TICK$GREEN"Config file not found, generating base configuration..."$ENDCOLOR echo "config_name=$(hostname)" > $CONFIG_PATH/global_config.conf # Add $remote_repo to global_config echo "$remote_repo" >> $CONFIG_PATH/global_config.conf - # Add default applications to global_applications - echo "curl\nneovim\nzsh" >> $CONFIG_PATH/global_applications.conf + # Add default applications to global_apps + echo "curl\nneovim\nzsh" > $CONFIG_PATH/global_apps.conf # Add default dot files to global_dotFiles.conf - echo ".tmux.conf" >> $CONFIG_PATH/global_dotFiles.conf - - + echo ".tmux.conf" > $CONFIG_PATH/global_dotFiles.conf fi } -pull_files(){ +get_files(){ # Push files to $remote_repo cd $CONFIG_PATH - echo $TICK$GREEN"Pulling Files"$ENDCOLOR - git -C $CONFIG_PATH pull origin main --allow-unrelated-histories + git -C $CONFIG_PATH pull origin main --allow-unrelated-histories > /dev/null 2>&1; # Figure out how to check if repo exists check_git + echo $TICK$GREEN"Pull complete"$ENDCOLOR # This has an error during first time setup. If global files are already in the $CONFIG_PATH, the pull will fail because they'll be overwritten } -remote_commit(){ +remote_push(){ # Push files to $remote_repo cd $CONFIG_PATH echo $TICK$GREEN"Adding Files"$ENDCOLOR @@ -163,21 +158,47 @@ distribute_files(){ backup_old cd $HOST_CONFIG_PATH for f in .[!.]* *; do - echo "Copying $f to $HOME" - cp -rf $f $HOME - # Going to need to figure out a way to move all files except for the backup folder + echo $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 done #echo $TICK_MOVE$GREEN"Copied $BLUE$line$GREEN to $BLUE$BACKUP_DIR"$ENDCOLOR } main(){ + if [ $# -eq 0 ]; then + echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR + echo $GREEN"*** $BLUE AutoDeploy - A pure bash configuration management tool$GREEN ***"$ENDCOLOR + echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR + echo " +$BLUE Usage: + autodeploy -h + +$BLUE Options: + $GREEN -h$BLUE Show this [h]elp screen. + $GREEN-l$BLUE [L]ist available configuration files + $GREEN-p$BLUE [P]ush files to remote repository + $GREEN-g$BLUE [G]et files from the remote repository + $GREEN-c$BLUE [C]ollect configuration files on the local file system and prepare them for a remote push (-p) + $GREEN-f$BLUE Re-run [f]irst time setup + $GREEN-a$BLUE [I]nstalls applications found in global_apps.conf + $GREEN-b$BLUE [B]acks up files defined in global_dotFiles.conf + $GREEN-m$BLUE [M]oves dotfiles defined in global_dotFiles.conf to their correct locations on the local machine + $GREEN-e $BLUE[E]dits autodeploy's configuration files + + --moored Moored (anchored) mine. + --drifting Drifting mine. + + + " + exit 0 + fi # Check if this is the first time autodeploy is being ran if !(test -d $CONFIG_PATH);then first_setup fi # Process command line arugments - while getopts "d c p s f a b l" o; do + while getopts "m c p s f a b l :e:" o; do case "${o}" in # Pull config l) @@ -185,29 +206,31 @@ main(){ echo $TICK$GREEN$TITLE"Listing available configuration files"$ENDCOLOR list_configs ;; - c) - c=${OPTARG} - echo $TICK$BLUE"Commit config to $remote_repo"$ENDCOLOR - remote_commit + e) + e=${OPTARG} + echo $TICK$GREEN$TITLE"Editing Files"$ENDCOLOR + edit_files ;; p) c=${OPTARG} - echo $TICK$BLUE"Pulling config from $remote_repo"$ENDCOLOR - pull_files + echo $TICK$BLUE"Push config to $remote_repo"$ENDCOLOR + remote_push ;; - # Commit config - s) - s=${OPTARG} - echo $TICK$GREEN"Staging config files to $BLUE$HOST_CONFIG_PATH"$ENDCOLOR + g) + g=${OPTARG} + echo $TICK$GREEN"Getting config from $BLUE$remote_repo"$ENDCOLOR + get_files + ;; + c) + c=${OPTARG} + echo $TICK$GREEN"Collecting config files and storing them in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR stage_files ;; - # Full install f) f=${OPTARG} - echo $TICK$BLUE"Running full install"$ENDCOLOR + echo $TICK$BLUE"Re-running first time setup"$ENDCOLOR ;; - # Only install applications a) a=${OPTARG} echo $TICK$BLUE"Installing applications"$ENDCOLOR @@ -218,12 +241,13 @@ main(){ echo $TICK$BLUE"Backing up current dotfiles to $BACKUP_DIR"$ENDCOLOR backup_old ;; - d) - d=${OPTARG} - echo $TICK$BLUE"Distributing files to correct locations"$ENDCOLOR + m) + m=${OPTARG} + echo $BOLD$BLUE"Move files to correct locations"$ENDCOLOR + echo $GREEN$BOLD"---------------------------------------"$ENDCOLOR distribute_files ;; - *) + ?) usage ;; esac