/ bin / rage
rage
 1  #!/bin/sh
 2  
 3  set -e
 4  
 5  rage_dir=~/.rage
 6  
 7  . ${rage_dir}/config
 8  
 9  cmd=$1
10  
11  list() {
12  	find $rage_dir -type f -name \*.age
13  }
14  
15  if [ -z ${cmd} ]; then
16  	list
17  	exit
18  fi
19  
20  case $cmd in
21  	ls)
22  		list
23  		;;
24  	re)
25  		F=""
26  		if [ -f $2 ]; then
27  			F=$2
28  		else
29  			F=$(list | grep $2)
30  		fi
31  
32  		echo "Re-encrypting: '${F}'"
33  		pass="$(age -i $identity -d "${F}")"
34  		echo "$pass" | age -a -R "${recipients}" > "${F}"
35  		;;
36  	en)
37  		printf 'Password: '
38  		stty -echo
39  		read pass
40  		stty echo
41  		echo ""
42  		printf 'Location: '
43  		read loc
44  		echo ""
45  		mkdir -p "$(dirname ~/.rage/${loc})"
46  		echo "$pass" | age -a -R "${recipients}" > ~/.rage/${loc}.age
47  		;;
48  	de)
49  		if [ -f $2 ]; then
50  			age -i $identity -d $2
51  		else
52  			F=$(list | grep $2)
53  			age -i $identity -d "${F}"
54  		fi
55  		;;
56  	otp)
57  		if [ -f $2 ]; then
58  			age -i $identity -d $2 | oathtool -b --totp -
59  		else
60  			F=$(list | grep $2)
61  			age -i $identity -d "${F}" | oathtool -b --totp -
62  		fi
63  		;;
64  	push)
65  		cd $rage_dir
66  		git push
67  		;;
68  	sync)
69  		cd $rage_dir
70  		git sync
71  		;;
72  	default)
73  		list
74  esac