From 0a20024a44beec657737be9467afa47d604affef Mon Sep 17 00:00:00 2001 From: Allen <63997543+aaw3@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:55:41 -0600 Subject: [PATCH] Clean up manage script --- data/docker/compose/manage | 51 +++++++++----------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/data/docker/compose/manage b/data/docker/compose/manage index d1e87d3..f2798d7 100755 --- a/data/docker/compose/manage +++ b/data/docker/compose/manage @@ -1,7 +1,6 @@ #!/bin/bash -# Note: all up scripts use set -a to export all variables created, set +a can be used to then turn off this effect -trap exiting EXIT #Print done when program exits +trap exiting EXIT # Handle program exit export VARIABLES_DIR=${PWD%/*}/variables/compose source $VARIABLES_DIR @@ -16,24 +15,21 @@ CONTAINERS="" BASE_DIR=$PWD all () { - ALL=$(ls -d */ | sed 's/\/$//') #Using -d and */ to get just directories, sed removes the trailing backslash if there is one -} #This method only works for one worded variables as all spaces will split variables! + ALL=$(ls -d */ | sed 's/\/$//') # Remove trailing backslashes +} -# If running comamnds, put all commands into an array if [[ "$1" == "run" ]]; then -# PROGRAMS=$(echo "${@:3}" | tr ';' '\n') - mapfile -t PROGRAMS < <(echo "${@:3}" | tr ';' '\n') # This uses an array which allows for spaces! + mapfile -t PROGRAMS < <(echo "${@:3}" | tr ';' '\n') fi -# If wanting to run the specified command under all containers, put all containers in a list, otherwise use user specified if [[ "$2" == "ALL" ]]; then all CONTAINERS=$ALL else - CONTAINERS=$(echo "$2" | tr '|' '\n') #This method only works for one worded variables as all spaces will split variables! + CONTAINERS=$(echo "$2" | tr '|' '\n') fi -# Pull if run or restart has the -P or --pull option as the 3rd arg or later (shouldn't be before 3rd) +# Pull if run or restart has the -P or --pull option as the 3rd arg or later if [[ "$1" == "up" || "$1" == "restart" ]]; then for arg in "${@:3}" do @@ -64,14 +60,11 @@ process () { return; fi exe="${1/\[CONTAINER\]/"$2"}" - #exe=$(echo "$1" | sed "s/\[CONTAINER\]/$2/g") # This works too, but using shorter method instead echo "Running under \"$2\":" echo "* $exe *" - bash -c "$exe" # Actually must use bash -c, otherwises running something like echo hi > test.txt will print everything instead of echoing it + bash -c "$exe" # -c is needed to run all bash syntax inside the bash instance } -# might be completely redundant to have a separate function for each, but allows for overrides. Also having a restart script for more customizability as well as I cannot easily keep track of what processes are in background, so having a restart script will manage all that for each service - up () { for container in $CONTAINERS; do $PWD/$container/up & @@ -94,33 +87,13 @@ run () { for container in $CONTAINERS; do cd $BASE_DIR cd $container -# echo "before loop" - #for program in $PROGRAMS; do -# echo "before prog" - #echo "$program" - #PROGRAMS=$(echo "${@:3}" | tr ';' '\n') - #echo $PROGRAMS - echo "$container:" - for i in "${PROGRAMS[@]}"; do - process "$i" $container - done -# echo "after prog" - #done -# echo "after loop" + echo "$container:" + for i in "${PROGRAMS[@]}"; do + process "$i" $container + done done } -#manage-var() { -# VAR="PATH_VAR_$2" -# VAR=${!VAR} -# if [ -z "$VAR" ] -# then -# prt-var -# exit 0 -# fi -# return $VAR -#} - ed-cmp () { for container in $CONTAINERS; do nano $PWD/$container/$3 @@ -244,7 +217,7 @@ case $COMMAND in ;; run) - run "$@" #I originally just had this as $@, without quotes, which separated all of the variables and caused massive issues + run "$@" ;; help)