-
Notifications
You must be signed in to change notification settings - Fork 1
/
pmss-legacy
775 lines (761 loc) · 26.7 KB
/
pmss-legacy
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#!/usr/bin/env bash
function bye_bye (){
printf "\033c"
echo -e '\E[1;32m'"A Screenshot Is An Image Of The Display On A Computer Screen"
echo -e '\E[1;32m'"But You Already Knew That So"
echo -e '\E[1;32m'"Bye, Ciao, Adios"
sleep 2
printf "\033c"
tput sgr0
exit 0
}
function view_log (){
test -f "${PMSS_LOG}" || { printf "\033c"; echo -e ""; echo -e '\E[1;32m'"PMSS Upload Log File Not Found"; echo -e '\E[1;32m'"Upload A Few Screenshots First"; echo -e ""; read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1; MenU; }
test -s "${PMSS_LOG}" || { printf "\033c"; echo -e ""; echo -e '\E[1;32m'"PMSS Upload Log File Is Empty"; echo -e '\E[1;32m'"Upload Some Screenshots First"; echo -e ""; read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1; MenU; }
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Enter \"V\" To View The Upload Log File"
echo -e '\E[1;32m'"Enter \"W\" To Wipe The Upload Log File"
echo -e '\E[1;32m'"Enter \"N\" To Go Back To The Main Menu"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"V" | "v")
if ! type less >/dev/null 2>&1; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Requires File Pager \"less\" To Display Upload Log"
echo -e '\E[1;32m'"Please Install Package \"less\" Via The Package Manager"
echo -e '\E[1;32m'"For Extra Information On \"less\" Please Visit Homepage"
echo -e '\E[1;32m'"http://www.greenwoodsoftware.com/less/"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
else
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Once You Are Done Viewing, Press \"Q\" To Close The File"
echo -e ""
read -rsp $'Press Any Key To View The File...\n' -n1
tput sgr0
less -RM "$PMSS_LOG"
MenU
fi
;;
"W" | "w")
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"This Will Clear Entire Upload Log! Are You Sure?"
echo -e ""
echo -e '\E[1;32m'"Enter \"Y\" To Wipe The Upload Log File"
echo -e '\E[1;32m'"Enter \"N\" To Go Back To The Main Menu"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
if type truncate >/dev/null 2>&1; then
truncate --size 0 "$PMSS_LOG"
else
: > "$PMSS_LOG"
fi
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"The Upload Log File Has Been Cleared"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
;;
"N" | "n")
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32m'"To Wipe The Upload Log File, Enter \"Y\""
echo -e '\E[1;32m'"To Go Back To The Main Menu, Enter \"N\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -rsp $'Press Any Key To Continue..\n' -n1
view_log
;;
esac
;;
"N" | "n")
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From V-W-N"
echo -e ""
echo -e '\E[1;32m'"To View The Upload Log File, Enter \"V\""
echo -e '\E[1;32m'"To Wipe The Upload Log File, Enter \"W\""
echo -e '\E[1;32m'"To Go Back To The Main Menu, Enter \"N\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -rsp $'Press Any Key To Continue..\n' -n1
view_log
;;
esac
}
function empty_dir (){
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"This Will Remove All Saved Screenshots! Are You Sure?"
echo -e ""
echo -e '\E[1;32m'"Enter \"Y\" To Empty Screenshots Directory"
echo -e '\E[1;32m'"Enter \"N\" To Move Back To Main PMSS Menu"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
if test -z "$(find "${DIR}" -maxdepth 1 -name '*.png' -print -quit)"; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Screenshots Directory Is Empty"
echo -e '\E[1;32m'"Nothing To Delete. Say Cheese!"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
else
PMSS_RM=$(which rm)
"$PMSS_RM" -f "${DIR}"/*.png
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Screenshots Directory Has Been Emptied"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
;;
"N" | "n")
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32m'"To Empty Screenshots Directory, Enter \"Y\""
echo -e '\E[1;32m'"To Move Back To Main PMSS Menu, Enter \"N\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -rsp $'Press Any Key To Continue..\n' -n1
empty_dir
;;
esac
}
function purge_shot (){
printf "\033c"
PMSS_RM=$(which rm)
"$PMSS_RM" -f "${NAME}"
MenU
}
function imgur_upload_personal (){
printf "\033c"
while IFS=: read -r k v; do
codes_map["$k"]="$v"
done < "${PMSS_CONFIG}"
if ! wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://api.imgur.com" -O /dev/null; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Cannot Connect To \"imgur\""
echo -e '\E[1;32m'"Check Your Internet Connection"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
RESPONSE=$(curl -s --connect-timeout 30 --user-agent "Mozilla/5.0 Gecko/20100101" -X POST -H "Authorization: Bearer ${codes_map[access_token]}" -F "image=@$NAME" "https://api.imgur.com/3/image.xml" 2>/dev/null)
if grep -q 'success="0"' <<<"$RESPONSE"; then
ERR_MSG2="${RESPONSE##*<error>}"
ERR_MSG="${ERR_MSG2%%</error>*}"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Something Went Wrong! Upload To imgur Failed!"
echo -e '\E[1;32m'"The Following Error Message Was Sent By imgur"
echo -e ""
echo -e '\E[1;32m'"\"$ERR_MSG\""
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
URL3="${RESPONSE##*<link>}"
URL2="${URL3%%</link>*}"
URL="${URL2//http:/https:}"
BASE_URL="${URL%.*}"
BASE_EXT="${URL##*.}"
DEL_HASH2="${RESPONSE##*<deletehash>}"
DEL_HASH="${DEL_HASH2%%</deletehash>*}"
DEL_URL="https://imgur.com/delete/${DEL_HASH}"
printf "\033c"
echo -e '\E[1;32m'"DIRECT LINK"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"${URL}"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"${BASE_URL}m.${BASE_EXT}"
echo -e ""
echo -e '\E[1;32m'"BBCODE LINK (FORUMS, MESSAGE BOARDS)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"[img]${URL}[/img]"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"[url=${BASE_URL}][img]${BASE_URL}m.${BASE_EXT}[/img][/url]"
echo -e ""
echo -e '\E[1;32m'"MARKDOWN LINK (REDDIT, GITHUB)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"[${SHORT_NAME}](${URL})"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"[${SHORT_NAME}](${BASE_URL}m.${BASE_EXT})"
echo -e ""
echo -e '\E[1;32m'"HTML LINK (WEBSITES, BLOGS)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"<a href=${BASE_URL}><img src=${URL} title=${SHORT_NAME} /></a>"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"<a href=${BASE_URL}><img src=${BASE_URL}m.${BASE_EXT} title=${SHORT_NAME} /></a>"
echo -e ""
echo -e '\E[1;32m'"DELETE LINK"
echo -e '\E[1;32m'"Delete url: "'\E[0;32m'"${DEL_URL}"
echo -e '\E[1;32m'""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
}
function imgur_token_test (){
if ! type curl >/dev/null 2>&1; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Requires \"cURL\" To Upload To imgur"
echo -e '\E[1;32m'"Install \"curl\" Via Your Package-manager"
echo -e '\E[1;32m'"For Extra Info Go To Website Of \"cURL\","
echo -e '\E[1;32m'"https://curl.haxx.se/"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
PERMS_CONFIG=$(stat -c "%a" "${PMSS_CONFIG}")
printf "\033c"
if ! [[ "${PERMS_CONFIG}" == 600 ]]; then
chmod 600 "${PMSS_CONFIG}"
fi
while IFS=: read -r k v; do
codes_map["$k"]="$v"
done < "${PMSS_CONFIG}"
TOKEN_TIME=$(find "${PMSS_CONFIG}" -mmin +40319)
if test "$TOKEN_TIME"; then
if ! wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://api.imgur.com" -O /dev/null; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Cannot Connect To \"imgur\""
echo -e '\E[1;32m'"Check Your Internet Connection"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
RESPONSE=$(curl -s --connect-timeout 30 --user-agent "Mozilla/5.0 Gecko/20100101" -X POST -H "Authorization: Bearer ${codes_map[access_token]}" -F "refresh_token=${codes_map[refresh_token]}" -F "client_id=${codes_map[client_id]}" -F "client_secret=${codes_map[client_secret]}" -F "grant_type=refresh_token" "https://api.imgur.com/oauth2/token" 2>/dev/null)
if grep -q 'success:false' <<<"$RESPONSE"; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Failed To Refresh The Access Token"
echo -e '\E[1;32m'"Please Retry The Process Sometime Later"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
while IFS=\" read -rd \, _ k _ v; do
if [[ "$k" = @(access_token|refresh_token) ]]; then
codes_map["$k"]="$v"
fi
done <<< "$RESPONSE"
printf '%s:%s\n' access_token "${codes_map[access_token]}" refresh_token "${codes_map[refresh_token]}" client_id "${codes_map[client_id]}" client_secret "${codes_map[client_secret]}" > "${PMSS_CONFIG}"
imgur_upload_personal
else
imgur_upload_personal
fi
}
function setup_stage2 (){
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Enter The \"Access Token\" Acquired During The Setup Process"
echo -e ""
read -er access_token
if [[ -z "$access_token" ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Nothing Was Entered!!!"
echo -e ""
sleep 2
setup_stage2
fi
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Enter The \"Refresh Token\" Acquired During The Setup Process"
echo -e ""
read -er refresh_token
if [[ -z "$refresh_token" ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Nothing Was Entered!!!"
echo -e ""
sleep 2
setup_stage2
fi
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Enter The \"Client ID\" Acquired During The Setup Process"
echo -e ""
read -er client_id
if [[ -z "$client_id" ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Nothing Was Entered!!!"
echo -e ""
sleep 2
setup_stage2
fi
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Enter The \"Client Secret\" Acquired During The Setup Process"
echo -e ""
read -er client_secret
if [[ -z "$client_secret" ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Nothing Was Entered!!!"
echo -e ""
sleep 2
setup_stage2
fi
codes_map[access_token]="$access_token"
codes_map[refresh_token]="$refresh_token"
codes_map[client_id]="$client_id"
codes_map[client_secret]="$client_secret"
printf '%s:%s\n' access_token "${codes_map[access_token]}" refresh_token "${codes_map[refresh_token]}" client_id "${codes_map[client_id]}" client_secret "${codes_map[client_secret]}" > "$PMSS_CONFIG"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"imgur \"OAuth 2\" Setup Is Now Complete"
echo -e '\E[1;32m'"Enjoy Uploading To Your imgur Account"
echo -e ""
read -r -s -p $'Press Any Key To Continue..\n' -n1
imgur_token_test
}
function setup_stage1 (){
if test -f "${PMSS_CONFIG}"; then
imgur_token_test
fi
echo -e ""
echo -e '\E[1;32m'"To Upload To Your imgur Account, \"OAuth 2\" Setup Needs To Be Completed"
echo -e '\E[1;32m'"Start The \"OAuth 2\" Setup Process Now?"
echo -e ""
echo -e '\E[1;32m'"Enter \"Y\" To Start The Setup"
echo -e '\E[1;32m'"Enter \"N\" To Go Back To Menu"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"First You Need To Register A New Application At imgur"
echo -e '\E[1;32m'"While Registering At imgur Do Select Following Option"
echo -e ""
echo -e '\E[0;32m'"\"OAuth 2 authorization without a callback URL\""
echo -e ""
echo -e ""
echo -e '\E[1;32m'"Open Following Link In A Browser To Register At imgur"
echo -e ""
echo -e '\E[0;32m'"https://api.imgur.com/oauth2/addclient"
echo -e ""
echo -e ""
echo -e '\E[1;32m'"You Would Now Have Your \"Client ID\" & \"Client Secret\""
echo -e '\E[1;32m'"Save Them In A Text File As They'll Be Required Later"
echo -e ""
read -rsp $'Press Any Key To Continue The Setup Process..\n' -n1
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Next In The Following Link, Replace \"CLIENT_ID\" With,"
echo -e '\E[1;32m'"Your \"Client ID\" Received After registration At imgur"
echo -e '\E[1;32m'"And Open The URL In A Browser To Receive Personal \"PIN\""
echo -e ""
echo -e '\E[0;32m'"https://api.imgur.com/oauth2/authorize?client_id=CLIENT_ID&response_type=pin"
echo -e ""
echo -e ""
echo -e '\E[1;32m'"imgur Webpage Will Display You The Following Message,"
echo -e ""
echo -e '\E[0;32m'"\"An application would like to connect to your account\""
echo -e ""
echo -e ""
echo -e '\E[1;32m'"On this imgur page simply click on the \"allow\" button"
echo -e '\E[1;32m'"You Will Now Have \"Client ID\" \"Client Secret\" & \"PIN\""
echo -e '\E[1;32m'"Save Them In A Text File As They'll Be Required Later"
echo -e ""
read -rsp $'Press Any Key To Continue The Setup Process..\n' -n1
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Replace \"CLIENT_ID\" \"CLIENT_SECRET\" & \"PIN\" With The,"
echo -e '\E[1;32m'"\"Client ID\" \"Client Secret\" & \"PIN\" That You Have Got"
echo -e '\E[1;32m'"From imgur And Run The Following Command In A Terminal"
echo -e ""
echo -e '\E[0;32m'"curl -X POST -F \"client_id=CLIENT_ID\" -F \"client_secret=CLIENT_SECRET\" -F \"pin=PIN\" -F \"grant_type=pin\" \"https://api.imgur.com/oauth2/token\""
echo -e ""
echo -e ""
echo -e '\E[1;32m'"You Will Now Have \"Access Token\" And \"Refresh Token\""
echo -e '\E[1;32m'"Save Them In A Text File As They'll Be Required Later"
echo -e ""
read -rsp $'Press Any Key To Continue The Setup Process..\n' -n1
setup_stage2
;;
"N" | "n")
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32m'"To Start OAuth 2 Set-up, Enter \"Y\""
echo -e '\E[1;32m'"To Go Back To Main Menu, Enter \"N\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -r -s -p $'Press Any Key To Continue..\n' -n1
setup_stage1
;;
esac
}
function imgur_upload_anonymous (){
if ! type curl >/dev/null 2>&1; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Requires \"cURL\" To Upload To imgur"
echo -e '\E[1;32m'"Install \"curl\" Via Your Package-manager"
echo -e '\E[1;32m'"For Extra Info Go To Website Of \"cURL\","
echo -e '\E[1;32m'"https://curl.haxx.se/"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
if ! wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://api.imgur.com" -O /dev/null; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"PMSS Cannot Connect To \"imgur\""
echo -e '\E[1;32m'"Check Your Internet Connection"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
RESPONSE=$(curl -s --connect-timeout 30 --user-agent "Mozilla/5.0 Gecko/20100101" -X POST -H "Authorization: Client-ID $ID_CLIENT" -F "image=@$NAME" "https://api.imgur.com/3/image.xml" 2>/dev/null)
if grep -q 'success="0"' <<<"$RESPONSE"; then
ERR_MSG2="${RESPONSE##*<error>}"
ERR_MSG="${ERR_MSG2%%</error>*}"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Something Went Wrong! Upload To imgur Failed!"
echo -e '\E[1;32m'"The Following Error Message Was Sent By imgur"
echo -e ""
echo -e '\E[1;32m'"\"$ERR_MSG\""
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
URL3="${RESPONSE##*<link>}"
URL2="${URL3%%</link>*}"
URL="${URL2//http:/https:}"
BASE_URL="${URL%.*}"
BASE_EXT="${URL##*.}"
DEL_HASH2="${RESPONSE##*<deletehash>}"
DEL_HASH="${DEL_HASH2%%</deletehash>*}"
DEL_URL="https://imgur.com/delete/${DEL_HASH}"
printf "\033c"
echo -e "################################################################################" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "DATE-TIME : $(date +"%d-%m-%Y::%H:%M:%S")" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "DIRECT LINK" >> "${PMSS_LOG}"
echo -e "Original : ${URL}" >> "${PMSS_LOG}"
echo -e "Thumbnail : ${BASE_URL}m.${BASE_EXT}" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "BBCODE LINK (FORUMS, MESSAGE BOARDS)" >> "${PMSS_LOG}"
echo -e "Original : [img]${URL}[/img]" >> "${PMSS_LOG}"
echo -e "Thumbnail : [url=${BASE_URL}][img]${BASE_URL}m.${BASE_EXT}[/img][/url]" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "MARKDOWN LINK (REDDIT, GITHUB)" >> "${PMSS_LOG}"
echo -e "Original : [${SHORT_NAME}](${URL})" >> "${PMSS_LOG}"
echo -e "Thumbnail : [${SHORT_NAME}](${BASE_URL}m.${BASE_EXT})" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "HTML LINK (WEBSITES, BLOGS)" >> "${PMSS_LOG}"
echo -e "Original : <a href=${BASE_URL}><img src=${URL} title=${SHORT_NAME} /></a>" >> "${PMSS_LOG}"
echo -e "Thumbnail : <a href=${BASE_URL}><img src=${BASE_URL}m.${BASE_EXT} title=${SHORT_NAME} /></a>" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "DELETE LINK" >> "${PMSS_LOG}"
echo -e "Delete url: ${DEL_URL}" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
echo -e "################################################################################" >> "${PMSS_LOG}"
echo -e "" >> "${PMSS_LOG}"
printf "\033c"
echo -e '\E[1;32m'"DIRECT LINK"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"${URL}"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"${BASE_URL}m.${BASE_EXT}"
echo -e ""
echo -e '\E[1;32m'"BBCODE LINK (FORUMS, MESSAGE BOARDS)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"[img]${URL}[/img]"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"[url=${BASE_URL}][img]${BASE_URL}m.${BASE_EXT}[/img][/url]"
echo -e ""
echo -e '\E[1;32m'"MARKDOWN LINK (REDDIT, GITHUB)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"[${SHORT_NAME}](${URL})"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"[${SHORT_NAME}](${BASE_URL}m.${BASE_EXT})"
echo -e ""
echo -e '\E[1;32m'"HTML LINK (WEBSITES, BLOGS)"
echo -e '\E[1;32m'"Original : "'\E[0;32m'"<a href=${BASE_URL}><img src=${URL} title=${SHORT_NAME} /></a>"
echo -e '\E[1;32m'"Thumbnail : "'\E[0;32m'"<a href=${BASE_URL}><img src=${BASE_URL}m.${BASE_EXT} title=${SHORT_NAME} /></a>"
echo -e ""
echo -e '\E[1;32m'"DELETE LINK"
echo -e '\E[1;32m'"Delete url: "'\E[0;32m'"${DEL_URL}"
echo -e '\E[1;32m'""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
}
function upload_check (){
if type xdg-open >/dev/null 2>&1; then
xdg-open "${NAME}" &> /dev/null
else
echo -e ""
echo -e '\E[1;32m'"PMSS Is Unable To Open The Screenshot"
echo -e '\E[1;32m'"It Needs \"xdg-utils\" Package To Do So"
echo -e ""
fi
echo -e ""
echo -e '\E[1;32m'"Do You Want To Upload The Screenshot?"
echo -e ""
echo -e '\E[1;32m'"Enter \"Y\" To Upload The Shot To imgur"
echo -e '\E[1;32m'"Enter \"D\" To Purge The Shot & Go Back"
echo -e '\E[1;32m'"Enter \"N\" To Go Back To The Main Menu"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Select The Preferred Image Upload Mode"
echo -e ""
echo -e '\E[1;32m'"Enter \"A\" For Anonymous Image Upload"
echo -e '\E[1;32m'"Enter \"U\" To Upload Image To Account"
echo -e ""
echo -e '\E[1;32m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"A" | "a")
printf "\033c"
imgur_upload_anonymous
;;
"U" | "u")
printf "\033c"
setup_stage1
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From A-P"
echo -e ""
echo -e '\E[1;32m'"For Uploading Image Anonymously, Enter \"A\""
echo -e '\E[1;32m'"To Upload Image To Your Account, Enter \"U\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -r -s -p $'Press Any Key To Continue..\n' -n1
MenU
;;
esac
;;
"D" | "d")
purge_shot
;;
"N" | "n")
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From Y-D-N"
echo -e ""
echo -e '\E[1;32m'"To Upload Image To imgur, Enter \"Y\""
echo -e '\E[1;32m'"To Delete Captured Image, Enter \"D\""
echo -e '\E[1;32m'"To Move Back To The Menu, Enter \"N\""
echo -e ""
echo -e '\E[1;32m'"Got it? It Is Not That Hard You See"
echo -e ""
read -rsp $'Press Any Key To Continue..\n' -n1
MenU
;;
esac
}
function area_mouse (){
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Draw A Rectangle On The Screen By Click-Dragging Left Mouse Button"
echo -e '\E[1;32m'"And Release The Mouse Button Once You Have Selected The Area To Be"
echo -e '\E[1;32m'"Captured. Region Inside The Drawn Rectangle Will Be Shot By Script"
echo -e ""
echo -e '\E[1;32m'"Once The Screen Capture Mode Is Activated, Pressing Any Keys Will"
echo -e '\E[1;32m'"Abort The Screenshot. So Keep The Keyboard Silent In Capture Mode"
echo -e ""
read -rsp $'Press Any Key To Activate Screen Capture Mode..\n' -n1
scrot -s "${NAME}"
RETVAL=$?
if [[ "$RETVAL" == 2 ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Keyboard Key Was Pressed. Screenshot Aborted"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
else
printf "\033c"
echo -e ""
echo -e '\E[0;32m'"${SHORT_NAME}"'\E[1;32m'" Saved In "'\E[0;32m'"${DIR}"
echo -e ""
upload_check
fi
}
function window_focus (){
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Minimize Terminal And Bring The Window To Be Captured In Focus.."
echo -e ""
scrot -u -d12 -b -c "${NAME}"
RETVAL=$?
if [[ "$RETVAL" == 2 ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Failed To Find A Focused Window"
echo -e '\E[1;32m'"Hence No Screenshot Is Captured"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
else
printf "\033c"
echo -e ""
echo -e '\E[0;32m'"${SHORT_NAME}"'\E[1;32m'" Saved In "'\E[0;32m'"${DIR}"
echo -e ""
upload_check
fi
}
function entire_area (){
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"Minimize Terminal & Any Open Window You Don't Wish To Capture.."
echo -e ""
scrot -d12 -c "${NAME}"
printf "\033c"
echo -e ""
echo -e '\E[0;32m'"${SHORT_NAME}"'\E[1;32m'" Saved In "'\E[0;32m'"${DIR}"
echo -e ""
upload_check
}
function MenU (){
export LC_ALL=C
type scrot >/dev/null 2>&1 || { printf "\033c"; echo -e ""; echo -e '\E[1;32m'"A required pmss dependency \"Scrot\" is not present."; echo -e '\e[1;32m'"\"Scrot\" is available for almost all linux distros."; echo -e '\e[1;32m'"Please install \"scrot\" using your package manager."; echo -e ""; tput sgr0; exit 1; }
if type xdg-user-dir >/dev/null 2>&1; then
DIR_CHECK="$(xdg-user-dir PICTURES)"
if [ "${DIR_CHECK}" != "${HOME}" ]; then
DIR="${DIR_CHECK}/Screenshots"
test -d "${DIR}" || mkdir -p "${DIR}"
fi
else
DIR="${HOME}/Pictures/Screenshots"
test -d "${DIR}" || mkdir -p "${DIR}"
fi
PMSS_LOG="${DIR}/pmss-upload.log"
test -f "${PMSS_LOG}" || touch "${PMSS_LOG}"
PMSS_CONFIG="${DIR}/.pmss.cfg"
ID_CLIENT=$(tr '\!-~' 'P-~\!-O' <<<"27a7g_h3ff562a4")
declare -A codes_map
printf "\033c"
echo -e '\E[1;32m'"** PMSS<>MENU *************************************************"
echo -e ""
echo -e '\E[1;32m'"** Select One Of The Following Options"
echo -e ""
echo -e '\E[1;32m'"** Enter \"E\" To Take The Screenshot Of The Entire Screen"
echo -e '\E[1;32m'"** Enter \"W\" To Take The Screenshot Of Window In Focus"
echo -e '\E[1;32m'"** Enter \"A\" To Take The Screenshot Of Area Selected By Mouse"
echo -e '\E[1;32m'"** Enter \"D\" To Empty Screenshots Directory"
echo -e '\E[1;32m'"** Enter \"L\" To Manage Upload Log"
echo -e '\E[1;32m'"** Enter \"Q\" To Exit"
echo -e ""
echo -e '\E[1;32m'"***************************************************************"
echo -e ""
tput sgr0
read -er Options
case "$Options" in
"E" | "e")
entire_area
;;
"W" | "w")
window_focus
;;
"A" | "a")
area_mouse
;;
"D" | "d")
empty_dir
;;
"L" | "l")
view_log
;;
"Q" | "q")
bye_bye
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32m'"\"$Options\" Is An Invalid Option!!!"
echo -e ""
echo -e '\E[1;32m'"Correct Options To Choose Are From E-W-A-D-Q"
echo -e ""
echo -e '\E[1;32m'"For Screenshot Of The Entire Screen, Press \"E\" & Hit \"Enter\" Key"
echo -e '\E[1;32m'"For Screenshot Of The Window In Focus, Press \"W\" & Hit \"Enter\" Key"
echo -e '\E[1;32m'"For Screenshot Of Area Selected By Mouse, Press \"A\" & Hit \"Enter\" Key"
echo -e '\E[1;32m'"To Empty Screenshots Directory, Press \"D\" & Hit \"Enter\" Key"
echo -e '\E[1;32m'"To Manage The Upload Log, Press \"L\" & Hit \"Enter\" Key"
echo -e '\E[1;32m'"To Exit From PMSS, Press \"Q\" & Hit \"Enter\" Key"
echo -e ""
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
;;
esac
}
while :
do
MenU
done