mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +00:00
78 lines
2.2 KiB
Bash
Executable File
78 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
set -o nounset
|
|
set -o pipefail
|
|
|
|
# A wrapper script to run swift-hpa in a docker container and
|
|
# mount the correct volumes, etc.
|
|
#
|
|
# To download templates, playbooks, setup secrets, generate shell completions, etc.
|
|
# you can call this script with 'init'.
|
|
#
|
|
# Otherwise it will run the hpa script inside of a docker container with any passed
|
|
# in arguments.
|
|
|
|
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
|
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
|
|
|
HPA_DOCKER_IMAGE="git.housh.dev/michael/swift-hpa"
|
|
HPA_DOCKER_TAG=${HPA_DOCKER_TAG:-"latest"}
|
|
|
|
HPA_DATA_DIR="$XDG_DATA_HOME/hpa"
|
|
HPA_CONFIG_DIR="$XDG_CONFIG_HOME/hpa"
|
|
CONSULTS_DIR=${CONSULTS_DIR:-$HOME/work/consults}
|
|
|
|
CONSULT_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
|
|
HPA_PLAYBOOK_URL="ssh://git@git.housh.dev:2222/michael/ansible-hpa-playbook.git"
|
|
HPA_VAULT_SECRET_KEY="${HPA_VAULT_SECRET_KEY:-vault-pass}"
|
|
|
|
generate-completion() {
|
|
local type=${1:-"zsh"}
|
|
local output=${2:-$HOME/.zsh/completions/_hpa}
|
|
local output_dir=$(dirname $output)
|
|
|
|
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
|
|
(
|
|
podman run --rm -it "$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" \
|
|
--generate-completion-script "$type" |
|
|
tr -d '\r'
|
|
) >"$output"
|
|
}
|
|
|
|
gnnerate-secret() {
|
|
local secret="$(pass -c ansible/vault-pass)"
|
|
printf "$secret" | podman secret create "$HPA_VAULT_SECRET_KEY" -
|
|
}
|
|
|
|
# Ensure the dependencies are installed / setup.
|
|
init() {
|
|
generate-completion "$@"
|
|
gnnerate-secret
|
|
mkdir -p "$CONSULTS_DIR" &>/dev/null
|
|
mkdir "$HPA_DATA_DIR" &>/dev/null
|
|
[[ ! -d "$HPA_DATA_DIR/playbook" ]] && git clone "$HPA_PLAYBOOK_URL" "$HPA_DATA_DIR/playbook"
|
|
[[ ! -d "$HPA_DATA_DIR/template" ]] && git clone "$CONSULT_TEMPLATE_URL" "$HPA_DATA_DIR/template"
|
|
}
|
|
|
|
run() {
|
|
podman run --rm -it \
|
|
--volume "$HPA_DATA_DIR/template":/template \
|
|
--volume "$HPA_DATA_DIR/playbook":/playbook \
|
|
--volume "$HPA_CONFIG_DIR":/config/hpa \
|
|
--volume "$CONSULTS_DIR":/consults \
|
|
--secret "$HPA_VAULT_SECRET_KEY" \
|
|
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
|
}
|
|
|
|
############################## MAIN ##############################
|
|
|
|
first_arg=${1:-""}
|
|
|
|
if [[ $first_arg == "init" ]]; then
|
|
shift
|
|
init "$@" && exit 0
|
|
else
|
|
run "$@"
|
|
fi
|