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