about summary refs log tree commit diff
diff options
context:
space:
mode:
-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"