-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvnrez.sh
executable file
·896 lines (822 loc) · 24.1 KB
/
vnrez.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
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
#!/bin/bash
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
source "$SCRIPT_DIR/components/functions/variables.sh"
source "$SCRIPT_DIR/components/functions/config.sh"
source "$SCRIPT_DIR/components/functions/checks.sh"
source "$SCRIPT_DIR/components/functions/misc.sh"
source "$SCRIPT_DIR/components/functions/locks.sh"
source "$SCRIPT_DIR/components/functions/handlers.sh"
trap 'tput cnorm' EXIT
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
fi
handle_cases
handle_args "$1" "$2" "$3"
if [[ "$1" == "--help" || "$1" == "-h" || ( "$1" == "auto" && ( "$2" == "--help" || "$2" == "-h" )) ]]; then
help
fi
check_root
check_linux
check_dependencies
initial_setup() {
echo -e "Initializing.."
services=("e-z" "nest" "none")
selected=0
find "$SCRIPT_DIR/components" -type f -exec chmod +x {} \;
tput clear
prev_rows=$(tput lines)
prev_cols=$(tput cols)
while true; do
rows=$(tput lines)
cols=$(tput cols)
if [[ $rows -ne $prev_rows || $cols -ne $prev_cols ]]; then
tput clear
prev_rows=$rows
prev_cols=$cols
fi
tput civis
tput cup 0 0
rows=$(tput lines)
cols=$(tput cols)
vpad=$(((rows - 20) / 2))
hpad=$(((cols - 40) / 2))
for ((i = 0; i < vpad; i++)); do echo; done
printf "%${hpad}s" ""
logo_setup | while IFS= read -r line; do
printf "%${hpad}s%s\n" "" "$line"
done
printf "%${hpad}s" ""
printf " \e[36mWelcome to VNREZ Configuration\e[0m\n"
printf "%${hpad}s" ""
printf "Select your preferred host using arrow keys:\n"
for i in "${!services[@]}"; do
printf "%${hpad}s" ""
if [[ "${services[$i]}" == "none" ]]; then
if [[ $i -eq $selected ]]; then
echo -e "\e[32m◆ ${services[$i]}\e[0m"
else
echo "◇ ${services[$i]}"
fi
else
if [[ $i -eq $selected ]]; then
echo -e "\e[32m• ${services[$i]}\e[0m"
else
echo "◦ ${services[$i]}"
fi
fi
done
read -rsn1 input
case $input in
$'\x1b')
read -rsn2 -t 0.1 input
if [[ $input == "[D" ]]; then
((selected--))
if [[ $selected -lt 0 ]]; then
selected=$((${#services[@]} - 1))
fi
elif [[ $input == "[C" ]]; then
((selected++))
if [[ $selected -ge ${#services[@]} ]]; then
selected=0
fi
fi
;;
"W" | "w" | "A" | "a")
((selected--))
if [[ $selected -lt 0 ]]; then
selected=$((${#services[@]} - 1))
fi
;;
"S" | "s" | "D" | "d")
((selected++))
if [[ $selected -ge ${#services[@]} ]]; then
selected=0
fi
;;
"")
service=${services[$selected]}
break
;;
esac
done
tput cnorm
if [[ "$service" != "none" ]]; then
echo -e "\e[33mEnter your API Key for $service:\e[0m"
echo -n "✦ ) "
auth_token=""
while [[ -z "$auth_token" || ${#auth_token} -lt 30 ]]; do
while IFS= read -r -s -n1 char; do
if [[ $char == "" ]]; then
echo
break
fi
if [[ $char == $'\x7f' ]]; then
if [[ -n $auth_token ]]; then
auth_token=${auth_token%?}
echo -ne "\b \b"
fi
else
auth_token+="$char"
echo -n "*"
fi
done
if [[ -z "$auth_token" ]]; then
echo -e "\e[31mAPI Key cannot be empty!\e[0m"
elif [[ ${#auth_token} -lt 30 ]]; then
echo -e "\e[31mAPI Key isn't valid!\e[0m"
fi
if [[ -z "$auth_token" || ${#auth_token} -lt 30 ]]; then
sleep 1
tput cuu1
tput el
tput cuu1
tput el
tput cuu1
tput el
printf "\e[33mEnter your API Key for $service:\e[0m\n✦ ) "
fi
done
fi
screenshot_tools=()
if command -v flameshot >/dev/null; then
screenshot_tools+=("flameshot")
fi
if command -v grim >/dev/null; then
screenshot_tools+=("grimshot")
fi
selected=0
tput sc
while true; do
trap handle_resize SIGWINCH
tput rc
tput civis
tput el
echo -e "\e[33mChoose your screenshot tool:\e[0m"
for i in "${!screenshot_tools[@]}"; do
if [[ $i -eq $selected ]]; then
echo -e "\e[32m• ${screenshot_tools[$i]}\e[0m"
else
echo "◦ ${screenshot_tools[$i]}"
fi
done
read -rsn1 input
case $input in
$'\x1b')
read -rsn2 -t 0.1 input
if [[ $input == "[A" ]]; then
((selected--))
if [[ $selected -lt 0 ]]; then
selected=$((${#screenshot_tools[@]} - 1))
fi
elif [[ $input == "[B" ]]; then
((selected++))
if [[ $selected -ge ${#screenshot_tools[@]} ]]; then
selected=0
fi
fi
;;
"")
screenshot_tool=${screenshot_tools[$selected]}
break
;;
esac
done
if [[ "$screenshot_tool" == "grimshot" ]]; then
grimshot=true
if [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then
echo -ne "\e[33mWould you like to use grimblast? (Y/N):\e[0m "
tput cnorm
read -r user_choice
if [[ "$user_choice" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
blast=true
else
blast=false
fi
else
blast=false
fi
else
grimshot=false
blast=false
fi
if [[ "$prompt_service" == true ]]; then
create_config "$service" "$auth_token"
return
fi
if [[ ! ("$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon")) && "$XDG_SESSION_TYPE" != "x11" ]]; then
screen_recorders=()
if command -v wf-recorder >/dev/null; then
screen_recorders+=("wf-recorder")
fi
if command -v wl-screenrec >/dev/null; then
screen_recorders+=("wl-screenrec")
fi
selected=0
tput sc
while true; do
trap handle_resize SIGWINCH
tput rc
tput civis
tput el
echo -e "\e[33mChoose your screen recorder:\e[0m"
for i in "${!screen_recorders[@]}"; do
if [[ $i -eq $selected ]]; then
echo -e "\e[32m• ${screen_recorders[$i]}\e[0m"
else
echo "◦ ${screen_recorders[$i]}"
fi
done
read -rsn1 input
case $input in
$'\x1b')
read -rsn2 -t 0.1 input
if [[ $input == "[A" ]]; then
((selected--))
if [[ $selected -lt 0 ]]; then
selected=$((${#screen_recorders[@]} - 1))
fi
elif [[ $input == "[B" ]]; then
((selected++))
if [[ $selected -ge ${#screen_recorders[@]} ]]; then
selected=0
fi
fi
;;
"")
screen_recorder=${screen_recorders[$selected]}
break
;;
esac
done
if [[ "$screen_recorder" == "wl-screenrec" ]]; then
wlscreenrec=true
else
wlscreenrec=false
fi
fi
tput cnorm
if [[ ! ("$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon")) ]]; then
echo -e "\e[33mEnter the desired FPS (default is 60):\e[0m"
echo -n "✦ ) "
read -r fps
fps=${fps:-60}
while ! [[ "$fps" =~ ^[0-9]+$ ]] || [[ $fps -gt 244 ]]; do
echo -e "\e[31mFPS must be a number and cannot exceed 244. Please enter a valid FPS:\e[0m"
echo -n "✦ ) "
read -r fps
sleep 0.1
done
fi
if [[ "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon") ]]; then
echo -e "\e[33mDo you want to save recordings? (Y/N):\e[0m"
echo -n "✦ ) "
read -r save_recordings
sleep 0.1
if [[ "$save_recordings" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
save=true
echo -e "\e[33mEnter the directory to save files (You need to set it on Kooha too) (default is ~/Videos/Kooha) :\e[0m"
echo -n "✦ ) "
read -r kooha_dir
sleep 0.1
kooha_dir=${kooha_dir:-"~/Videos/Kooha"}
while [[ ! -d "$kooha_dir" || "$kooha_dir" == "/" || "$kooha_dir" != "$HOME"* ]]; do
echo -e "\e[31mInvalid directory! Please enter a valid directory path:\e[0m"
echo -n "✦ ) "
read -r kooha_dir
sleep 0.1
if [[ "$kooha_dir" == "~"* ]]; then
kooha_dir="$HOME${kooha_dir:1}"
fi
done
fi
fi
if [[ "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon") ]]; then
if [[ "$service" != "none" ]]; then
echo -e "\e[33mDo you want to enable failsave? (Y/N):\e[0m"
echo -n "✦ ) "
read -r failsave_option
sleep 0.1
if [[ "$failsave_option" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
failsave=true
else
failsave=false
fi
fi
fi
if [[ "$wlscreenrec" == false || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mEnter the desired CRF (default is 20):\e[0m"
echo -n "✦ ) "
read -r crf
sleep 0.1
crf=${crf:-20}
while ! [[ "$crf" =~ ^[0-9]+$ ]] || [[ $crf -gt 100 ]]; do
echo -e "\e[31mCRF must be a number and cannot exceed 100. Please enter a valid CRF:\e[0m"
echo -n "✦ ) "
read -r crf
sleep 0.1
done
fi
if [[ "$wlscreenrec" == false || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mEnter the desired preset (default is fast):\e[0m"
echo -n "✦ ) "
read -r preset
sleep 0.1
preset=${preset:-fast}
fi
if [[ "$wlscreenrec" == false || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mEnter the desired pixel format (default is yuv420p):\e[0m"
echo -n "✦ ) "
read -r pixelformat
sleep 0.1
pixelformat=${pixelformat:-yuv420p}
fi
if [[ "$wlscreenrec" == true ]]; then
echo -e "\e[33mEnter the desired pixel format (default is nv12):\e[0m"
echo -n "✦ ) "
read -r extpixelformat
sleep 0.1
extpixelformat=${extpixelformat:-nv12}
fi
if [[ "$wlscreenrec" == false || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mEnter the desired encoder (default is libx264):\e[0m"
echo -n "✦ ) "
read -r encoder
sleep 0.1
encoder=${encoder:-libx264}
fi
if [[ "$wlscreenrec" == true ]]; then
echo -e "\e[33mEnter the desired codec (default is auto):\e[0m"
echo -n "✦ ) "
read -r codec
sleep 0.1
codec=${codec:-auto}
fi
if [[ "$wlscreenrec" == true ]]; then
echo -e "\e[33mEnter the desired bitrate (default is 5 mb):\e[0m"
echo -n "✦ ) "
read -r bitrate
sleep 0.1
bitrate=${bitrate:-"\"5 mb"\"}
if [[ "$bitrate" != \"*\" ]]; then
bitrate="\"$bitrate\""
fi
fi
if [[ ! ("$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon")) ]]; then
echo -e "\e[33mDo you want to save recordings? (Y/N):\e[0m"
echo -n "✦ ) "
read -r save_recordings
sleep 0.1
directory=${directory:-"~/Videos"}
if [[ "$save_recordings" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
save=true
echo -e "\e[33mEnter the directory to save recordings (default is ~/Videos/) :\e[0m"
echo -n "✦ ) "
read -r directory
directory=${directory:-"~/Videos"}
sleep 0.1
while [[ ! -d "$directory" || "$directory" == "/" || "$directory" != "$HOME"* ]]; do
echo -e "\e[31mInvalid directory! Please enter a valid directory path:\e[0m"
echo -n "✦ ) "
read -r directory
directory=${directory:-"~/Videos"}
sleep 0.1
if [[ "$directory" == "~"* ]]; then
directory="$HOME${directory:1}"
fi
done
fi
if [[ "$service" != "none" ]]; then
echo -e "\e[33mDo you want to enable failsave? (Y/N):\e[0m"
echo -n "✦ ) "
read -r failsave_option
sleep 0.1
if [[ "$failsave_option" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
failsave=true
else
failsave=false
fi
fi
fi
if [[ "$XDG_SESSION_TYPE" == "wayland" || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mDo you want to have start notifications? (Y/N):\e[0m"
echo -n "✦ ) "
read -r startnotif
sleep 0.1
if [[ -z "$startnotif" || "$startnotif" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
startnotif=true
else
startnotif=false
fi
fi
if [[ "$XDG_SESSION_TYPE" == "wayland" || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mDo you want to have end notifications? (Y/N):\e[0m"
echo -n "✦ ) "
read -r endnotif
sleep 0.1
if [[ -z "$endnotif" || "$endnotif" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
endnotif=true
else
endnotif=false
fi
fi
create_config "$service" "$auth_token" "$fps" "$crf" "$preset" "$pixelformat" "$extpixelformat" "$wlscreenrec" "$codec" "$directory" "$failsave" "$save" "$encoder" "$startnotif" "$endnotif" "$grimshot" "$blast" "$bitrate"
}
if [[ "$1" == "config" || ( "$1" == "auto" && "$2" == "config" ) ]]; then
if [[ ! -f "$CONFIG_FILE" ]]; then
initial_setup
fi
if command -v xdg-open >/dev/null; then
xdg-open "$(eval echo $CONFIG_FILE)"
elif command -v open >/dev/null; then
open "$(eval echo $CONFIG_FILE)"
elif command -v nvim >/dev/null; then
nvim "$(eval echo $CONFIG_FILE)"
elif command -v nano >/dev/null; then
nano "$(eval echo $CONFIG_FILE)"
else
echo "No suitable text editor found. Please open $(eval echo $CONFIG_FILE) manually."
fi
exit 0
fi
if [[ "$1" == "reinstall" || ( "$1" == "auto" && "$2" == "reinstall" ) ]]; then
read -p "Do you want to reinstall the config file with default settings? (Y/N): " confirm
if [[ "$confirm" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
initial_setup
else
echo "Reinstallation canceled."
fi
exit 0
fi
if [[ ! -f "$CONFIG_FILE" && ! ( "$1" == "auto" && ( "$2" == "record" || "$2" == "shot" )) ]]; then
initial_setup
fi
if [[ "$1" == "auto" ]] || [[ ! -f "$CONFIG_FILE" && $(command -v grim) && ! $(command -v flameshot) && "$XDG_SESSION_TYPE" != "x11" && "$XDG_CURRENT_DESKTOP" != "GNOME" && "$XDG_CURRENT_DESKTOP" != "KDE" && "$XDG_CURRENT_DESKTOP" != "COSMIC" && "$XDG_CURRENT_DESKTOP" != "X-Cinnamon" ]]; then
grimshot=true
if [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then
blast=true
else
blast=false
fi
else
grimshot=false
blast=false
fi
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
update_config
fi
if [[ -z "$1" || ( "$1" == "auto" && -z "$2" ) ]]; then
options=("record" "shot" "upload" "ǀ" "⨯")
selected=0
tput clear
while true; do
tput civis
tput cup 0 0
rows=$(tput lines)
cols=$(tput cols)
vpad=$(((rows - 20) / 2))
hpad=$(((cols - ${#options[@]} * 15) / 2))
for ((i = 0; i < vpad; i++)); do echo; done
logo | while IFS= read -r line; do
hpad=$(((cols - ${#line}) / 2))
printf "%${hpad}s%s\n" "" "$line"
done
text="Select an option using arrow keys and press Enter:"
hpad=$(((cols - ${#text}) / 2))
printf "%${hpad}s" ""
echo -e "\e[36m$text\e[0m"
printf "%${hpad}s" ""
line=""
for i in "${!options[@]}"; do
if [[ "${options[$i]}" == "⨯" ]]; then
if [[ $i -eq $selected ]]; then
line+="\e[32m⨯\e[0m "
else
line+="⨯ "
fi
elif [[ "${options[$i]}" == "ǀ" ]]; then
line+="ǀ "
elif [[ $i -eq $selected ]]; then
line+="\e[32m• ${options[$i]}\e[0m "
else
line+="◦ ${options[$i]} "
fi
done
echo -e "$line"
read -rsn1 input
case $input in
$'\x1b')
read -rsn2 -t 0.1 input
if [[ $input == "[D" ]]; then
((selected--))
while [[ "${options[$selected]}" == "ǀ" ]]; do
((selected--))
done
if [[ $selected -lt 0 ]]; then
selected=$((${#options[@]} - 1))
fi
elif [[ $input == "[C" ]]; then
((selected++))
while [[ "${options[$selected]}" == "ǀ" ]]; do
((selected++))
done
if [[ $selected -ge ${#options[@]} ]]; then
selected=0
fi
fi
;;
"")
choice=${options[$selected]}
if [[ "$choice" == "⨯" ]]; then
tput cnorm
exit 0
fi
if [[ "$choice" == "upload" ]]; then
if [[ "$service" == "none" ]]; then
cols=$(tput cols)
error_message="ERROR: Service is none."
hpad=$(((cols - ${#error_message}) / 2))
printf "%${hpad}s\033[1;5;31mERROR:\033[0m Service is none.\n"
hpad=$(((cols - ${#text}) / 2))
printf "%${hpad}s%s" "" "Would you like to add a service? (Y/N): "
read -r add_service
if [[ "$add_service" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
prompt_service=true
initial_setup
exec "$0" "$@"
fi
else
tput cnorm
if [[ "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon") ]]; then
default_save_dir="$(eval echo $kooha_dir)"
else
default_save_dir="$(eval echo $directory)"
fi
printf "\nEnter the file paths to upload, separated by spaces (limit is 6):\n"
echo -n "✦"
echo -n " ) "
file_paths=""
while IFS= read -r -s -n1 char; do
if [[ $char == "" ]]; then
echo
break
fi
if [[ $char == $'\x7f' ]]; then
if [[ -n $file_paths ]]; then
file_paths=${file_paths%?}
echo -ne "\b \b"
fi
else
file_paths+="$char"
echo -ne "\033[4m$char\033[0m"
fi
done
IFS=' ' read -r -a paths_array <<<"$file_paths"
for i in "${!paths_array[@]}"; do
if [[ ! -f "${paths_array[$i]}" && "$save" == true ]]; then
if [[ -f "$default_save_dir/${paths_array[$i]}" ]]; then
paths_array[$i]="$default_save_dir/${paths_array[$i]}"
fi
fi
done
file_paths="${paths_array[*]}"
"$SCRIPT_DIR/components/upload.sh" $file_paths
sleep 2.5
exec "$0" "$@"
tput civis
fi
fi
if [[ "$choice" == "↩" ]]; then
exec "$0" "$@"
fi
break
;;
esac
done
tput cnorm
if [[ "$choice" == "record" ]]; then
if [[ "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon") ]]; then
base_options=("none" "gif" "abort")
else
base_options=("sound" "fullscreen-sound" "fullscreen" "no-sound" "gif" "abort")
fi
elif [[ "$choice" == "shot" ]]; then
acquire_lock
if command -v grim >/dev/null; then
if [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" && "$grimshot" == true && "$blast" == true ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimblast.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimblast.sh" "${@:2}"
fi
elif [[ "$grimshot" == true && "$blast" == false ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimshot.sh" "${@:2}"
fi
else
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
else
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
release_lock
exit 0
fi
sub_options=("${base_options[@]}" "ǀ" "↩" "⨯")
selected=0
tput clear
while true; do
tput civis
tput cup 0 0
cols=$(tput cols)
lines=$(tput lines)
vpad=$(((lines - 8) / 4))
for ((i = 0; i < vpad; i++)); do
echo ""
done
logo | while IFS= read -r line; do
hpad=$(((cols - ${#line}) / 2))
printf "%${hpad}s%s\n" "" "$line"
done
text="Select a sub-option for $choice using arrow keys and press Enter:"
hpad=$(((cols - ${#text}) / 2))
hpad_small=$(((cols - ${#text}) / 3 + 5))
printf "%${hpad}s" ""
echo -e "\e[36m$text\e[0m"
if [[ "$choice" == "record" && ! ("$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon")) ]]; then
printf "%${hpad_small}s" ""
else
printf "%${hpad}s"""
fi
line=""
for i in "${!sub_options[@]}"; do
if [[ "${sub_options[$i]}" == "↩" ]]; then
if [[ $i -eq $selected ]]; then
line+="\e[32m↩\e[0m "
else
line+="↩ "
fi
elif [[ "${sub_options[$i]}" == "⨯" ]]; then
if [[ $i -eq $selected ]]; then
line+="\e[32m⨯\e[0m "
else
line+="⨯ "
fi
elif [[ "${sub_options[$i]}" == "ǀ" ]]; then
line+="ǀ "
elif [[ $i -eq $selected ]]; then
line+="\e[32m• ${sub_options[$i]}\e[0m "
else
line+="◦ ${sub_options[$i]} "
fi
done
echo -e "$line"
read -rsn1 input
case $input in
$'\x1b')
read -rsn2 -t 0.1 input
if [[ $input == "[D" ]]; then
((selected--))
while [[ "${sub_options[$selected]}" == "ǀ" ]]; do
((selected--))
done
if [[ $selected -lt 0 ]]; then
selected=$((${#sub_options[@]} - 1))
fi
elif [[ $input == "[C" ]]; then
((selected++))
while [[ "${sub_options[$selected]}" == "ǀ" ]]; do
((selected++))
done
if [[ $selected -ge ${#sub_options[@]} ]]; then
selected=0
fi
fi
;;
"")
sub_choice=${sub_options[$selected]}
if [[ "$sub_choice" == "⨯" ]]; then
tput cnorm
exit 0
fi
if [[ "$sub_choice" == "↩" ]]; then
exec "$0" "$@"
fi
break
;;
esac
done
tput cnorm
if [[ "$choice" == "record" ]]; then
if [[ "$sub_choice" == "none" && "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC" || "$XDG_CURRENT_DESKTOP" == "X-Cinnamon") ]]; then
sleep 0.5
"$SCRIPT_DIR/components/record.sh" &>/dev/null
else
sleep 0.5
"$SCRIPT_DIR/components/record.sh" "--$sub_choice" &>/dev/null
fi
elif [[ "$choice" == "shot" ]]; then
if [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" && "$grimshot" == true && "$blast" == true ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimblast.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimblast.sh" "${@:2}"
fi
elif [[ "$grimshot" == true && "$blast" == false ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimshot.sh" "${@:2}"
fi
elif [[ "$grimshot" == false ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
else
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
sleep 0.2
exec "$0" "$@"
fi
if [[ "$1" == "upload" || "$1" == "-u" || ( "$1" == "auto" && ( "$2" == "upload" || "$2" == "-u" )) ]]; then
if [[ "$1" == "auto" ]]; then
"$SCRIPT_DIR/components/upload.sh" "${@:3}"
else
"$SCRIPT_DIR/components/upload.sh" "${@:2}"
fi
exit 0
fi
if [[ "$1" == "shot" || ( "$1" == "auto" && "$2" == "shot" ) ]]; then
acquire_lock
if [[ "$XDG_SESSION_TYPE" == "wayland" && ( "$XDG_CURRENT_DESKTOP" != "GNOME" && "$XDG_CURRENT_DESKTOP" != "KDE" && "$XDG_CURRENT_DESKTOP" != "COSMIC" && "$XDG_CURRENT_DESKTOP" != "X-Cinnamon" ) ]]; then
if [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" && "$grimshot" == true && "$blast" == true ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimblast.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimblast.sh" "${@:2}"
fi
elif [[ "$grimshot" == true && "$blast" == false ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/grimshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/grimshot.sh" "${@:2}"
fi
elif [[ "$grimshot" == false ]]; then
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
else
if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/flameshot.sh" auto "${@:2}"
else
"$SCRIPT_DIR/components/flameshot.sh" "${@:2}"
fi
fi
release_lock
exit 0
fi
if [[ "$1" == "record" || ( "$1" == "auto" && "$2" == "record" ) ]]; then
acquire_lock
if [[ ( "$1" == "auto" && "$2" == "--abort" ) || "$2" == "--abort" ]]; then
"$SCRIPT_DIR/components/record.sh" "${@:2}"
elif [[ ( "$1" == "auto" && "$2" == "record" ) || "$2" == "record" && ! -f "$CONFIG_FILE" ]]; then
if pgrep -x ffmpeg >/dev/null || pgrep -x wf-recorder >/dev/null || pgrep -x wl-screenrec >/dev/null || pgrep -x kooha >/dev/null; then
"$SCRIPT_DIR/components/record.sh" auto
release_lock
exit 0
else
if pgrep -x ffmpeg >/dev/null || pgrep -x wf-recorder >/dev/null || pgrep -x wl-screenrec >/dev/null || pgrep -x kooha >/dev/null; then
"$SCRIPT_DIR/components/record.sh"
release_lock
exit 0
fi
fi
if [[ ( "$1" == "auto" && "$2" == "record" ) || "$2" == "record" && ! -f "$CONFIG_FILE" ]]; then
"$SCRIPT_DIR/components/record.sh" auto "${@:3}"
fi
else
"$SCRIPT_DIR/components/record.sh" "${@:2}"
fi
release_lock
fi
exit 0