2023-04-26 21:48:32 +00:00
|
|
|
#!/usr/bin/env sh
|
2023-04-20 21:34:25 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf '%s\n' "Usage:"
|
2023-08-05 16:09:43 +00:00
|
|
|
printf '$ %s\n' "$0 [--help]"
|
2023-04-26 17:34:53 +00:00
|
|
|
printf '$ %s\n' "$0 [--dry] os"
|
2023-07-20 17:21:24 +00:00
|
|
|
printf '$ %s\n' "$0 [--dry] base"
|
|
|
|
printf '$ %s\n' "$0 [--dry] firewall"
|
|
|
|
printf '$ %s\n' "$0 [--dry] ssh"
|
2023-04-26 17:34:53 +00:00
|
|
|
printf '$ %s\n' "$0 [--dry] docker"
|
2023-07-07 21:21:03 +00:00
|
|
|
printf '$ %s\n' "$0 [--dry] docker_config"
|
2023-08-05 16:09:43 +00:00
|
|
|
printf '$ %s\n' "$0 [--dry] users [--init]"
|
|
|
|
printf '$ %s\n' "$0 [--dry] reboot"
|
|
|
|
printf '$ %s\n' "$0 [--dry] services [--down|--restart|--recreate] [SINGLE_SERVICE]"
|
2023-04-20 21:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_modules() {
|
|
|
|
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
|
|
|
|
ansible-galaxy collection install community.general
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-14 01:01:46 +00:00
|
|
|
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
|
2023-04-20 21:34:25 +00:00
|
|
|
cd "$(dirname "$0")" || exit 255
|
2023-05-14 01:01:46 +00:00
|
|
|
|
2023-04-26 17:34:53 +00:00
|
|
|
if [ "$1" = "--dry" ]; then
|
|
|
|
EXEC="echo"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
EXEC="eval"
|
|
|
|
fi
|
|
|
|
|
2023-05-14 01:01:46 +00:00
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
TAG="$1"
|
|
|
|
shift
|
|
|
|
fi
|
2023-04-20 21:34:25 +00:00
|
|
|
|
2023-04-26 17:34:53 +00:00
|
|
|
case $TAG in
|
2023-04-20 21:34:25 +00:00
|
|
|
"")
|
2023-08-05 16:09:43 +00:00
|
|
|
install_modules; $EXEC "$BASE_CMD" ;;
|
2023-07-20 17:21:24 +00:00
|
|
|
os|base|firewall|ssh|docker|docker_config)
|
2023-08-05 16:09:43 +00:00
|
|
|
install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;;
|
2023-04-20 21:34:25 +00:00
|
|
|
users)
|
|
|
|
install_modules
|
2023-04-26 17:34:53 +00:00
|
|
|
|
2023-08-05 16:09:43 +00:00
|
|
|
if [ "$1" = "--init" ]; then
|
2023-04-26 17:34:53 +00:00
|
|
|
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
2023-04-20 21:34:25 +00:00
|
|
|
else
|
2023-04-26 17:34:53 +00:00
|
|
|
$EXEC "$BASE_CMD --tags '$TAG'"
|
2023-04-20 21:34:25 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reboot)
|
2023-08-05 16:09:43 +00:00
|
|
|
install_modules; $EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'do_reboot=true'" ;;
|
2023-04-20 21:34:25 +00:00
|
|
|
services)
|
|
|
|
install_modules
|
2023-04-26 17:34:53 +00:00
|
|
|
|
2023-08-05 16:09:43 +00:00
|
|
|
if [ "$1" = "--down" ]; then
|
|
|
|
ACTION="down"
|
|
|
|
shift
|
|
|
|
elif [ "$1" = "--restart" ]; then
|
|
|
|
ACTION="restart"
|
|
|
|
shift
|
|
|
|
elif [ "$1" = "--recreate" ]; then
|
|
|
|
ACTION="recreate"
|
2023-04-26 17:34:53 +00:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2023-08-05 16:09:43 +00:00
|
|
|
case $1 in
|
|
|
|
--*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
SINGLE_SERVICE="$1" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
|
|
|
VARS="single_service=$SINGLE_SERVICE"
|
|
|
|
elif [ -n "$ACTION" ] && [ -z "$SINGLE_SERVICE" ]; then
|
|
|
|
VARS="$ACTION=true"
|
|
|
|
elif [ -n "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
|
|
|
VARS='{"'$ACTION'": true, "single_service": "'$SINGLE_SERVICE'"}'
|
2023-04-20 21:34:25 +00:00
|
|
|
fi
|
2023-04-26 17:34:53 +00:00
|
|
|
|
|
|
|
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
2023-04-20 21:34:25 +00:00
|
|
|
;;
|
2023-08-05 16:09:43 +00:00
|
|
|
--help)
|
2023-04-20 21:34:25 +00:00
|
|
|
usage ;;
|
|
|
|
*)
|
|
|
|
usage >&2; exit 1 ;;
|
|
|
|
esac
|