Added usage statement

main
Graham Helton 2 years ago
parent dcf2956896
commit a6996720b4

@ -1,5 +1,6 @@
#/bin/bash #/bin/bash
# Preamble # Preamble
BOLD="\e[1m"
RED="\e[31m" RED="\e[31m"
BLUE="\e[94m" BLUE="\e[94m"
GREEN="\e[32m" GREEN="\e[32m"
@ -7,7 +8,7 @@ YELLOW="\e[33m"
ENDCOLOR="\e[0m" ENDCOLOR="\e[0m"
TITLE="\e[4m" TITLE="\e[4m"
TICK="[$GREEN+$ENDCOLOR] " TICK="[$GREEN+$ENDCOLOR] "
TICK_MOVE="[$GREEN~>$ENDCOLOR] " TICK_MOVE="[$GREEN~>$ENDCOLOR]"
TICK_BACKUP="[$GREEN<~~$ENDCOLOR] " TICK_BACKUP="[$GREEN<~~$ENDCOLOR] "
TICK_INPUT="[$YELLOW!$ENDCOLOR] " TICK_INPUT="[$YELLOW!$ENDCOLOR] "
TAB="--" TAB="--"
@ -18,19 +19,14 @@ FILE_LOG=$HOST_CONFIG_PATH$(hostname)_files.log
remote_repo="http://iroh.int/Graham/ConfigFiles.git" remote_repo="http://iroh.int/Graham/ConfigFiles.git"
user=$(hostname) user=$(hostname)
usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; } # Copy and pasted, need to update usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 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(){ first_setup(){
echo $TICK$GREEN"Running first time setup"$ENDCOLOR echo $TICK$GREEN"Running first time setup"$ENDCOLOR
echo $TICK$GREEN"Creating Configuration Files in $BLUE~/.config/autodeploy/ "$ENDCOLOR echo $TICK$GREEN"Creating Configuration Files in $BLUE~/.config/autodeploy/ "$ENDCOLOR
mkdir -p ~/.config/autodeploy/ 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"Enter your remote git repository URL"$ENDCOLOR
echo $TICK$GREEN"For example: $BLUE"https://github.com/grahamhelton/DotFiles""$ENDCOLOR echo $TICK$GREEN"For example: $BLUE"https://github.com/grahamhelton/DotFiles""$ENDCOLOR
@ -75,7 +71,7 @@ get_posture(){
install_apt(){ install_apt(){
echo $TICK$BLUE"Please input SUDO password"$ENDCOLOR 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"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 echo $temp_output
} }
list_configs(){ list_configs(){
@ -106,38 +102,37 @@ stage_files(){
} }
edit_files() {
"${EDITOR:-vi}" $CONFIG_PATH/$OPTARG
}
check_git(){ check_git(){
# Check if global_dotFiles.conf is in the current repo # Check if global_dotFiles.conf is in the current repo
if test -f "$CONFIG_PATH/global_dotFiles.conf";then if ! test -f "$CONFIG_PATH/global_dotFiles.conf";then
echo $RED"-------DEBUG--------"
echo $TICK$GREEN"Config file already found"$ENDCOLOR
else
echo $RED"-------DEBUG--------"
echo $TICK$GREEN"Config file not found, generating base configuration..."$ENDCOLOR echo $TICK$GREEN"Config file not found, generating base configuration..."$ENDCOLOR
echo "config_name=$(hostname)" > $CONFIG_PATH/global_config.conf echo "config_name=$(hostname)" > $CONFIG_PATH/global_config.conf
# Add $remote_repo to global_config # Add $remote_repo to global_config
echo "$remote_repo" >> $CONFIG_PATH/global_config.conf echo "$remote_repo" >> $CONFIG_PATH/global_config.conf
# Add default applications to global_applications # Add default applications to global_apps
echo "curl\nneovim\nzsh" >> $CONFIG_PATH/global_applications.conf echo "curl\nneovim\nzsh" > $CONFIG_PATH/global_apps.conf
# Add default dot files to global_dotFiles.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 fi
} }
pull_files(){ get_files(){
# Push files to $remote_repo # Push files to $remote_repo
cd $CONFIG_PATH cd $CONFIG_PATH
echo $TICK$GREEN"Pulling Files"$ENDCOLOR 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
check_git 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 # 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 # Push files to $remote_repo
cd $CONFIG_PATH cd $CONFIG_PATH
echo $TICK$GREEN"Adding Files"$ENDCOLOR echo $TICK$GREEN"Adding Files"$ENDCOLOR
@ -163,21 +158,47 @@ distribute_files(){
backup_old backup_old
cd $HOST_CONFIG_PATH cd $HOST_CONFIG_PATH
for f in .[!.]* *; do for f in .[!.]* *; do
echo "Copying $f to $HOME" echo $TICK_MOVE$GREEN"Copying $BLUE$f$GREEN to $BLUE$HOME"
cp -rf $f $HOME cp -rf $f $HOME # Going to need to figure out a way to move all files except for the backup folder
# Going to need to figure out a way to move all files except for the backup folder
done done
#echo $TICK_MOVE$GREEN"Copied $BLUE$line$GREEN to $BLUE$BACKUP_DIR"$ENDCOLOR #echo $TICK_MOVE$GREEN"Copied $BLUE$line$GREEN to $BLUE$BACKUP_DIR"$ENDCOLOR
} }
main(){ 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 <File> $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 # Check if this is the first time autodeploy is being ran
if !(test -d $CONFIG_PATH);then if !(test -d $CONFIG_PATH);then
first_setup first_setup
fi fi
# Process command line arugments # 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 case "${o}" in
# Pull config # Pull config
l) l)
@ -185,29 +206,31 @@ main(){
echo $TICK$GREEN$TITLE"Listing available configuration files"$ENDCOLOR echo $TICK$GREEN$TITLE"Listing available configuration files"$ENDCOLOR
list_configs list_configs
;; ;;
c) e)
c=${OPTARG} e=${OPTARG}
echo $TICK$BLUE"Commit config to $remote_repo"$ENDCOLOR echo $TICK$GREEN$TITLE"Editing Files"$ENDCOLOR
remote_commit edit_files
;; ;;
p) p)
c=${OPTARG} c=${OPTARG}
echo $TICK$BLUE"Pulling config from $remote_repo"$ENDCOLOR echo $TICK$BLUE"Push config to $remote_repo"$ENDCOLOR
pull_files remote_push
;; ;;
# Commit config g)
s) g=${OPTARG}
s=${OPTARG} echo $TICK$GREEN"Getting config from $BLUE$remote_repo"$ENDCOLOR
echo $TICK$GREEN"Staging config files to $BLUE$HOST_CONFIG_PATH"$ENDCOLOR get_files
;;
c)
c=${OPTARG}
echo $TICK$GREEN"Collecting config files and storing them in $BLUE$HOST_CONFIG_PATH"$ENDCOLOR
stage_files stage_files
;; ;;
# Full install
f) f)
f=${OPTARG} f=${OPTARG}
echo $TICK$BLUE"Running full install"$ENDCOLOR echo $TICK$BLUE"Re-running first time setup"$ENDCOLOR
;; ;;
# Only install applications
a) a)
a=${OPTARG} a=${OPTARG}
echo $TICK$BLUE"Installing applications"$ENDCOLOR echo $TICK$BLUE"Installing applications"$ENDCOLOR
@ -218,12 +241,13 @@ main(){
echo $TICK$BLUE"Backing up current dotfiles to $BACKUP_DIR"$ENDCOLOR echo $TICK$BLUE"Backing up current dotfiles to $BACKUP_DIR"$ENDCOLOR
backup_old backup_old
;; ;;
d) m)
d=${OPTARG} m=${OPTARG}
echo $TICK$BLUE"Distributing files to correct locations"$ENDCOLOR echo $BOLD$BLUE"Move files to correct locations"$ENDCOLOR
echo $GREEN$BOLD"---------------------------------------"$ENDCOLOR
distribute_files distribute_files
;; ;;
*) ?)
usage usage
;; ;;
esac esac

Loading…
Cancel
Save