improve shell script

This commit is contained in:
Henri Dohmen 2025-12-30 14:57:31 +01:00
parent 6461102325
commit 801e4681fe
Signed by: hd
GPG key ID: AB79213B044674AE

View file

@ -13,26 +13,26 @@ first_missing=$(
. as $root . as $root
| $root.managed_clients[] | $root.managed_clients[]
| select($root.hashes[.] | not) | select($root.hashes[.] | not)
' $FILEPATH \ ' "$FILEPATH" \
| head -n 1 \ | head -n 1 \
) )
[ -z "$first_missing" ] && echo "Done" >&2 && exit 0 [ -z "$first_missing" ] && echo "Done" >&2 && exit 0
echo "Generating cerificate for $first_missing" echo "Generating cerificate for $first_missing"
mkdir $tmp/$first_missing mkdir "$tmp/$first_missing"
hash=$( hash=$(
syncthing generate \ syncthing generate \
--config $tmp/$first_missing \ --config "$tmp/$first_missing" \
--data $tmp/$first_missing/data \ --data "$tmp/$first_missing/data" \
| grep -oP '(?<=device=)[A-Z0-9-]+' \ | grep -oP '(?<=device=)[A-Z0-9-]+' \
) )
mkdir -p $PKI_PATH mkdir -p "$PKI_PATH"
mv $tmp/$first_missing/cert.pem $PKI_PATH/$first_missing.cert mv "$tmp/$first_missing/cert.pem" "$PKI_PATH/$first_missing.cert"
# Remove the file so agenix does not try to decrypt # Remove the file so agenix does not try to decrypt
[ -f "$SECRETS_PATH/$first_missing.age" ] && rm "$SECRETS_PATH/$first_missing.age" [ -f "$SECRETS_PATH/$first_missing.age" ] && rm "$SECRETS_PATH/$first_missing.age"
agenix -e $SECRETS_PATH/$first_missing.age < $tmp/$first_missing/key.pem agenix -e "$SECRETS_PATH/$first_missing.age" < "$tmp/$first_missing/key.pem"
jq --arg client "$first_missing" \ jq --arg client "$first_missing" \
--arg hash "$hash" \ --arg hash "$hash" \