-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwdmgr
executable file
·48 lines (42 loc) · 1.17 KB
/
pwdmgr
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/bash
if [ ! -e "$HOME/.pwdmgr" ]; then
echo "A ~/.pwdmgr file that defines GPG_PWD_FILE and TMP_PWD_FILE is missing."
exit 1
fi
source "$HOME/.pwdmgr"
if [ -e "$TMP_PWD_FILE" ]; then
echo "$TMP_PWD_FILE already exists. Please, select a different file."
exit 1
else
TMP_PWD_DIR=$(dirname "$TMP_PWD_FILE")
if [ ! -e "$TMP_PWD_DIR" ]; then
echo "$TMP_PWD_DIR does not exist. Creating it."
mkdir -p "$TMP_PWD_DIR"
fi
fi
if [ -d "$GPG_PWD_FILE" ]; then
echo "$GPG_PWD_FILE needs to be a regular file."
exit 1
elif [ ! -e "$GPG_PWD_FILE" ]; then
echo "$GPG_PWD_FILE does not exist. Create it? (y/n) "
read a
if [ $(echo "$a" | tr '[:upper:]' '[:lower:]') = "y" ]; then
GPG_PWD_DIR=$(dirname "$GPG_PWD_FILE")
if [ ! -e "$GPG_PWD_DIR" ]; then
echo "$GPG_PWD_DIR does not exist. Creating it."
mkdir -p "$GPG_PWD_DIR"
fi
touch "$GPG_PWD_FILE"
else
echo "OK, bye."
exit 0
fi
else
gpg2 --output "$TMP_PWD_FILE" --decrypt "$GPG_PWD_FILE"
fi
if [ -z "$EDITOR" ]; then
EDITOR="emacs -q"
fi
$EDITOR "$TMP_PWD_FILE"
gpg2 --cipher-algo AES256 --output "$GPG_PWD_FILE" --symmetric "$TMP_PWD_FILE"
rm -P "$TMP_PWD_FILE"*