Simplify vault script

It gathers all .age files and decrypts into secrets folder that is .gitignored. Assembly of the distribution plucks the decrypted files from secrets folder
This commit is contained in:
Lukas Stancik
2025-03-17 17:42:46 +00:00
parent 64ec3e48b4
commit 95f487fa2a
+16 -16
View File
@@ -1,38 +1,38 @@
#!/bin/sh
set -e
FILES_IN_VAULT='./src/wifi-password.txt
./src/repository-builder/packager.rsa
./src/repository-builder/packager.rsa.pub
./src/wireguard.private.key
./src/wireguard.public.key
./src/authorized_keys'
FILES_IN_VAULT=$(find . -name *.age)
age_encrypt() {
local input="$1"
local output="$1.tmp"
local AGE_PASSPHRASE=`cat ./.vault_password_file`
if [ $# -ne 1 ] ; then
echo "invalid argument"
exit 1
fi
./cache/age/age --encrypt --passphrase --armor --output $output $input && rm $input && mv $output $input
AGE_PASSPHRASE=$(cat ./.vault_password_file) age --encrypt --passphrase --armor --output "$2" "$1"
}
age_decrypt() {
local input="$1"
local output="$1.tmp"
local AGE_PASSPHRASE=`cat ./.vault_password_file`
if [ $# -ne 1 ] ; then
echo "invalid argument"
exit 1
fi
./cache/age/age --decrypt --output $output $input && rm $input && mv $output $input
BASENAME=$(basename $1 .age)
AGE_PASSPHRASE=$(cat ./.vault_password_file) age --decrypt --output "secrets/$BASENAME" "$1"
}
encrypt() {
for FILE in $FILES_IN_VAULT; do
age_encrypt $FILE
age_encrypt "$FILE"
done
}
decrypt() {
for FILE in $FILES_IN_VAULT; do
age_decrypt $FILE
age_decrypt "$FILE"
done
}