Added first run check

main
Graham Helton 2 years ago
parent 9ee14654af
commit 7a5c4200f1

@ -1,29 +1,41 @@
#/bin/bash
# Pretext
# Preamble
RED="\e[31m"
BLUE="\e[94m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
TICK="[$GREEN+$ENDCOLOR] "
TICK_MOVE="[$GREEN~>$ENDCOLOR] "
TAB="--"
CONFIG_PATH=~/.config/autodeploy
HOST_CONFIG_PATH=~/.config/autodeploy/$(hostname)_config/
user=$(hostname)
usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; } # Copy and pasted, need to update
pre_check(){
# Sets default variables, creates config folder, and uses pre-existing config file if it exists
echo $TICK$BLUE"Running Pre-flight check"$ENDCOLOR
user=$(hostname)
echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR
echo $GREEN"*** $BLUE AutoDeploy - A pure bash configuration management tool$GREEN ***"$ENDCOLOR
echo $GREEN"-------------------------------------------------------------------"$ENDCOLOR
sleep 1
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/
if test -f $CONFIG_PATH/"$user"_config.txt ;then
echo "File exists"
. ~/.config/autodeploy/"$user"_config.txt
else
echo "config_name=$(hostname)" > ~/.config/autodeploy/config.txt
echo "remote_repo="https://github.com/grahamhelton"" >> ~/.config/autodeploy/config.txt
. ~/.config/autodeploy/config.txt
fi
echo $TICK$GREEN"Add your git repository by editing $BLUE~/.config/autodeploy/config.conf"$ENDCOLOR # Change this to accept user input
echo "config_name=$(hostname)" > $CONFIG_PATH/config.conf
echo "remote_repo="http://iroh.int/Graham/ConfigFiles.git"" >> $CONFIG_PATH/config.conf
. ~/.config/autodeploy/config.conf
cd $CONFIG_PATH
git init > /dev/null 2>&1;
git remote add origin $remote_repo > /dev/null 2>&1;
git checkout -b main> /dev/null 2>&1;
echo "config_name=$(hostname)" > $CONFIG_PATH/config.conf
echo "remote_repo="http://iroh.int:80/Graham/ConfigFiles.git"" >> $CONFIG_PATH/config.conf
. $CONFIG_PATH/config.conf
}
pre_check
# Handle command line options. Not sure why this isn't working inside a function
while getopts "p c f d" o; do
@ -43,10 +55,10 @@ pre_check
f=${OPTARG}
echo $TICK$BLUE"Running full install"$ENDCOLOR
;;
# Only install dot files
d)
# Only install applications
a)
d=${OPTARG}
echo $TICK$BLUE"Only installing dot files"$ENDCOLOR
echo $TICK$BLUE"Only installing applications"$ENDCOLOR
;;
*)
usage
@ -59,28 +71,69 @@ get_posture(){
# 1. Internet connectivity
# 2. Checks for dependencies
# 3.
# 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
echo $TICK"Internet Connectivity Detected"$ENDCOLOR
internet=True
else
echo $RED"Internet Connectivity Not Detected"$ENDCOLOR
internet=False
internet=false
fi
if apt help install -h > /dev/null 2>&1; then
echo $TICK"APT is installed"$ENDCOLOR
apt=True
apt=true
else
echo $RED"APT is NOT installed"$ENDCOLOR
apt=False
apt=false
fi
}
install_apt(){
echo $TICK$BLUE"Please input SUDO password"$ENDCOLOR
echo $TICK$GREEN"Running apt update and apt upgrade"$ENDCOLOR && sudo apt update -y> /dev/null 2>&1 && sudo apt upgrade -y > /dev/null 2>&1
echo $TICK$GREEN"Installing from $CONFIG_PATH/install.txt"$ENDCOLOR && xargs sudo apt install -y <$CONFIG_PATH/install.txt > /dev/null 2>&1
echo $TICK$GREEN"Running apt update and apt upgrade..."$ENDCOLOR ; sudo apt update -y> /dev/null 2>&1 && sudo apt upgrade -y > /dev/null 2>&1
echo $TICK$GREEN"Installing applications from $CONFIG_PATH/install.conf"$ENDCOLOR && xargs sudo apt install -y <$CONFIG_PATH/install.conf > /dev/null 2>&1
}
stage_files(){
# Grab files from around the system and move them to $CONFIG_PATH
if test -d $HOST_CONFIG_PATH;then
echo $TICK$GREEN"Config file already found in $BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR
else
mkdir -p $HOST_CONFIG_PATH
echo $TICK$GREEN"Created config file in $BLUE$CONFIG_PATH/$(hostname)_config"$ENDCOLOR
fi
# Copy each line in $CONFIG_PATH/files.conf to $HOST_CONFIG_PATH
while read line; do
cp -rf $HOME/$line $HOST_CONFIG_PATH
echo $TICK_MOVE$GREEN"Copied $BLUE$line$GREEN to $BLUE$HOST_CONFIG_PATH"$ENDCOLOR
done < $CONFIG_PATH/files.conf
}
get_posture
remote_push(){
# Push files to $remote_repo
cd $CONFIG_PATH
echo $TICK$GREEN"Adding Files"$ENDCOLOR
git add $HOST_CONFIG_PATH
echo $TICK$GREEN"Commiting"$ENDCOLOR
git commit -m "Autodeploy from $(hostname) on $(date)"
echo $TICK$GREEN"Pushing"$ENDCOLOR
git push -u origin main
}
main(){
if !(test -d $CONFIG_PATH);then
first_setup
else
echo "not first time"
fi
#stage_files
#remote_push
}
main

Loading…
Cancel
Save