-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass2xy
executable file
·173 lines (141 loc) · 4.17 KB
/
pass2xy
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2017 Osiris Alejandro Gomez <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
die ()
{
echo -e "\e[31m[ERROR]\e[0m $1" && exit 1
}
print_help()
{
echo "$0"
echo
echo "Read 2 references from pass and copy to xy screen positions."
echo
echo "USE"
echo " $0 a1 b1"
echo " $0 REF1 REF2"
echo " $0 REFA REFB"
echo
echo "CONFIG"
echo
echo " You need create ~/.pass2xy.conf with required variables:"
echo
echo " X1: 123"
echo " X2: 678"
echo " Y1: 200"
echo " Y2: 200"
echo " SLEEP1: 1"
echo " SLEEP2: 1"
echo " PASS_STORE_DIR: /home/username/.password-store"
echo " PASS_REF_DIR: xy"
echo
echo " # optional variables: "
echo " REGEX_PASS1: [0-9]+"
echo " REGEX_PASS2: [0-9]+"
echo " REGEX_REF1: [a-z]{1}[0-9]{1}"
echo " REGEX_REF2: [a-z]{1}[0-9]{1}"
echo
echo "REQUIREMENTS:"
echo
echo " apt-get install pass xautomation"
echo
exit 2
}
CONFIG="$HOME/.pass2xy.conf"
[[ ! -e "$CONFIG" ]] && die "not found file: $CONFIG"
eval $(sed '/:/!d;/^ *#/d;s/:/ /;' < "$CONFIG" | while read -r key val
do
str="$key='$val'"
echo "$str"
done)
[[ -z "$X1" ]] && die "empty X1 in $CONFIG"
[[ -z "$X2" ]] && die "empty X2 in $CONFIG"
[[ -z "$Y1" ]] && die "empty Y1 in $CONFIG"
[[ -z "$Y2" ]] && die "empty Y2 in $CONFIG"
[[ -z "$PASS_STORE_DIR" ]] && die "empty PASS_STORE_DIR in $CONFIG"
[[ -z "$PASS_REF_DIR" ]] && die "empty PASS_REF_DIR in $CONFIG"
XTE=$(which xte)
[[ "$XTE" != "/usr/bin/xte" ]] && die "try: apt-get install xautomation"
[[ -z "$1" ]] && die "REF1 is required"
[[ -z "$2" ]] && die "REF2 is required"
REF1="$1"
REF2="$2"
OPTS=$(getopt -o h --long help -n 'bajas.sh' -- "$@")
eval set -- "$OPTS"
while true; do
case "$1" in
-h | --help)
print_help ;;
--) shift; break;;
esac
done;
if [ ! -z "$REGEX_REF1" ]
then
VALID_REF1=$(echo "$REF1" | egrep -o "$REGEX_REF1")
[[ "$VALID_REF1" != "$REF1" ]] && die "invalid REF1"
fi
if [ ! -z "$REGEX_REF2" ]
then
VALID_REF2=$(echo "$REF2" | egrep -o "$REGEX_REF2")
[[ "$VALID_REF2" != "$REF2" ]] && die "invalid REF2"
fi
PASS_DIR="$PASS_STORE_DIR/$PASS_REF_DIR"
PASS_REF1_FILE="$PASS_DIR/${REF1}.gpg"
PASS_REF2_FILE="$PASS_DIR/${REF2}.gpg"
PASS_REF1_PASS="$PASS_REF_DIR/$REF1"
PASS_REF2_PASS="$PASS_REF_DIR/$REF2"
[[ ! -e "$PASS_REF1_FILE" ]] && PASS1=$(pass insert "$PASS_REF1_PASS")
OK="$?"
[[ "$OK" -gt 1 ]] && die "unknown pass error: pass $PASS_REF1_PASS"
PASS1=$(pass "$PASS_REF1_PASS")
[[ ! -e "$PASS_REF2_FILE" ]] && PASS2=$(pass insert "$PASS_REF2_PASS")
OK="$?"
[[ "$OK" -gt 1 ]] && die "unknown pass error: pass $PASS_REF2_PASS"
PASS2=$(pass "$PASS_REF2_PASS")
[[ ! -e "$PASS_REF1_FILE" ]] && die "not found file: $PASS_REF1_FILE"
[[ ! -e "$PASS_REF2_FILE" ]] && die "not found file: $PASS_REF2_FILE"
[[ -z "$PASS1" ]] && die "empty PASS1"
[[ -z "$PASS2" ]] && die "empty PASS2"
if [ ! -z "$REGEX_PASS1" ]
then
VALID_PASS1=$(echo "$PASS1" | egrep -o "$REGEX_PASS1")
if [ "$VALID_PASS1" != "$PASS1" ]
then
die "invalid PASS1: pass $PASS_REF1_PASS"
fi
fi
if [ ! -z "$REGEX_PASS2" ]
then
VALID_PASS2=$(echo "$PASS2" | egrep -o "$REGEX_PASS2")
if [ "$VALID_PASS2" != "$PASS2" ]
then
die "install PASS2: pass $PASS_REF2_PASS"
fi
fi
xte "mousemove $X1 $Y1"
xte 'mouseclick 1'
[[ ! -z "$SLEEP1" ]] && sleep "$SLEEP1"
echo "$PASS1" | grep -o . | while read C
do
xte "key $C"
done
xte "mousemove $X2 $Y2"
xte 'mouseclick 1'
[[ ! -z "$SLEEP2" ]] && sleep "$SLEEP2"
echo "$PASS2" | grep -o . | while read C
do
xte "key $C"
done