blob: 23ab4ec088fc47f6a9e2850e0ff4a5d1af796799 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/bin/sh
# ayu(1) - an actually boring password manager, which uses age(1) as backend.
# Path to the program's directory
ayu_dir="${ayu_dir:-$HOME/.config/ayu}"
# Path to the password store
ayu_store="${ayu_store:-$HOME/.ayu}"
# Path to the age(1) keys
ayu_key="${ayu_key:-${ayu_dir}/sec.age}"
ayu_pub="${ayu_pub:-${ayu_dir}/pub.age}"
EDITOR=${EDITOR:-vi}
# Run some tests
test -d $ayu_dir || mkdir -p $ayu_dir
test -d $ayu_store || mkdir -p $ayu_store
test -f $ayu_key || printf "$0: Generate your own age(1) key with age-keygen(1) and place it as a $ayu_key. \n"
test -f $ayu_pub || printf "$0: Public key needs to be placed on $ayu_pub (Hint: it's the visible output of age-keygen(1)) \n"
# Switch directory to the password store, otherwise bail out.
cd $ayu_store || exit 1
# Edit an entry if it exists
edit() {
age --decrypt --identity=$ayu_key --output=${1%%.age} ${1%%.age}.age
${EDITOR} ${1%%.age}
age --encrypt -R $ayu_pub --output=${1%%.age}.age ${1%%.age}
rm ${1%%.age}
}
# List contents of the store
list() {
tree $ayu_store
}
# Create a new entry
new() {
test -d "$1" && usage && exit
tmpfile="$(mktemp)"
${EDITOR} "$tmpfile"
mkdir -p "$(dirname "$1")"
age --encrypt -R $ayu_pub -o $tmpfile.age $tmpfile
mv $tmpfile.age "${1%%.age}".age
rm $tmpfile
}
# Remove
re() {
rm -v ${1}${2}.age
}
# Remove-recursive
rr() {
test -d "$@" && usage && exit
rm -r -v "$(dirname "$@")"
}
# Print usage
usage() {
printf "$0 [ ed | ls | new | re | rr | vi ] \n"
}
# View an entry, otherwise list the contents of the directory specified.
view() {
if [ -f "${1%%.age}".age ];then
age --decrypt --identity=$ayu_key "${1%%.age}".age
elif [ -d "${1:-.}" ];then
tree "${1:-.}"
else
usage
exit
fi
}
case $1 in
edit | ed)
edit $2
;;
list | ls)
list
;;
new)
new $2
;;
remove | re)
re $2 $3
;;
remove-recursive | rr)
rr $2
;;
usage)
usage
;;
view | vi)
view $2
;;
*)
list
;;
esac
|