Skip to content

Instantly share code, notes, and snippets.

@angelacastaneda
Created October 26, 2024 21:30
Show Gist options
  • Save angelacastaneda/c700019600d745698acc028f9f8bac97 to your computer and use it in GitHub Desktop.
Save angelacastaneda/c700019600d745698acc028f9f8bac97 to your computer and use it in GitHub Desktop.
age shadow script to emulate gpg {-d,-e} <file>
#!/bin/sh -eu
# shadow script that does three things:
# - 'age -e <file>' produce an ascii armored <file>.age in the same
# directory encrypted with the age_def_rec file
# - 'age -d <file>' decrypts the file to stdout with the age_def_id file
# - anything that's not a file or doesn't uses -e/-d flags gets sent to the
# proper age binary location at age_bin
age_bin=/usr/bin/rage
age_def_rec="${XDG_CONFIG_HOME:-$HOME/.config}/age/recipients.txt"
age_def_id="${XDG_CONFIG_HOME:-$HOME/.config}/age/identity.txt"
if [ "$#" -ne 2 ]; then
exec "$age_bin" "$@"
fi
if ! [ -f "$2" ]; then
exec "$age_bin" "$@"
fi
file="$2"
case "${1%%:*}" in
-e|--encrypt)
exec "$age_bin" -e -R "$age_def_rec" -a -o "$file.age" "$file"
;;
-d|--decrypt)
exec "$age_bin" -d -i "$age_def_id" "$file"
;;
*)
exec "$age_bin" "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment