about summary refs log tree commit diff
path: root/secret_create.sh
diff options
context:
space:
mode:
authorEmile <git@emile.space>2024-03-25 15:34:22 +0100
committerEmile <git@emile.space>2024-03-25 15:34:22 +0100
commitfec1842d1280338dade0b1338ecd79c085868b78 (patch)
treea45ca0a58fc86e741a3216c6a93db213d062a85c /secret_create.sh
parent967c4667a2c4bec8b744f31953db713fc77bfc3e (diff)
small script for creating secrets
Diffstat (limited to 'secret_create.sh')
-rwxr-xr-xsecret_create.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/secret_create.sh b/secret_create.sh
new file mode 100755
index 0000000..fcd05cb
--- /dev/null
+++ b/secret_create.sh
@@ -0,0 +1,27 @@
+# usage:
+# $1 = hostname
+# $2 = secretname (with .age suffix)
+
+if [ $# -lt 2 ]; then
+    # TODO: print usage
+    echo "USAGE: ./secret_create.sh <hostname> <secretname>"
+    echo "EXAMPLE: ./secret_create.sh corrino abc.age"
+    exit 1
+fi
+
+# the path we'll use to store our secret in the end
+SECRET_FILE="nix/hosts/$1/secrets/$2"
+
+# but first, we're editing the default "new" secret
+NEW_FILE="nix/hosts/$1/secrets/new"
+
+echo "Editing the 'new' file: '$NEW_FILE'"
+EDITOR=hx nix run git+https://github.com/ryantm/agenix -- -e $NEW_FILE
+
+echo "Moving the 'new' file to the specified secret file '$2'"
+mv $NEW_FILE $SECRET_FILE
+
+echo "Adding the secret to git in order to use it"
+git add $SECRET_FILE
+
+echo "Created secret $SECRET_FILE"