homelab/fighter/scripts/docker-stacks.sh

77 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2023-10-16 22:37:51 -07:00
function initialize {
USER="admin"
HOSTNAME=$(hostname)
STACKS_DIRECTORY="/home/$USER/homelab/$HOSTNAME/config"
echo "Initialized with:"
echo "USER=$USER"
echo "HOSTNAME=$HOSTNAME"
echo "STACKS_DIRECTORY=$STACKS_DIRECTORY"
}
function main {
2023-10-10 14:16:24 -07:00
while [[ $# -gt 0 ]]; do
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
;;
2023-10-16 22:37:51 -07:00
config*) COMMAND="docker-compose config"; shift;
2023-10-10 14:29:53 -07:00
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 ;;
esac
done
2023-10-10 14:16:24 -07:00
2023-10-16 22:37:51 -07:00
if [ -z ${COMMAND+x} ]; then
2023-10-10 15:53:32 -07:00
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-16 22:37:51 -07:00
initialize
main "$@"