]> Sergey Matveev's repositories - passman.git/blob - passman
Raise copyright years
[passman.git] / passman
1 #!/bin/sh -e
2 # passman -- simple password manager
3 # Copyright (C) 2013-2020 Sergey Matveev (stargrave@stargrave.org)
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 3 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 DB=~/.passmandb
18
19 generator()
20 {
21     gpg --armor --gen-random 1 16 | tr '+/' '-_' | tr -d =
22 }
23
24 cliper()
25 {
26     xclip -in -selection $1
27 }
28
29 case "$1" in
30 gen)
31     generator
32     ;;
33 add)
34     dst="$2"
35     passwd="$3"
36     [ -n "$dst" ]
37     [ -n "$passwd" ] || passwd=$(generator)
38     echo Adding password for $dst
39     mkdir -p $DB/$dst
40     umask 077
41     echo "$passwd" > $DB/$dst/passwd
42     ;;
43 *)
44     cd $DB
45     result=$(find . -type d -path "*$1*" | while read ent; do
46         [ -e "$ent/passwd" ] || continue
47         echo "$ent" | sed 's#^\./##'
48     done)
49     if [ $(echo "$result" | wc -l) -ne 1 ]; then
50         echo "$result"
51         exit
52     fi
53     [ -n "$result" ] || exit 1
54     echo $result
55     if [ -e "$result"/data ]; then
56         echo -n "Associated data: "
57         cat "$result"/data
58     fi
59     perl -ne 'chop and print' "$result"/passwd | cliper clipboard
60     echo $(basename "$result") | perl -ne 'chop and print' | cliper primary
61     sleep 10
62     echo -n | cliper clipboard
63     ;;
64 esac