From 71ca410123abf3cfed8bf4ae7461785414fa82e5 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 25 Oct 2025 15:12:03 -0700 Subject: [PATCH] Add ability to spawn basic configurations for testing. --- setup.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 3664124..c571464 100755 --- a/setup.sh +++ b/setup.sh @@ -15,7 +15,7 @@ BRANCH="main" function usage { cat <<- EOF - $PROG [-l] [-b branch_name] [-h] + $PROG [-l] [-b branch_name] [-g] [-w] [-s] [-h] Program to initialize synchronization with Hyperling's Ansible configuration. $URL @@ -23,7 +23,10 @@ function usage { -l : Run the local playbook associated with this $PROG. This is helpful for development or just saving bandwidth. It also provides prettier colors than the plaintext from ansible-pull. ;) - -b branch_name: Download and run a specific branch. Default is $BRANCH. + -b branch_name : Download and run a specific branch. Default is $BRANCH. + -g : Enable the General config with test contents. + -w : Enable the Workstation config with test contents. + -s : Enable the Server config with test contents. -h : Display this help text EOF @@ -32,10 +35,13 @@ function usage { ## Parameter Parsing ## -while getopts ":lb:h" arg; do +while getopts ":lb:gwsh" arg; do case $arg in l) local="Y" && echo "Running $LOCAL as the playbook." ;; b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;; + l) create_general="Y" && echo "Creating basic '$general_config'." ;; + l) create_workstation="Y" && echo "Creating basic '$workstation_config'." ;; + l) create_server="Y" && echo "Creating basic '$server_config'." ;; h) usage ;; *) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;; esac @@ -52,6 +58,19 @@ if [[ -z "$local" && "$branch" == "" ]]; then branch="$BRANCH" fi +if [[ -n "$create_general" && -f "$general_config" ]]; then + echo "WARNING: General configuration already exists, will not overwrite." + ls -lh "$general" +fi +if [[ -n "$create_workstation" && -f "$workstation_config" ]]; then + echo "WARNING: Workstation configuration already exists, will not overwrite." + ls -lh "$workstation_config" +fi +if [[ -n "$create_server" && -f "$server_config" ]]; then + echo "WARNING: Server configuration already exists, will not overwrite." + ls -lh "$server_config" +fi + ## Main ## os="$(cat /etc/os-release)" @@ -105,6 +124,41 @@ echo "Installed!" #ansible-galaxy collection install community.general #echo "Added!" +# Create basic layouts if configs do not exist and are requested. +if [[ -n "$create_general" && ! -f "$general_config" ]]; then + function print_general_contents { + cat <<- EOF + enable=true + user=test + user_desc=Test + branch=$branch + EOF + } + print_general_contents > "$general_config" +fi +if [[ -n "$create_workstation" && ! -f "$workstation_config" ]]; then + function print_workstation_contents { + cat <<- EOF + enable=true + user=test + user_desc=Test + branch=$branch + EOF + } + print_workstation_contents > "$workstation_config" +fi +if [[ -n "$create_server" && ! -f "$server_config" ]]; then + function print_server_contents { + cat <<- EOF + enable=true + user=test + user_desc=Test + branch=$branch + EOF + } + print_server_contents > "$server_config" +fi + echo "Provisioning Ansible..." if [[ $local == "Y" ]]; then sudo ansible-playbook $LOCAL