2023-10-09 11:09:40 -07:00
|
|
|
function main {
|
2023-10-10 14:16:24 -07:00
|
|
|
STACKS_DIRECTORY="/home/admin/homelab/fighter/config"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
2023-10-09 11:09:40 -07:00
|
|
|
case $1 in
|
2023-10-10 15:52:02 -07:00
|
|
|
# parse global flags
|
2023-10-10 14:21:48 -07:00
|
|
|
-n|--nas-only) NAS_ONLY=true; shift ;;
|
2023-10-10 14:16:24 -07:00
|
|
|
-l|--lint) LINT=true; shift ;;
|
|
|
|
-p|--path) STACKS_DIRECTORY="$2"; shift; shift ;;
|
|
|
|
-v|--verbose) VERBOSE=true; shift ;;
|
2023-10-10 15:52:02 -07:00
|
|
|
# parse command
|
|
|
|
up*) COMMAND="docker-compose up -d"; shift;
|
2023-10-10 14:16:24 -07:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2023-10-10 15:52:02 -07:00
|
|
|
-f|--force-recreate) COMMAND="$COMMAND --force-recreate"; shift;;
|
2023-10-10 14:29:53 -07:00
|
|
|
*) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;;
|
2023-10-10 14:16:24 -07:00
|
|
|
esac
|
|
|
|
done
|
2023-10-09 11:21:23 -07:00
|
|
|
;;
|
2023-10-10 15:52:02 -07:00
|
|
|
down*) COMMAND="docker-compose down"; shift;
|
2023-10-10 14:16:24 -07:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2023-10-10 15:52:02 -07:00
|
|
|
-o|--remove-orphans) COMMAND="$COMMAND --remove-orphans"; shift;;
|
2023-10-10 14:29:53 -07:00
|
|
|
*) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
config*) COMMAND="config"; shift;
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2023-10-10 15:52:02 -07:00
|
|
|
-n|--no-interpolate) COMMAND="$COMMAND --no-interpolate"; shift;;
|
2023-10-10 14:29:53 -07:00
|
|
|
*) echo "Unrecognized option '$1' for '$COMMAND'"; exit 1;;
|
2023-10-10 14:16:24 -07:00
|
|
|
esac
|
|
|
|
done
|
2023-10-09 11:21:23 -07:00
|
|
|
;;
|
2023-10-10 14:16:24 -07:00
|
|
|
*) echo "Unrecognized option $1"; exit 1 ;;
|
2023-10-09 11:09:40 -07:00
|
|
|
esac
|
|
|
|
done
|
2023-10-10 14:16:24 -07:00
|
|
|
|
2023-10-10 15:53:32 -07:00
|
|
|
if [ ! $COMMAND ]; then
|
|
|
|
echo "Error: no command specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-10 14:16:24 -07:00
|
|
|
for stack in "$STACKS_DIRECTORY"/* ; do
|
2023-10-10 14:36:07 -07:00
|
|
|
cd $stack
|
2023-10-10 15:00:13 -07:00
|
|
|
if [ $NAS_ONLY ] || [ $LINT ]; then
|
|
|
|
TMP=$(docker-compose config)
|
|
|
|
PASS=$?
|
2023-10-10 15:52:02 -07:00
|
|
|
if [ $PASS != 0 ]; then
|
|
|
|
echo "ERROR: $stack failed to lint"
|
|
|
|
continue
|
|
|
|
fi
|
2023-10-10 15:00:13 -07:00
|
|
|
if [ $NAS_ONLY ]; then
|
|
|
|
echo $TMP | grep -q /mnt/nas
|
|
|
|
NAS_DEPENDENT=$?
|
2023-10-10 15:52:02 -07:00
|
|
|
if [ $NAS_DEPENDENT == 1 ]; then
|
|
|
|
continue
|
2023-10-10 15:00:13 -07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2023-10-10 15:52:02 -07:00
|
|
|
|
|
|
|
echo "${PWD} $COMMAND"
|
2023-10-10 14:16:24 -07:00
|
|
|
done
|
2023-10-09 11:09:40 -07:00
|
|
|
}
|
|
|
|
|
2023-10-10 14:16:24 -07:00
|
|
|
ARGS="$@"
|
|
|
|
|
|
|
|
main $ARGS
|