/
passman
executable file
·100 lines (90 loc) · 2.41 KB
/
passman
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
#!/bin/bash
# Author: Mats Rauhala
#
# A simple password manager. Uses gpg for encryption. For easier usage, set
# default-key, session manager and default-recipient-self
VERSION=0.1.1
# Check for dependencies
which tree
if [ $? -gt 0 ]; then
echo "tree command is missing. Try installing it"
exit 1
fi
root=$HOME/passwords
function handlePath {
local original=$root/$1
dir=$(dirname $original)
filename="$(basename $original).gpg"
}
function insertPassword
{
local dir=$1
local filename=$2
local fullpath=$dir/$filename
local username=$3
local password=$4
local notes=$5
local tempfile=$(mktemp)
echo "Full path: $fullpath"
if [ -f $fullpath ]; then
# File already exists
rm $tempfile
echo "Decrypting old"
gpg --output $tempfile --decrypt $fullpath
rm $fullpath
fi
touch $tempfile
echo "Date: $(date)" >> $tempfile
echo "Username: $username" >> $tempfile
echo "Password: $password" >> $tempfile
echo "Notes: $notes" >> $tempfile
echo "" >> $tempfile
gpg --output $fullpath --encrypt $tempfile
rm $tempfile
}
while getopts "i:ls:rh" flags
do
case $flags in
"i") # Insert new
handlePath $OPTARG
echo $dir
if [ ! -e $dir ]; then
mkdir -p $dir
fi
echo "Username:"
read username
echo ""
echo "Password:"
read -s password
echo ""
echo "Notes:"
read notes
insertPassword "$dir" "$filename" "$username" "$password" "$notes"
password=""
;;
"l") # List all
tree -P "*.gpg" $root | less
;;
"s") # See username password
handlePath $OPTARG
if [ ! -e $dir/$filename ]
then
echo "No such file"
exit 1
fi
echo "Reading $dir/$filename"
gpg --decrypt $dir/$filename
;;
"r") # Recommend a password
pwgen
;;
"h") # Help
echo "passman $VERSION"
echo ""
echo -e "\t-h\t\tThis help"
echo -e "\t-i [path]\tInsert a new password"
echo -e "\t-l \t\tList passwords"
echo -e "\t-s [path]\tSee password"
echo -e "\t-r \t\tRecommend a new password"
esac
done