blob: c8cd0deb3c482f9dd2648655c00bc496feac7483 (
plain)
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
|
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: Copyright 2021 Aleksei Kovura
[ -z "$PASSWORD_STORE_DIR_PLAIN" ] && {
printf "set \$PASSWORD_STORE_DIR_PLAIN first\n"
exit 1
}
#[ ! -d "$PASSWORD_STORE_DIR_PLAIN" ] && {
#printf "%s is not a directory\n" "$PASSWORD_STORE_DIR_PLAIN"
#exit 1
#}
PASSWORD_STORE_DIR_PLAIN=$HOME/passwords-plain
name_to_file() {
file="${PASSWORD_STORE_DIR_PLAIN}/${1}.pass"
printf "%s\n" $file
}
name_is_in_repo() {
[ -z "$1" ] && printf "%s\n" "provide name" 1>&2 && return 1
file="${PASSWORD_STORE_DIR_PLAIN}/${1}.pass"
[ ! -f $file ] && printf "%s not in repo\n" $1 1>&2 && return 1
return 0
}
case $1 in
edit)
[ -z "$EDITOR" ] && printf "\$EDITOR is not set\n" && exit 1
name_is_in_repo $2 && $EDITOR $(name_to_file $2)
;;
show)
name_is_in_repo $2 && cat $(name_to_file $2)
;;
list|ls|"")
basename -a -s '.pass' $PASSWORD_STORE_DIR_PLAIN/*.pass
;;
generate)
name_is_in_repo $2 && printf "%s already exists\n" $2 && exit 1
command -v pwgen 1>/dev/null && {
pwgen -cns1 25 | tee $PASSWORD_STORE_DIR_PLAIN/${2}.pass
} || printf "need pwgen installed" && exit 1
;;
remove|rm|delete)
[ -z "$2" ] && printf "%s\n" "provide name" && exit 1
file=$(name_to_file $2)
rm -iv $file
;;
*)
printf "%s is not implemented\n" "$1"
;;
esac
|