dotconf/bin/rage

55 lines
875 B
Plaintext
Raw Normal View History

2020-12-26 15:08:17 -07:00
#!/bin/sh
2020-12-28 07:30:29 -07:00
set -e
2020-12-26 15:08:17 -07:00
rage_dir=~/.rage
rage_id_file="$(awk -F= '/^identity/{print $NF}' ${rage_dir}/config)"
rage_id_recip="$(awk -F= '/^identity/{print $NF ".pub"}' ${rage_dir}/config)"
cmd=$1
list() {
find $rage_dir -type f -name \*.age
}
if [ -z ${cmd} ]; then
list
exit
fi
case $cmd in
ls)
list
;;
2021-01-16 08:42:58 -07:00
en)
printf 'Password: '
stty -echo
read pass
stty echo
echo ""
printf 'Location: '
read loc
echo ""
mkdir -p "$(dirname ~/.rage/${loc})"
echo "$pass" | age -r "$(cat ${rage_id_file}.pub)" > ~/.rage/${loc}.age
;;
2020-12-26 15:08:17 -07:00
de)
2021-02-01 11:47:34 -07:00
if [ -f $2 ]; then
age -i $rage_id_file -d $2
else
F=$(list | grep $2)
age -i $rage_id_file -d "${F}"
fi
2020-12-26 15:08:17 -07:00
;;
2021-05-05 11:05:01 -06:00
otp)
if [ -f $2 ]; then
age -i $rage_id_file -d $2 | oathtool -b --totp -
else
F=$(list | grep $2)
age -i $rage_id_file -d "${F}" | oathtool -b --totp -
fi
;;
2020-12-26 15:08:17 -07:00
default)
list
esac