homelab/fighter/scripts/docker-stacks.sh

106 lines
2.4 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
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
2023-10-09 11:52:55 -07:00
up*)
2023-10-09 11:33:44 -07:00
echo "OPERATION is up"
2023-10-09 11:52:55 -07:00
while [ $# -gt 0 ]; do
case $1 in
-f | --force)
FORCE=true
;;
up)
true
;;
*)
echo "Unrecognized operation \'$1\'"
exit
;;
esac
shift
done
echo "FORCE is $FORCE"
2023-10-09 11:33:44 -07:00
;;
2023-10-09 11:52:55 -07:00
down*)
2023-10-09 11:33:44 -07:00
echo "OPERATION is down"
2023-10-09 11:52:55 -07:00
# run "down" on all stacks
while [ $# -gt 0 ]; do
case $1 in
down)
true
;;
*)
echo "Unrecognized operation \'$1\'"
exit
;;
esac
shift
done
echo "FORCE is $FORCE"
2023-10-09 11:33:44 -07:00
;;
*)
2023-10-09 11:52:55 -07:00
echo "Operation not recognized."
exit
2023-10-09 11:33:44 -07:00
;;
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 "$@"