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

51 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/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-01-16 14:27:07 +00:00
printf '$ %s\n' "$0 [-h|--help]"
2022-12-26 01:13:06 +00:00
printf '$ %s\n' "$0 os"
2023-01-16 14:27:07 +00:00
printf '$ %s\n' "$0 docker"
2022-12-26 01:13:06 +00:00
printf '$ %s\n' "$0 reboot [-f|--force]"
2023-01-16 14:27:07 +00:00
printf '$ %s\n' "$0 services [SINGLE_SERVICE]"
}
install_modules() {
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
ansible-galaxy collection install community.general
fi
}
2023-01-04 20:02:33 +00:00
cd "$(dirname "$0")" || exit 255
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
if [ -z "$1" ]; then
$BASE_CMD
else
case $1 in
2023-01-16 14:27:07 +00:00
os|docker)
2023-01-16 14:31:25 +00:00
install_modules; $BASE_CMD --tags "$1" ;;
2023-01-16 14:27:07 +00:00
reboot)
install_modules
if [ "$2" = "-f" ] || [ "$2" = "--force" ]; then
$BASE_CMD --tags "$1" --extra-vars "force_reboot=true"
else
2023-01-16 14:27:07 +00:00
$BASE_CMD --tags "$1"
fi
2023-01-14 18:29:21 +00:00
;;
2023-01-16 14:27:07 +00:00
services)
install_modules
if [ -z "$2" ]; then
$BASE_CMD --tags "$1"
2022-12-25 17:39:26 +00:00
else
2023-01-16 14:27:07 +00:00
$BASE_CMD --tags "$1" --extra-vars "single_service=$2"
2022-12-25 17:39:26 +00:00
fi
2023-01-14 18:29:21 +00:00
;;
-h|--help)
2023-01-14 18:29:21 +00:00
usage ;;
*)
2023-01-14 18:29:21 +00:00
usage >&2; exit 1 ;;
esac
fi