Clean up manage script
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/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
|
export VARIABLES_DIR=${PWD%/*}/variables/compose
|
||||||
source $VARIABLES_DIR
|
source $VARIABLES_DIR
|
||||||
@ -16,24 +15,21 @@ CONTAINERS=""
|
|||||||
BASE_DIR=$PWD
|
BASE_DIR=$PWD
|
||||||
|
|
||||||
all () {
|
all () {
|
||||||
ALL=$(ls -d */ | sed 's/\/$//') #Using -d and */ to get just directories, sed removes the trailing backslash if there is one
|
ALL=$(ls -d */ | sed 's/\/$//') # Remove trailing backslashes
|
||||||
} #This method only works for one worded variables as all spaces will split variables!
|
}
|
||||||
|
|
||||||
# If running comamnds, put all commands into an array
|
|
||||||
if [[ "$1" == "run" ]]; then
|
if [[ "$1" == "run" ]]; then
|
||||||
# PROGRAMS=$(echo "${@:3}" | tr ';' '\n')
|
mapfile -t PROGRAMS < <(echo "${@:3}" | tr ';' '\n')
|
||||||
mapfile -t PROGRAMS < <(echo "${@:3}" | tr ';' '\n') # This uses an array which allows for spaces!
|
|
||||||
fi
|
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
|
if [[ "$2" == "ALL" ]]; then
|
||||||
all
|
all
|
||||||
CONTAINERS=$ALL
|
CONTAINERS=$ALL
|
||||||
else
|
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
|
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
|
if [[ "$1" == "up" || "$1" == "restart" ]]; then
|
||||||
for arg in "${@:3}"
|
for arg in "${@:3}"
|
||||||
do
|
do
|
||||||
@ -64,14 +60,11 @@ process () {
|
|||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
exe="${1/\[CONTAINER\]/"$2"}"
|
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 "Running under \"$2\":"
|
||||||
echo "* $exe *"
|
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 () {
|
up () {
|
||||||
for container in $CONTAINERS; do
|
for container in $CONTAINERS; do
|
||||||
$PWD/$container/up &
|
$PWD/$container/up &
|
||||||
@ -94,33 +87,13 @@ run () {
|
|||||||
for container in $CONTAINERS; do
|
for container in $CONTAINERS; do
|
||||||
cd $BASE_DIR
|
cd $BASE_DIR
|
||||||
cd $container
|
cd $container
|
||||||
# echo "before loop"
|
|
||||||
#for program in $PROGRAMS; do
|
|
||||||
# echo "before prog"
|
|
||||||
#echo "$program"
|
|
||||||
#PROGRAMS=$(echo "${@:3}" | tr ';' '\n')
|
|
||||||
#echo $PROGRAMS
|
|
||||||
echo "$container:"
|
echo "$container:"
|
||||||
for i in "${PROGRAMS[@]}"; do
|
for i in "${PROGRAMS[@]}"; do
|
||||||
process "$i" $container
|
process "$i" $container
|
||||||
done
|
done
|
||||||
# echo "after prog"
|
|
||||||
#done
|
|
||||||
# echo "after loop"
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#manage-var() {
|
|
||||||
# VAR="PATH_VAR_$2"
|
|
||||||
# VAR=${!VAR}
|
|
||||||
# if [ -z "$VAR" ]
|
|
||||||
# then
|
|
||||||
# prt-var
|
|
||||||
# exit 0
|
|
||||||
# fi
|
|
||||||
# return $VAR
|
|
||||||
#}
|
|
||||||
|
|
||||||
ed-cmp () {
|
ed-cmp () {
|
||||||
for container in $CONTAINERS; do
|
for container in $CONTAINERS; do
|
||||||
nano $PWD/$container/$3
|
nano $PWD/$container/$3
|
||||||
@ -244,7 +217,7 @@ case $COMMAND in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
run)
|
run)
|
||||||
run "$@" #I originally just had this as $@, without quotes, which separated all of the variables and caused massive issues
|
run "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
help)
|
help)
|
||||||
|
Reference in New Issue
Block a user