forked from evadogstar/qvm-screenshot-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qvm-screenshot-tool.sh
284 lines (224 loc) · 9.4 KB
/
qvm-screenshot-tool.sh
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/sh
# Take screenshot in Qubes Dom0, auto copy to AppVM, upload to imgurl service
# Dependencies: scrot at dom0 (sudo qubes-dom0-update scrot)
# zenity at dom0 and at AppVM (already exists by default at fedora and dom0)
#
# Plans: 1) delayed screenshots
# 2) select multi regions and make one image from all of them to upload
# 3) upload any image from dom0 after select it
# 4) editor of screenshots before upload
version="0.1beta"
DOM0_SHOTS_DIR=$HOME/Pictures
APPVM_SHOTS_DIR=/home/user/Pictures
QUBES_DOM0_APPVMS=/var/lib/qubes/appvms/
UPLOADHELPER=$(cat <<'EOFFILE'
#!/bin/bash
# Eva Dog Star imgurl uploader
imgur_anon_id="ea6c0ef2987808e"
# check arguments
if [ $# == 0 ]; then
echo "[ERROR] No file specified" >&2
exit 16
fi
# check curl is available
type curl >/dev/null 2>/dev/null || {
echo "[ERROR] Couln't find curl, which is required at AppVM." >&2
exit 17
}
file="$1"
logfile="$2"
# check file exists
if [ ! -f "$file" ]; then
echo "[ERROR] file '$file' doesn't exist at AppVM" >&2
exit 18
fi
response="$(curl --compressed --connect-timeout "5" -m "150" --retry "1" -fsSL --stderr - -H "Authorization: Client-ID ${imgur_anon_id}" -F "image=@$file" https://api.imgur.com/3/image)"
if egrep -q '"success":\s*true' <<<"${response}"; then
img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https!
del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
imgurl="https://i.imgur.com/${img_id}.${img_ext}"
imgdeleteurl="https://imgur.com/delete/${del_id}"
echo -e "Image url:\n$imgurl\n\nDelete image url: \n$imgdeleteurl\n\n \nQubes Screenshot Tool - EvaDogStar 2016" > $logfile
echo "[success] imgurl: $imgurl" >&2
echo "[success] delete url: $imgdeleteurl" >&2
else # upload failed
err_msg="$(egrep -o '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
test -z "${err_msg}" && err_msg="${response}"
echo "[ERROR] $err_msg"
echo "[RESPONSE] $response"
echo -e "Error: \n\n$err_msg \n\nImgurl Server response: \n\n$response\n\n\n \nQubes Screenshot Tool - EvaDogStar 2016" > $logfile
#echo ${err_msg}
fi
(which xclip &>/dev/null && echo -n "$imgurl" | xclip -selection clipboard ) || echo "[NOTE] no xclip at AppVM"
EOFFILE
)
#kdialog --msgbox "dsadasd"
#exit 1
#kdialog --inputbox "Url:" "fasffasf asfsaf af asf saf sdag sdg s" "dasdas" "fgdsgsad"
#exit 1
# vai_ksnapshootxxx()
# {
# # setGrabMode notes: 0=full-screen, 1=window, 2=region
# #kstart -iconify ksnapshot && sleep 0.2
# ksnapshot &
# sleep 1
# while [ "$PID" == "" ]; do PID="$(pgrep ksnapshot)"; done
# program="org.kde.ksnapshot-${PID}"
# #### qdbus $program /KSnapshot setGrabMode "$1"
# #####qdbus $program /KSnapshot setTime 0
# ####kdialog --radiolist "Continue upload process? Confirm only if you are ready" continue continue continue --default continue --title "$program" --nograb --noxim
# zenity --question --text "Move this mindow away and make screenshot. When you will be ready to upload image click on OK button."
# [[ $1 -eq 2 ]] && qdbus $program /KSnapshot slotGrab
# [[ $1 -eq 4 ]] && qdbus $program /KSnapshot slotGrab
# [[ $1 -eq 2 ]] && sleep 4
# #sleep 5
# #kdialog --msgbox "click yes when you done ?"
# # confirm dialog for region selection tool
# ### [[ $1 -eq 2 ]] && kdialog --radiolist "Continue upload process? Confirm only if you are ready" continue continue continue --default continue --title "$program" --nograb --noxim
# #qdbus $program /KSnapshot setURL "$2"
# #qdbus $program /KSnapshot slotSave
# PID="$(pgrep -n ksnapshot)"
# program="org.kde.ksnapshot-${PID}"
# qdbus $program /KSnapshot slotGrab
# sleep 2
# qdbus $program /KSnapshot save $2
# echo "$2"
# qdbus $program /KSnapshot exit
# }
checkscrot()
{
(which scrot &>/dev/null ) || {
scrotnomes="[EXIT] no \"scrot\" tool at dom0 installeted use: \n\nsudo qubed-dom0-update scrot \n\ncommand to add it first"
echo "$scrotnomes"
zenity --info --modal --text "$scrotnomes" &>/dev/null
exit 1
}
}
start_ksnapshoot()
{
PID="$(pgrep ksnapshot)"
if [ "$PID" == "" ]; then
ksnapshot &
sleep 1
fi
# setGrabMode notes: 0=full-screen, 1=window, 2=region
#kstart ksnapshot
#kdialog --radiolist "Now you can user Spapshot tool to make screenshots. When and only when you will be ready with screenshot (check preview area) click OKEY. Confirm only if you are ready!" READY READY READY --default continue --title "$program" --nograb --noxim
zenity --question --text "Move this mindow away and make screenshot. When you will be ready to upload image click on OK button."
# while [ "$PID" == "" ]; do PID="$(pgrep -n ksnapshot)"; done
# ksnap pid changed after using region selection tool
PID="$(pgrep ksnapshot)"
program="org.kde.ksnapshot-${PID}"
qdbus $program /KSnapshot save $2
echo "ksnap save: $2"
qdbus $program /KSnapshot exit
}
(which zenity &>/dev/null ) || {
scrotnomes="[FATAL] no \"zenity\" tool at dom0 installeted use: \n\nsudo qubed-dom0-update zenity command to add it first"
echo "$scrotnomes"
exit 1
}
program="`basename $0`"
shotslist=""
mkdir -p $DOM0_SHOTS_DIR ||exit 1
while true; do
d=`date +"%Y-%m-%d-%H%M%S"`
shotname=$d.png
ans=$(zenity --list --modal --text "Choose some available mode of capturing \n If you will use:" --radiolist --column "Pick" --column "Option" \
FALSE Ksnapshot \
TRUE "Region or Window" \
FALSE "Fullscreen" \
)
# echo $ans
if [ X"$ans" == X"Ksnapshot" ]; then
echo "[+] starting ksnapshot..."
start_ksnapshoot 4 $DOM0_SHOTS_DIR/$shotname || break
elif [ X"$ans" == X"Region or Window" ]; then
checkscrot || break
echo "[+] capturing window, click on it to select"
scrot -s -b $DOM0_SHOTS_DIR/$shotname || break
elif [ X"$ans" == X"Fullscreen" ]; then
checkscrot || break
echo "[+] capturing fullscreen desktop"
scrot -b $DOM0_SHOTS_DIR/$shotname || break
else
echo "You must select some mode to continue" && exit 1
fi
if [ -f "$DOM0_SHOTS_DIR/$shotname" ]
then
echo "[+] Success at dom0. Screenshot saved at $DOM0_SHOTS_DIR/$shotname" || break
else
echo "[ERROR] Something goes wrong and screenshot is not saved at dom0."
$(zenity --info --modal --text "Something goes wrong and screenshot is NOT saved at dom0")
exit 12
fi
[[ $mode_quick -eq 1 ]] && exit 1
shotslist="$shotname"
#shotslist="${shotslist}${shotname}:"
break
# [[ $mode_multi -eq 1 ]] && kdialog --yesno "Other shot ?" || break
done
ans=$(zenity --list --modal --width=200 --height=290 --text "Screenshot saved at dom0 \nWhat do you want to do next?\nSelect or multiselect some options:" --checklist --column "Pick" --column "Options" \
FALSE Exit \
FALSE "Upload to AppVM only" \
FALSE "Upload to Imgurl" \
FALSE "Start Nautilus at AppVM" \
FALSE "Keep screenshot at dom0"
)
#echo "xxx $ans xxx"
[[ X"$ans" == X"" ]] && exit 1
mode_onlyupload=0
mode_nautilus=0
mode_imgurl=0
mode_not_delete_screen_at_dom=0
IFSDEFAULT=$IFS
IFS='|'; for val in $ans;
do
#echo "variable: $val and $1"
case $val in
'Exit') echo "[+] Good Bye"; exit 1 ;;
'Upload to AppVM only') mode_onlyupload=1; ;;
'Upload to Imgurl') mode_imgurl=1; ;;
'Start Nautilus at AppVM') mode_nautilus=1; ;;
'Keep screenshot at dom0') mode_not_delete_screen_at_dom=1; ;;
# -r) mode_region=1; ;;
*) echo "Never Good Bye!"; exit 1 ;;
esac done
IFS=$IFSDEFAULT
choiceappvm=`ls $QUBES_DOM0_APPVMS |sed 's/\([^ ]*\)/FALSE \1 /g'`
#appvm=`kdialog --radiolist "Select destination AppVM" $choice --title "$program"`
appvm=$(zenity --list --modal --width=200 --height=390 --text "Select destination AppVM (unix based):" --radiolist --column "Pick" --column "AppVM" $choiceappvm )
#echo $appvm
if [ X"$appvm" != X"" ]; then
echo "[-] start AppVM: $appvm"
qvm-run -a $appvm "mkdir -p $APPVM_SHOTS_DIR"
if [ $mode_nautilus -eq 1 ]; then
echo "[-] running nautilus in AppVM"
qvm-run $appvm "nautilus $APPVM_SHOTS_DIR"
sleep 1
fi
shot=$shotslist
echo "[-] coping screenshot to $APPVM_SHOTS_DIR/$shot"
cat $DOM0_SHOTS_DIR/$shot \
|qvm-run --pass-io $appvm "cat > $APPVM_SHOTS_DIR/$shot"
[[ $mode_not_delete_screen_at_dom -eq 1 ]] && rm -f $DOM0_SHOTS_DIR/$shot && echo "[+] Screen at dom0 deleted $DOM0_SHOTS_DIR/$shot"
[[ $mode_onlyupload -eq 1 ]] && exit 1
[[ $mode_imgurl -eq 0 ]] && exit 1
echo "[-] copying imgurl uploader to AppVM $appvm"
# echo $UPLOADHELPER \
# | qvm-run --pass-io $appvm "echo $UPLOADHELPER > $APPVM_SHOTS_DIR/autouplodertemp.sh"
uploadername='evauploadermgur.sh'
logfile="$APPVM_SHOTS_DIR/imgurl.log"
echo "$UPLOADHELPER" | qvm-run --pass-io $appvm "cat > $APPVM_SHOTS_DIR/$uploadername"
qvm-run --pass-io $appvm "chmod +x $APPVM_SHOTS_DIR/$uploadername"
RESULT="$(qvm-run --pass-io $appvm "$APPVM_SHOTS_DIR/$uploadername $APPVM_SHOTS_DIR/$shot $logfile")"
qvm-run $appvm "rm $APPVM_SHOTS_DIR/$uploadername"
#qvm-run $appvm "gedit $logfile"
qvm-run $appvm "zenity --text-info --width=500 --height=180 --modal --filename=$logfile --text Ready"
echo $RESULT
#done
else
echo "[-] no AppVM name provided"
fi
echo "[*] Dom0 say Good Bye"