-
Notifications
You must be signed in to change notification settings - Fork 11
/
container-session
executable file
·1478 lines (1081 loc) · 29.4 KB
/
container-session
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
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# dependencies /////////////////////////////////////////////////////////////////
if [[ -z $(command -v frobulator) ]]
then
if [[ $(id -u -n) = "root" ]]
then
SUDO_HOME=/root
USER="${SUDO_USER}"
HOME=/home/"${USER}"
fi
if [[ -z $(command -v curl) ]]
then
yes | apt-get install curl
fi
if [ ! -d "${HOME}"/.local/bin ]
then
mkdir -p "${HOME}"/.local/bin
fi
curl -s -L get.frbltr.app > "${HOME}"/.local/bin/frobulator
chmod +x "${HOME}"/.local/bin/frobulator
fi
. "${HOME}"/.local/bin/frobulator
# script ///////////////////////////////////////////////////////////////////////
script=$(basename -- "${BASH_SOURCE[0]}")
# version //////////////////////////////////////////////////////////////////////
version="05-29-2024"
# usage ////////////////////////////////////////////////////////////////////////
while (($#))
do
case "${1}"
in
-o|--start)
option="start"
display="${2}"
shift
;;
-x|--stop)
option="stop"
display="${2}"
shift
;;
-p|--password)
option="password"
;;
-c|--clean)
option="clean"
;;
-n|--new)
option="new"
;;
-v|--view)
option="view"
;;
-a|--application)
option="application"
application="${2}"
shift
;;
-u|--username)
option="username"
user_name="${2}"
shift
;;
-r|--root)
option="root"
root_filesystem="${2}"
shift
;;
-h|--help)
echo
echo -e "Usage: ${script} -o [Display Server] | -u [User Name] | -a [Application] | -n [Selection] | [OPTION]"
echo
echo -e "Options:"
echo
echo -e "-o, --start Start display session server."
echo -e " [ vnc ]"
echo -e " [ x11 ] [ Default ]"
echo
echo -e "-x, --stop Stop display session server."
echo -e "-p, --password Generate display session password."
echo
echo -e "-c, --clean Clean display session geometry selection."
echo -e "-n, --new Generate new display session geometry selection."
echo -e "-v, --view Reload display viewer application window."
echo
echo -e "-a, --application Specify application to start on session login."
echo
echo -e "-u, --username Specify user name for session login."
echo
echo -e "-r, --root Specify root filesystem directory."
echo
echo -e "-h, --help Show help and usage information."
echo
echo -e "'${script}' [ Version // ${version} ]"
echo
exit
;;
"")
# handle empty argument:
# use default values specified in script
:
;;
*)
echo
echo -e "Usage: ${script} -o [Display Server] | -u [User Name] | -a [Application] | -n [Selection] | [OPTION]"
echo
echo -e "${script}: Unknown option '${1}'"
echo -e "Type './${script} --help' for help and usage information."
echo
exit 1
;;
esac
shift
done
# prompt ///////////////////////////////////////////////////////////////////////
frobulator.script "Setting up ${script#*-}"
# variables ////////////////////////////////////////////////////////////////////
# reference session viewer activity calls for known android applications:
# FreebVNC: com.iiordanov.freebVNC/com.iiordanov.bVNC.RemoteCanvasActivity
# RealVNC: com.realvnc.viewer.android/.app.DesktopActivity
# Remotix: com.nulana.android.remotix/.Viewer
# Termux:x11: com.termux.x11/.MainActivity
free_vnc_activity="com.iiordanov.freebVNC/com.iiordanov.bVNC.RemoteCanvasActivity"
real_vnc_activity="com.realvnc.viewer.android/.app.DesktopActivity"
remotix_vnc_activity="com.nulana.android.remotix/.Viewer"
termux_x11_activity="com.termux.x11/.MainActivity"
termux_x11_activity_stop="com.termux.x11.ACTION_STOP"
# defaults /////////////////////////////////////////////////////////////////////
if [ -z "${display}" ]
then
display="x11"
fi
if [ -z "${environment}" ]
then
environement="$(cat ${HOME}/.dextop/dextop-environment)"
fi
if [ -z "${session}" ]
then
session="$(cat ${HOME}/.dextop/dextop-session)"
fi
if [ -z "${LOCALHOST}" ]
then
LOCALHOST="127.0.0.1"
fi
if [ -z "${ADDRESS}" ]
then
ADDRESS="${LOCALHOST}"
fi
if [ -z "${PORT}" ]
then
PORT="590${DISPLAY_NUMBER}"
fi
if [ -z "${COLORTERM}" ]
then
COLORTERM="truecolor"
fi
if [ -z "${LANG}" ]
then
LANG="C.UTF-8"
fi
if [ -z "${SHELL}" ]
then
SHELL="/bin/bash"
fi
if [ -z "${DISPLAY}" ]
then
DISPLAY=":0"
fi
if [ -z "${DISPLAY_NUMBER}" ]
then
DISPLAY_NUMBER="${DISPLAY/:/}"
fi
if [ -z "${DISPLAY_DRIVER}" ]
then
DISPLAY_DRIVER="virpipe"
fi
if [ -z "${GALLIUM_DRIVER}" ]
then
GALLIUM_DRIVER="${DISPLAY_DRIVER}"
fi
if [ -f /etc/os-release ]
then
. /etc/os-release
name="${NAME}"
fi
# exports //////////////////////////////////////////////////////////////////////
export DISPLAY="${DISPLAY}"
export GALLIUM_DRIVER="${DISPLAY_DRIVER}"
# functions ////////////////////////////////////////////////////////////////////
container_root () {
# set container root directory
CONTAINER_ROOT=("${PREFIX}"/cnt/*/*)
# single container
if [[ ${#CONTAINER_ROOT[@]} -eq 1 ]]
then
CONTAINER_ROOT=("${PREFIX}"/cnt/*/*)
fi
# multiple containers:
# parse container directories
if [[ ${#CONTAINER_ROOT[@]} -ge 2 ]]
then
for distribution in "${PREFIX}"/cnt/*
do
for version in "${distribution}"/*
do
distribution_name=$(basename $distribution)
distribution_version=$(basename $version)
containers+=($distribution_name $distribution_version)
done
done
# set padding for uniform output
pad_length=10
# continue list using array selection of suppported values
for (( i=0 ; i<${#containers[@]} ; i+=2 ))
do
name="${containers[$i]}"
version="${containers[$i+1]}"
container="${name} ${version}"
number=$((($i/2) + 1))
if (( $i/2 >= 0 && $i/2 <= 8 ))
then
# handle number spacing for entries 1-9
printf ' [ %s ] %s ' ${number} ${name}
else
# handle number spacing for entries 10+
printf ' [ %s ] %s ' ${number} ${name}
fi
printf '%*s' $((pad_length - ${#name}))
printf '%s\n' ${version}
done
printf '\n'
container_handle
fi
}
container_handle () {
# values #
values_list=(
selection
)
# handle user input for values_list
frobulator_return=()
if [ -f "${HOME}"/.dextop/selection ]
then
selection=$(cat "${HOME}"/.dextop/selection)
else
frobulator.input ${values_list[@]}
fi
eval ${frobulator_return[@]}
# check selection input against selection list
while true
do
# range check:
# selection input must be in provided range and an integer
if [[ "${selection}" -lt 1 ]] || \
[[ "${selection}" -gt "${number}" ]] || \
[[ ! "${selection}" =~ ^[0-9]+$ ]]
then
echo
frobulator.err "Invalid selection:"
echo
frobulator.wrn "Select container [ 1 - ${number} ]"
echo
frobulator.ipt "Selection:"
frobulator.read selection
else
break
fi
done
distribution_name="${name}"
distribution_version="${version}"
CONTAINER_ROOT="${PREFIX}"/cnt/"${distribution_name}"/"${distribution_version}"
}
container_input () {
if [ -d "${root_filesystem}" ]
then
CONTAINER_ROOT="${root_filesystem}"
frobulator.scs "Container location found."
echo
frobulator.inf "Loading" "[ ${CONTAINER_ROOT} ]"
echo
else
frobulator.err "Container location not found."
echo
frobulator.ipt "Select one of the following containers:"
echo
container_handle
fi
}
container_environment () {
# generate container environement
# set path:
# in order of retreival
CONTAINER_PATH=""
# container
[ -d "${CONTAINER_ROOT}"/usr/local/sbin ] && CONTAINER_PATH+="/usr/local/sbin:"
[ -d "${CONTAINER_ROOT}"/usr/local/bin ] && CONTAINER_PATH+="/usr/local/bin:"
[ -d "${CONTAINER_ROOT}"/usr/sbin ] && CONTAINER_PATH+="/usr/sbin:"
[ -d "${CONTAINER_ROOT}"/usr/sbin ] && CONTAINER_PATH+="/usr/bin:"
[ -d "${CONTAINER_ROOT}"/sbin ] && CONTAINER_PATH+="/sbin:"
[ -d "${CONTAINER_ROOT}"/bin ] && CONTAINER_PATH+="/bin:"
# termux
[ -d "${HOME}"/.local/bin ] && CONTAINER_PATH+="${HOME}/.local/bin:"
[ -d "${PREFIX}"/sbin ] && CONTAINER_PATH+="${PREFIX}/sbin:"
[ -d "${PREFIX}"/bin ] && CONTAINER_PATH+="${PREFIX}/bin:"
# android
[ -d /system/sbin ] && CONTAINER_PATH+="/system/sbin:"
[ -d /system/bin ] && CONTAINER_PATH+="/system/bin:"
CONTAINER_PATH="${CONTAINER_PATH}"
return
}
container_user () {
# authentication
frobulator.fwd "Authenticating${marker_elp}"
echo
# verify user existence:
# loop through container's /etc/passwd file and make sure 'user' exists
# source environment variables when 'user' corresponds to 'username'
# default to 'root' if 'username' is invalid, is not specified or does not exist
last_entry="$(tail -n 1 "${CONTAINER_ROOT}"/etc/passwd)"
while read -r entry
do
IFS=':'
read USER _ USER_ID GROUP_ID GECOS HOME SHELL <<< "${entry}"
IFS=','
read FULL_NAME ROOM_NUMBER WORK_PHONE HOME_PHONE USER_EMAIL <<< "${GECOS}"
# reset IFS
IFS=' '
# verify login options and parameters
# no user name specified
if [[ -z "${user_name}" ]]
then
user_name="root"
USER="root"
USER_ID="0"
GROUP_ID="0"
UID="${USER_ID}"
GID="${GROUP_ID}"
if [ -d "${CONTAINER_ROOT}"/root ]
then
HOME="/root"
else
HOME="/"
fi
frobulator.wrn "No user name - Defaulting" "[ '${user_name}' ]"
echo
break
fi
# valid user name found
if [[ "${user_name}" == "${USER}" ]]
then
USER="${user_name}"
if [[ "${user_name}" == "root" ]]
then
frobulator.wrn "Valid user name - Superuser" "[ '${user_name}' ]"
echo
else
frobulator.scs "Valid user name - Accessing" "[ '${user_name}' ]"
echo
fi
break
fi
# user naem not found
if [[ "${entry}" == "${last_entry}" ]]
then
frobulator.err "Invalid user name - Aborting" "[ '${user_name}' ]"
echo
exit 1
fi
done < "${CONTAINER_ROOT}"/etc/passwd
}
container_session () {
# load session settings
# assume 'termux-exec' is installed
unset LD_PRELOAD
# setup 'proot' command arguments
unset session_command
session_command+="proot"
session_command+=" --kill-on-exit"
session_command+=" --link2symlink"
session_command+=" --rootfs=${CONTAINER_ROOT}"
session_command+=" --change-id=${USER_ID}:${GROUP_ID}"
session_command+=" --pwd=${HOME}"
# android 10+ requirements
[ -d "/apex" ] && intent_command+=" --bind=/apex:/apex"
[ -e "/linkerconfig/ld.config.txt" ] && intent_command+=" --bind=/linkerconfig/ld.config.txt:/linkerconfig/ld.config.txt"
# android requirements
[ -d "/data" ] && session_command+=" --bind=/data:/data"
[ -d "/dev" ] && session_command+=" --bind=/dev:/dev"
[ -e "/dev/urandom" ] && session_command+=" --bind=/dev/urandom:/dev/random"
[ -d "/proc" ] && session_command+=" --bind=/proc:/proc"
[ -d "/proc/self/fd" ] && session_command+=" --bind=/proc/self/fd:/dev/fd"
[ -e "/proc/self/fd/0" ] && session_command+=" --bind=/proc/self/fd/0:/dev/stdin"
[ -e "/proc/self/fd/1" ] && session_command+=" --bind=/proc/self/fd/1:/dev/stdout"
[ -e "/proc/self/fd/2" ] && session_command+=" --bind=/proc/self/fd/2:/dev/stderr"
[ -d "/storage" ] && session_command+=" --bind=/storage:/storage"
[ -d "/sys" ] && session_command+=" --bind=/sys:/sys"
[ -d "/system" ] && session_command+=" --bind=/system:/system"
[ -d "/vendor" ] && session_command+=" --bind=/vendor:/vendor"
[ -d "${PREFIX%/*}"/home ] && session_command+=" --bind=${PREFIX%/*}/home:${HOME}"
[ -d "${PREFIX}"/storage/external ] && session_command+=" --bind=${PREFIX}/storage/external:/media/external"
[ -d "${PREFIX}"/storage/internal ] && session_command+=" --bind=${PREFIX}/storage/internal:/media/internal"
[ -d "${PREFIX}"/storage/internal/Documents ] && session_command+=" --bind=${PREFIX}/storage/internal/Documents:/home/${USER}/Documents"
[ -d "${PREFIX}"/storage/internal/Downloads ] && session_command+=" --bind=${PREFIX}/storage/internal/Downloads:/home/${USER}/Documents"
[ -d "${PREFIX}"/storage/internal/Music ] && session_command+=" --bind=${PREFIX}/storage/internal/Music:/home/${USER}/Music"
[ -d "${PREFIX}"/storage/internal/Pictures ] && session_command+=" --bind=${PREFIX}/storage/internal/Pictures:/home/${USER}/Pictures"
[ -d "${PREFIX}"/storage/internal/Public ] && session_command+=" --bind=${PREFIX}/storage/internal/Public:/home/${USER}/Public"
[ -d "${PREFIX}"/storage/internal/Templates ] && session_command+=" --bind=${PREFIX}/storage/internal/Templates:/home/${USER}/Templates"
[ -d "${PREFIX}"/storage/internal/Videos ] && session_command+=" --bind=${PREFIX}/storage/internal/Videos:/home/${USER}/Videos"
[ -d "${PREFIX}"/tmp ] && session_command+=" --bind=${PREFIX}/tmp:/tmp"
# environemnt
session_command+=" env"
session_command+=" --ignore-environment"
session_command+=" ANDROID_ART_ROOT=${ANDROID_ART_ROOT}"
session_command+=" ANDROID_DATA=${ANDROID_DATA}"
session_command+=" ANDROID_I18N_ROOT=${ANDROID_I18N_ROOT}"
session_command+=" ANDROID_ROOT=${ANDROID_ROOT}"
session_command+=" ANDROID_RUNTIME_ROOT=${ANDROID_RUNTIME_ROOT}"
session_command+=" ANDROID_TZDATA_ROOT=${ANDROID_TZDATA_ROOT}"
session_command+=" BOOTCLASSPATH=${BOOTCLASSPATH}"
session_command+=" DEX2OATBOOTCLASSPATH=${DEX2OATBOOTCLASSPATH}"
# termux
session_command+=" PREFIX=${PREFIX}"
# container
session_command+=" COLORTERM=${COLORTERM}"
session_command+=" DISPLAY=${DISPLAY}"
session_command+=" DISPLAY_DRIVER=${DISPLAY_DRIVER}"
session_command+=" HOME=${HOME}"
session_command+=" LANG=${LANG}"
session_command+=" LOCALHOST=${LOCALHOST}"
session_command+=" PATH=${PATH}"
session_command+=" SHELL=${SHELL}"
session_command+=" TERM=${TERM}"
session_command+=" TMPDIR=${TMPDIR}"
session_command+=" USER=${USER}"
session_command+=" XDG_RUNTIME_DIR=/run/user/${USER_ID}"
session_command+=" XDG_CONFIG_DIRS=/etc/xdg"
session_command+=" XDG_CACHE_HOME=${HOME}/.cache"
session_command+=" XDG_CONFIG_HOME=${HOME}/.config"
session_command+=" XDG_DATA_HOME=${HOME}/.local/share"
session_command+=" XDG_STATE_HOME=${HOME}/.local/state"
session_command+=" XDG_DATA_DIRS=/usr/local/share:/usr/share"
session_command+=" XAUTHORITY=${XDG_RUNTIME_DIR}/Xauthority"
# command
session_command+=" ${SHELL}"
session_command+=" --login"
# execute 'proot'
${session_command}
}
server_intent () {
unset load_command
if [[ "${display}" = [vV][nN][cC] ]]
then
load_command+="x11vnc"
load_command+=" -display ${DISPLAY}"
load_command+=" -clip xinerama=${DISPLAY}"
load_command+=" -rfbport ${PORT}"
load_command+=" -scale 1.00"
load_command+=" -xkb"
load_command+=" -nocursor"
load_command+=" -nocursorshape"
load_command+=" -noshm"
load_command+=" -noxdamage"
load_command+=" -noxfixes"
load_command+=" -noxrecord"
${load_command} > "${sink}" 2>&1 &
fi
if [[ "${display}" = [xX][1][1] ]]
then
unset load_command
if [[ $(pidof virgl*) ]]
then
:
else
load_command+="virgl_test_server_android"
${load_command} > "${sink}" 2>&1 &
fi
unset load_command
if [[ $(pidof app_process / com.termux.x11.Loader) ]]
then
:
else
load_command+="termux-x11"
${load_command} > "${sink}" 2>&1 &
fi
fi
}
display_clean () {
if [[ "${display}" = [vV][nN][cC] ]]
then
if [ -d "${HOME}" ]
then
rm -r -f "${HOME}"/.ICE*
rm -r -f "${HOME}"/.X11*
rm -r -f "${HOME}"/.Xauth*
fi
if [ -d "${TMPDIR}" ]
then
rm -r -f "${TMPDIR}"/.ICE*
rm -r -f "${TMPDIR}"/.X11*
rm -r -f "${TMPDIR}"/.Xauth*
fi
fi
if [[ "${display}" = [xX][1][1] ]]
then
:
fi
}
display_geometry () {
frobulator.msg "Select geometry or input [c]ustom properties:"
echo
# list supported display resolutions
monitors=(
VGA 0640 0480
WVGA 0768 0480
SVGA 0800 0600
FWVGA 0854 0480
qHD 0960 0540
DVGA 0960 0640
WSVGA 1024 0576
WSVGA 1024 0600
XGA 1024 0768
XGA+ 1152 0864
HD 1280 0720
WXGA 1366 0768
WXGA+ 1440 0900
HD+ 1600 0900
SXGA 1280 1024
SXGA+ 1400 1050
UXGA 1600 1200
WSXGA+ 1680 1050
FHD 1920 1080
WUXGA 1920 1200
DCI2K 2048 1080
QWXGA 2048 1152
QXGA 2048 1536
UWFHD 2560 1080
QHD 2560 1440
WQXGA 2560 1600
QSXGA 2560 2048
QHD+ 3200 1800
WQSXGA 3200 2048
QUXGA 3200 2400
UWQHD 3440 1440
UW4K 3840 1600
4KUHD 3840 2160
WQUXGA 3840 2400
DCI4K 4096 2160
UW5K 5120 2160
5K 5120 2880
8KUHD 7680 4320
)
phones=(
GN6P 2560 1440
GN6 2560 1440
GN5X 1920 1080
GN5 1920 1080
GP5 2340 1080
GP4XL 3040 1440
GP4a 2340 1080
GP4 2280 1080
GP3aXL 2160 1080
GP3a 2220 1080
GP3XL 2960 1440
GP3 2160 1080
GP2XL 2880 1440
GP2 1920 1080
GPXL 2560 1440
GP 1920 1080
SGN20+ 3088 1440
SGN20 3200 1440
SGN10+ 3040 1440
SGN10 2280 1080
SGN9 2960 1440
SGN8 2960 1440
SGN7 2560 1440
SGS10+ 3040 1440
SGS10 3040 1440
SGS9+ 2960 1440
SGS9 2960 1440
SGS8+ 2960 1440
SGS8 2960 1440
SGS7E 2560 1440
SGS7 2560 1440
SGS6E+ 2560 1440
SGS6E 2560 1440
SGS6 2560 1440
)
tablets=(
GN9 2048 1536
GN7-2013 1920 1200
GPC 2560 1800
SGTS7+ 2800 1752
SGTS7 2560 1600
SGTS6 2560 1600
SGTS5E 2560 1600
)
devices=(
${phones[@]}
${tablets[@]}
)
geometries=(
${monitors[@]}
${devices[@]}
)
# set padding for uniform output
pad_length=10
# continue list using array selection of suppported values
for (( i=0 ; i<${#geometries[@]} ; i+=3 ))
do
format="${geometries[$i]}"
width="${geometries[$i+1]}"
height="${geometries[$i+2]}"
geometry="${width}x${height}"
number=$(( ( $i / 3 ) + 1 ))
if (( $i / 3 >= 0 && $i / 3 <= 8 ))
then
# handle number spacing for entries 1-9
printf ' [ %s ] %s' ${number} ${format}
else
# handle number spacing for entries 10+
printf ' [ %s ] %s' ${number} ${format}
fi
printf '%*s' $(( pad_length - ${#format} ))
printf '%s\n' ${geometry}
done
printf '\n'
}
display_handle () {
# values #
values_list=(
selection
)
# handle user input for values_list
frobulator_return=()
if [ -f "${HOME}"/.vnc/selection ]
then
selection=$(cat "${HOME}"/.vnc/selection)
else
frobulator.input ${values_list[@]}
fi
eval ${frobulator_return[@]}
# check selection input against selection list
while true
do
# range check:
# selection input must be in provided range and an integer
if [[ "${selection}" -lt 1 ]] || \
[[ "${selection}" -gt "${number}" ]] || \
[[ ! "${selection}" =~ ^[0-9]+$ ]]
then
echo
frobulator.err "Invalid selection:"
echo
frobulator.wrn "Select geometry [ 1 - ${number} ] or input [c]ustom properties."
echo
frobulator.ipt "Selection:"
frobulator.read selection
else
break
fi
if [[ "${selection}" = [cC] ]]
then
selection=custom
break
fi
done
unset geometry
# integer check:
# handle numerical selection
if [[ "${selection}" =~ ^[0-9]+$ ]]
then
i=$(( ${selection} ))
i=$(( $i * 3 ))
format="${geometries[$i-3]}"
width="${geometries[$i-2]}"
height="${geometries[$i-1]}"
geometry="${width}x${height}"
fi
# handle custom selection
if [[ "${selection}" = "custom" ]]
then
frobulator.fwd "Setting custom properties${marker_elp}"
echo
frobulator.ipt "Set width" "[ pixels ]"
frobulator.read width
frobulator.ipt "Set height" "[ pixels ]"
frobulator.read height
frobulator.ipt "Set display number" "[ e.g. 1 ]"
frobulator.read display
format="Custom"
geometry="${width}x${height}"
DISPLAY=":${display}"
DISPLAY_NUMBER="${DISPLAY/:/}"
PORT="590${DISPLAY_NUMBER}"
fi
}
display_intent () {
frobulator.fwd "Generating display${marker_elp}"
echo
if [[ "${display}" = [vV][nN][cC] ]]
then
# explicit VNC viewer application to kill:
# used when vnc is stopped or restarted using vnc:// intent
# when launched via the activity manager
# [ 'am start -d {URI} -S {ACTIVITY}' ]
# start android vnc intent and force-stop existing activity
# frobulator.silence "am start
# --user 0
# -a android.intent.action.VIEW
# -d vnc://${ADDRESS}:${PORT}
# -S ${display_activity}"
unset intent_command
intent_command+="am start"
intent_command+=" --user 0"
intent_command+=" -a android.intent.action.VIEW"
intent_command+=" -d vnc://${ADDRESS}:${PORT}"
frobulator.silence "${intent_command}"
fi
if [[ "${display}" = [xX][1][1] ]]
then
display_activity="${termux_x11_activity}"
# start termux:x11 intent
unset intent_command
intent_command+="am start"
intent_command+=" --user 0"
intent_command+=" -n ${display_activity}"
frobulator.silence "${intent_command}"
fi
}
display_view () {
frobulator.fwd "Opening display${marker_elp}"
echo
if [[ "${display}" = [vV][nN][cC] ]]
then
display_activity="${remotix_vnc_activity}"
unset intent_command
intent_command+="am start"
intent_command+=" --user 0"
intent_command+=" -a android.intent.action.VIEW"
intent_command+=" -d vnc://${ADDRESS}:${PORT}"
intent_command+=" -S ${display_activity}"
frobulator.silence "${intent_command}"
fi
if [[ "${display}" = [xX][1][1] ]]
then
display_activity="${termux_x11_activity}"