This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
pi-ansible/provision.sh

79 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env sh
2023-01-16 14:31:25 +00:00
set -e
2022-12-26 01:13:06 +00:00
usage() {
printf '%s\n' "Usage:"
2023-08-05 12:18:35 +00:00
printf '$ %s\n' "$0 [--help]"
printf '$ %s\n' "$0 [--dry] os"
2023-07-20 17:10:02 +00:00
printf '$ %s\n' "$0 [--dry] base"
2023-07-02 00:09:57 +00:00
printf '$ %s\n' "$0 [--dry] firewall"
printf '$ %s\n' "$0 [--dry] ssh"
2023-07-20 17:10:02 +00:00
printf '$ %s\n' "$0 [--dry] docker"
printf '$ %s\n' "$0 [--dry] docker_config"
2023-08-05 12:18:35 +00:00
printf '$ %s\n' "$0 [--dry] users [--init]"
printf '$ %s\n' "$0 [--dry] reboot"
printf '$ %s\n' "$0 [--dry] services [--down] [SINGLE_SERVICE]"
2023-01-16 14:27:07 +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-29 00:29:13 +00:00
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
2023-01-04 20:02:33 +00:00
cd "$(dirname "$0")" || exit 255
2023-05-29 00:29:13 +00:00
if [ "$1" = "--dry" ]; then
EXEC="echo"
shift
else
EXEC="eval"
fi
2023-05-29 00:29:13 +00:00
if [ "$#" -gt 0 ]; then
TAG="$1"
shift
fi
case $TAG in
2023-03-29 18:41:30 +00:00
"")
2023-05-28 15:58:12 +00:00
install_modules; $EXEC "$BASE_CMD" ;;
2023-07-20 17:10:02 +00:00
os|base|firewall|ssh|docker|docker_config)
2023-05-28 15:58:12 +00:00
install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;;
users)
install_modules
2023-08-05 12:18:35 +00:00
if [ "$1" = "--init" ]; then
$EXEC "$BASE_CMD --user root --tags '$TAG'"
else
$EXEC "$BASE_CMD --tags '$TAG'"
fi
;;
2023-03-29 18:41:30 +00:00
reboot)
2023-08-05 12:18:35 +00:00
install_modules; $EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'do_reboot=true'" ;;
2023-03-29 18:41:30 +00:00
services)
install_modules
2023-08-05 12:18:35 +00:00
if [ "$1" = "--down" ]; then
DOWN=1
shift
2023-03-29 18:41:30 +00:00
fi
if [ -z "$DOWN" ] && [ -n "$1" ]; then
VARS="single_service=$1"
elif [ -n "$DOWN" ] && [ -z "$1" ]; then
VARS="stop=true"
elif [ -n "$DOWN" ] && [ -n "$1" ]; then
VARS='{"stop": true, "single_service": "'$1'"}'
fi
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
2023-03-29 18:41:30 +00:00
;;
2023-08-05 12:18:35 +00:00
--help)
2023-03-29 18:41:30 +00:00
usage ;;
*)
usage >&2; exit 1 ;;
esac