nixos-config/scripts/_gpg-unlock.nix
Leonardo Eugênio 8140d0e79f fix gpg unlock
2022-12-08 12:41:03 -03:00

31 lines
680 B
Nix

{ pkgs, ... }:
pkgs.writeShellScriptBin "_gpg-unlock" ''
${pkgs.gnupg}/bin/gpg-connect-agent reloadagent /bye
set -e
test -f "$HOME/.config/.preset-password" || {
${pkgs.libnotify}/bin/notify-send "No preset password found"
exit 0;
}
get_keygrip() {
${pkgs.gnupg}/bin/gpg --list-secret-keys --with-keygrip |
${pkgs.gawk}/bin/awk '
/^ssb/ {
ssb=1
}
/Keygrip/{
if (ssb) print $3
}'
}
keygrip=$(get_keygrip)
test -n "$keygrip" || exit 0
${pkgs.coreutils}/bin/cat "$HOME/.config/.preset-password" |
${pkgs.coreutils}/bin/base64 -d |
${pkgs.gnupg}/libexec/gpg-preset-passphrase --preset "$keygrip"
''