pkgs/nixfiles: Move utility scripts to pkgs
This commit is contained in:
32
pkgs/nixfiles/nixfiles-generate-backup-secrets.sh
Executable file
32
pkgs/nixfiles/nixfiles-generate-backup-secrets.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd $(git rev-parse --show-toplevel)
|
||||
|
||||
host=$1
|
||||
|
||||
job_main=$(nix run nixpkgs#pwgen -- -1 64 1)
|
||||
target_cyan=$(nix run nixpkgs#pwgen -- -1 64 1)
|
||||
target_cyan_htpasswd=$(nix shell nixpkgs#apacheHttpd -c htpasswd -nbB ${host} ${target_cyan})
|
||||
target_magenta=$(nix run nixpkgs#pwgen -- -1 64 1)
|
||||
target_magenta_htpasswd=$(nix shell nixpkgs#apacheHttpd -c htpasswd -nbB ${host} ${target_magenta})
|
||||
|
||||
mkdir -p hosts/${host}/secrets
|
||||
|
||||
echo "$job_main" | nix run github:ryantm/agenix -- -e hosts/${host}/secrets/new
|
||||
mv hosts/${host}/secrets/new hosts/${host}/secrets/clerie-backup-job-main.age
|
||||
|
||||
echo "$target_cyan" | nix run github:ryantm/agenix -- -e hosts/${host}/secrets/new
|
||||
mv hosts/${host}/secrets/new hosts/${host}/secrets/clerie-backup-target-cyan.age
|
||||
|
||||
echo "$target_magenta" | nix run github:ryantm/agenix -- -e hosts/${host}/secrets/new
|
||||
mv hosts/${host}/secrets/new hosts/${host}/secrets/clerie-backup-target-magenta.age
|
||||
|
||||
prev_htpasswd_cyan=$(nix run github:ryantm/agenix -- -d hosts/clerie-backup/secrets/restic-server-cyan-htpasswd.age)
|
||||
cat <(echo "$prev_htpasswd_cyan") <(echo "$target_cyan_htpasswd") | nix run github:ryantm/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=$(nix run github:ryantm/agenix -- -d hosts/backup-4/secrets/restic-server-magenta-htpasswd.age)
|
||||
cat <(echo "$prev_htpasswd_magenta") <(echo "$target_magenta_htpasswd") | nix run github:ryantm/agenix -- -e hosts/backup-4/secrets/new
|
||||
mv hosts/backup-4/secrets/new hosts/backup-4/secrets/restic-server-magenta-htpasswd.age
|
||||
Reference in New Issue
Block a user