]> 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-2021 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     gpg --armor --gen-random 1 16 | tr '+/' '-_' | tr -d =
21 }
22
23 cliper() {
24     xclip -in -selection $1
25 }
26
27 ENTITY=""
28
29 finder() {
30     cd $DB
31     result=$(find . -type d -path "*$1*" | while read ent; do
32         [ -e "$ent/passwd" ] || continue
33         echo "$ent" | sed 's#^\./##'
34     done)
35     if [ $(echo "$result" | wc -l) -ne 1 ]; then
36         echo "$result"
37         exit 1
38     fi
39     [ -n "$result" ] || exit 1
40     ENTITY=$result
41     echo "$result"
42 }
43
44 case "$1" in
45 has)
46     finder "$2"
47     ;;
48 gen)
49     generator
50     ;;
51 add)
52     dst="$2"
53     passwd="$3"
54     [ -n "$dst" ]
55     [ -n "$passwd" ] || passwd=$(generator)
56     echo Adding password for $dst
57     mkdir -p $DB/$dst
58     umask 077
59     echo "$passwd" > $DB/$dst/passwd
60     ;;
61 *)
62     finder "$1"
63     if [ -e "$ENTITY"/data ]; then
64         echo -n "Associated data: "
65         cat "$ENTITY"/data
66     fi
67     perl -ne 'chop and print' "$ENTITY"/passwd | cliper clipboard
68     echo $(basename "$ENTITY") | perl -ne 'chop and print' | cliper primary
69     sleep 10
70     echo -n | cliper clipboard
71     ;;
72 esac