about summary refs log tree commit diff
path: root/secret_create.sh
blob: fcd05cbd797bdfda7d8ca2e85056c4b6ad2e805c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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"