forked from n0use/sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpg
76 lines (68 loc) · 2.4 KB
/
gpg
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
pass ()
{
user=$1;
if [ -z "$1" ] ; then
for f in ${HOME}/etc/pass/password-* ; do
p=$(basename ${f})
echo ${p} | sed 's/^password-\(.*\).txt.*$/\1/'
done
return 0
fi
pass_file="${HOME}/etc/pass/password-${user}.txt"
if [ -f "${pass_file}" ] ; then
echo "Warning: you have an UNENCRYPTED PASSWORD FILE (${pass_file}).. you should remove this file for security reasons."
cat "${pass_file}"
return 0
fi
if [ ! -f ${HOME}/etc/pass/password-${user}.txt.gpg ]; then
echo "No password for \"${user}\" stored.";
possibles=$(ls ${HOME}/etc/pass/password-* | sed "s#${HOME}/etc/pass/password-##" | sed 's/.txt.gpg$//' | grep -i ${user})
if [ -n "${possibles}" ] ; then
echo "Did you mean one of these - "
# for p in $(echo ${possibles} | sed 's/ /\n/g' | | sed 's/.txt.gpg$//') ; do
for p in ${possibles} ; do
echo " ${p}"
done
fi
return 1;
fi;
# gpg -d ${HOME}/etc/pass/password-${user}.txt.gpg > /tmp/p.$$ && clear && cat /tmp/p.$$ && rm -f /tmp/p.$$
gpg -d ${HOME}/etc/pass/password-${user}.txt.gpg > /tmp/p.$$ && cat /tmp/p.$$ && rm -f /tmp/p.$$
}
newpass ()
{
replace=0
if [[ "$1" == "-r" ]] ; then
replace=1
shift
fi
pass=$1
pass_file="${HOME}/etc/pass/password-${pass}.txt"
if [ -f "${pass_file}" ] || [ -f "${pass_file}.gpg" ] ; then
if [[ "${replace}" == 0 ]] ; then
echo "There is already a password stored for this - remove the old one and try again."
return 1
fi
echo -n "Are you sure you want to REPLACE the information you already have stored for '$pass'? [Ny] "
read yesno
[[ yesno =~ [yY] ]] || return 1
rm -f "${pass_file}" "${pass_file}.gpg"
fi
echo "Enter the information to store in the encrypted file for \"${pass}\""
cnt=0
input=()
while read line ; do
input[${cnt}]="$line"
cnt=$(($cnt + 1))
done
for ((i=0;i<${cnt};i++)) do
echo "${input[${i}]}" >> "${pass_file}"
done
gpg -r [email protected] -e "${pass_file}"
rm "${pass_file}"
}
# DISABLED TESTING GPGTools for OSX
#if [ -z $(pgrep gpg-agent) ] ; then
# gpg-agent --daemon --enable-ssh-support --write-env-file "${HOME}/.gpg-agent-info" > ~/sh/gpg-agent.rc;
# . ~/sh/gpg-agent.rc
#fi