homelab/fighter/scripts/docker-stacks.sh

78 lines
1.7 KiB
Bash
Raw Normal View History

2023-10-06 15:56:19 -07:00
# takes a docker-compose.yml file path and returns a boolean to represent
# whether that stack depends on an smb share under the `/mnt/nas` path
function uses_smb_share {
2023-10-06 15:56:19 -07:00
STACK_PATH=$1
docker-compose config -f $STACK_PATH | grep -q /mnt/nas
MATCH=$?
if [ $MATCH == 0]; then
return true
else
return false
fi
}
# takes a docker-compose.yml file path and returns a boolean to represent
# whether that stack passes a docker-compose config lint
function valid_compose {
STACK_PATH=$1
docker-compose config -f $STACK_PATH > /dev/null 2>&1
return $?
}
# takes a docker-compose.yml file path and shuts it down
function compose_down {
STACK_PATH=$1
docker-compose down -f $STACK_PATH
}
# takes a docker-compose.yml file path and brings it up
function compose_up {
STACK_PATH=$1
docker-compose up -f $STACK_PATH -d
}
# takes a docker-compose.yml file path and force recreates it
function compose_up_recreate {
STACK_PATH=$1
docker-compose up -d --force-recreate -f $STACK_PATH
}
function main {
2023-10-09 11:33:44 -07:00
NASONLY=false
LINT=false
FORCE=false
while [ $# -gt 0 ]; do
case $1 in
-n | --nas-only)
NASONLY=true
;;
2023-10-09 11:21:23 -07:00
-l | --lint)
LINT=true
;;
2023-10-09 11:33:44 -07:00
-f | --force)
FORCE=true
;;
2023-10-09 11:21:23 -07:00
*)
2023-10-09 11:33:44 -07:00
OPERATION="$OPERATION $1"
2023-10-09 11:21:23 -07:00
;;
esac
shift
done
2023-10-09 11:33:44 -07:00
case $OPERATION in
up)
echo "OPERATION is up"
;;
down)
echo "OPERATION is down"
;;
*)
echo "OPERATION is not up or down"
;;
esac
2023-10-09 11:21:23 -07:00
echo "\$NASONLY is $NASONLY"
2023-10-09 11:21:23 -07:00
echo "\$LINT is $LINT"
echo "\$OPERATION is $OPERATION"
}
main "$@"