dotconf/bin/rage
2021-12-16 08:13:25 -07:00

75 lines
1003 B
Bash
Executable File

#!/bin/sh
set -e
rage_dir=~/.rage
. ${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
;;
re)
F=""
if [ -f $2 ]; then
F=$2
else
F=$(list | grep $2)
fi
echo "Re-encrypting: '${F}'"
pass="$(age -i $identity -d "${F}")"
echo "$pass" | age -a -R "${recipients}" > "${F}"
;;
en)
printf 'Password: '
stty -echo
read pass
stty echo
echo ""
printf 'Location: '
read loc
echo ""
mkdir -p "$(dirname ~/.rage/${loc})"
echo "$pass" | age -a -R "${recipients}" > ~/.rage/${loc}.age
;;
de)
if [ -f $2 ]; then
age -i $identity -d $2
else
F=$(list | grep $2)
age -i $identity -d "${F}"
fi
;;
otp)
if [ -f $2 ]; then
age -i $identity -d $2 | oathtool -b --totp -
else
F=$(list | grep $2)
age -i $identity -d "${F}" | oathtool -b --totp -
fi
;;
push)
cd $rage_dir
git push
;;
sync)
cd $rage_dir
git sync
;;
default)
list
esac