33 lines
1.4 KiB
Bash
Executable File
33 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
host="$1"
|
|
|
|
job_main="$(pwgen -1 64 1)"
|
|
target_cyan="$(pwgen -1 64 1)"
|
|
target_cyan_htpasswd="$(htpasswd -nbB "${host}" "${target_cyan}")"
|
|
target_magenta="$(pwgen -1 64 1)"
|
|
target_magenta_htpasswd="$(htpasswd -nbB "${host}" "${target_magenta}")"
|
|
|
|
mkdir -p "hosts/${host}/secrets"
|
|
|
|
echo "$job_main" | agenix -e "hosts/${host}/secrets/new"
|
|
mv "hosts/${host}/secrets/new" "hosts/${host}/secrets/clerie-backup-job-main.age"
|
|
|
|
echo "$target_cyan" | agenix -e "hosts/${host}/secrets/new"
|
|
mv "hosts/${host}/secrets/new" "hosts/${host}/secrets/clerie-backup-target-cyan.age"
|
|
|
|
echo "$target_magenta" | agenix -e "hosts/${host}/secrets/new"
|
|
mv "hosts/${host}/secrets/new" "hosts/${host}/secrets/clerie-backup-target-magenta.age"
|
|
|
|
prev_htpasswd_cyan="$(agenix -d hosts/clerie-backup/secrets/restic-server-cyan-htpasswd.age)"
|
|
cat <(echo "$prev_htpasswd_cyan") <(echo "$target_cyan_htpasswd") | agenix -e "hosts/clerie-backup/secrets/new"
|
|
mv "hosts/clerie-backup/secrets/new" "hosts/clerie-backup/secrets/restic-server-cyan-htpasswd.age"
|
|
|
|
prev_htpasswd_magenta="$(agenix -d "hosts/backup-4/secrets/restic-server-magenta-htpasswd.age")"
|
|
cat <(echo "$prev_htpasswd_magenta") <(echo "$target_magenta_htpasswd") | agenix -e "hosts/backup-4/secrets/new"
|
|
mv "hosts/backup-4/secrets/new" "hosts/backup-4/secrets/restic-server-magenta-htpasswd.age"
|