forked from SDRausty/TermuxPRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTermuxArch.sh
executable file
·1139 lines (1090 loc) · 46 KB
/
setupTermuxArch.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
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
#!/usr/bin/env bash
## Copyright 2017-2021 (c) by SDRausty, all rights reserved, see LICENSE
## hosting termuxarch.github.io/TermuxArch courtesy pages.github.com
## termuxarch.github.io/TermuxArch/CONTRIBUTORS thank you for your help!
################################################################################
set -Eeuo pipefail
shopt -s nullglob globstar
umask 0022
unset LD_PRELOAD
VERSIONID=2.0.451
_STRPERROR_() { # run on script error
local RV="$?"
printf "\\e[?25h\\n\\e[1;48;5;138m %s\\e[0m\\n" "TermuxArch WARNING: Generated script signal ${RV:-UNKNOWN} near or at line number ${1:-UNKNOWN} by '${2:-COMMAND}'!"
_ADERHELP_() {
printf "\\e[1;32mThe command 'bash %s help' has information how to use '%s' effectively.\\n" "${0##*/}" "${0##*/}"
}
[[ -z "${ARGS:-}" ]] && printf "\\e[1;32mPlease run 'bash %s' again or use 'bash %s refresh'.\\n\\e[1;32m\\n\\e[0m" "${0##*/}" "${0##*/}" && _ADERHELP_ || printf "\\e[1;32mPlease run 'bash %s' again or use 'bash %s refresh'.\\n\\e[1;32m\\n\\e[0m" "${0##*/} $ARGS" "${0##*/}" && _ADERHELP_
if [[ "$RV" = 4 ]]
then
printf "\\n\\e[1;48;5;139m %s\\e[0m\\n" "Please ensure background data is not restricted. Check the wireless connection."
fi
printf "\\n"
exit 201
}
_STRPEXIT_() { # run on exit
local RV="$?"
rm -rf "$TAMPDIR"
sleep 0.04
if [[ ! -z "${TAMATRIXENDLCR:-}" ]]
then
_TAMATRIXEND_
fi
if [[ "$RV" = 0 ]]
then
printf "\\e[0;32mCommand \\e[1;32m%s \\e[0;32mversion %s\\e[1;34m: \\e[1;32m%s\\e[0m\\n\\n" "'${0##*/} $ARGS'" "$VERSIONID" "DONE 🏁 "
printf "\\e]2; %s: %s \\007" "${0##*/} $ARGS" "DONE 🏁 "
else
printf "\\e[0;32m%s %s \\e[0m$VERSIONID\\e[1;34m: \\e[0;32m%s %s\\e[0m\\n\\n" "${0##*/}" "$ARGS" "[Exit Signal $RV]" "DONE 🏁 "
printf "\033]2; %s: %s %s \\007" "${0##*/} $ARGS" "[Exit Signal $RV]" "DONE 🏁 "
fi
printf "\\e[?25h\\e[0m"
set +Eeuo pipefail
exit
}
_STRPSIGNAL_() { # run on signal
printf "\\e[?25h\\e[1;7;38;5;0mTermuxArch WARNING: Signal %s received!\\e[0m\\n" "$?"
rm -rf "$TAMPDIR"
exit 211
}
_STRPQUIT_() { # run on quit
printf "\\e[?25h\\e[1;7;38;5;0mTermuxArch WARNING: Quit signal %s received!\\e[0m\\n" "$?"
exit 221
}
trap '_STRPERROR_ $LINENO $BASH_COMMAND $?' ERR
trap '_STRPEXIT_ $LINENO $BASH_COMMAND $?' EXIT
trap '_STRPSIGNAL_ $LINENO $BASH_COMMAND $?' HUP INT TERM
trap '_STRPQUIT_ $LINENO $BASH_COMMAND $?' QUIT
_ARG2DIR_() { # argument as ROOTDIR
ARG2="${@:2:1}"
if [[ -z "${ARG2:-}" ]]
then
ROOTDIR=/arch
_PREPTERMUXARCH_
else
ROOTDIR=/"$ARG2"
_PREPTERMUXARCH_
fi
}
_BLOOMSKEL_() {
ELCR=0
_INTROBLOOM_ "$@"
if [[ -d "$INSTALLDIR" ]] && [[ -d "$INSTALLDIR"/root/bin ]] && [[ -d "$INSTALLDIR"/var/binds ]] && [[ -f "$INSTALLDIR"/bin/we ]] && [[ -f "$INSTALLDIR"/usr/bin/env ]]
then
printf "\\n\\e[0;33m%s\\e[1;33m%s\\e[0;33m.\\e[0m\\n\\n" "TermuxArch WARNING! " "The root directory structure of ~/${INSTALLDIR##*/} is correct; Cannot continue '${0##*/} $ARGS' to create the directory skeleton! Commands '${0##*/} h[e[lp]]' and '$STARTBIN h[elp]' have more information"
else
_PREPTERMUXARCH_
_INTRO_ "$@" || exit 122
fi
}
_CHK_() {
if sha512sum -c termuxarchchecksum.sha512 1>/dev/null
then
if [[ -z "${INSTALLDIR:-}" ]] # is unset
then # exit here or the program will run on
printf "\\e[0;34m%s \\e[1;34m%s \\e[1;32m%s\\e[0m\\n" " 🕛 = 🕛" "TermuxArch $VERSIONID integrity:" "OK"
exit 123
else
printf "\\n\\e[0;34m%s \\e[1;34m%s \\e[1;32m%s\\e[0m\\n" " 🕛 > 🕜" "TermuxArch $VERSIONID integrity:" "OK"
_CHKSELF_
_COREFILESLOAD_
fi
else
printf "\\n"
_PRINTSHA512SYSCHKER_
fi
}
_CHKDWN_() {
sha512sum -c setupTermuxArch.sha512 1>/dev/null && printf "\\e[0;34m%s\\e[1;34m%s\\e[1;32m%s\\n\\n" " 🕛 > 🕐 " "TermuxArch download: " "OK" && bsdtar -x -p -f setupTermuxArch.tar.gz || _PRINTSHA512SYSCHKER_
}
_CHKSELF_() { # compare setupTermuxArch and file being used
cd "$WFDIR" # change directory to working file directory
if [[ "$(<$TAMPDIR/setupTermuxArch)" != "$(<${0##*/})" ]] # differ
then # update the working file to newest version
# update working file
cd "$WDIR"
cp "$TAMPDIR/setupTermuxArch" "$0"
[[ -z "${ARGS:-}" ]] && printf "\\n\\e[1;32mFile \\e[0;32m'%s'\\e[1;32m was UPDATED\\e[1;34m:\\e[0;32m run 'bash %s' again if this automatic update was unsuccessful.\\n\\e[1;32mRESTARTED \\e[0;32m'%s'\\e[1;34m:\\e[1;32m CONTINUING...\\n\\n\\e[0m" "${0##*/}" "${0##*/}" "${0##*/}" || printf "\\n\\e[1;32mFile \\e[0;32m'%s'\\e[1;32m was UPDATED\\e[1;34m:\\e[0;32m run 'bash %s' again if this automatic update was unsuccessful; You should be able to use the '!!' command to run '%s' again.\\n\\e[1;32mRESTARTED \\e[0;32m'%s'\\e[1;34m:\\e[1;32m CONTINUING...\\n\\n\\e[0m" "${0##*/}" "${0##*/} $ARGS" "${0##*/} $ARGS" "${0##*/} $ARGS"
# restart with updated version
. $0 $ARGS
fi
cd "$TAMPDIR"
}
_CHOOSEABI_(){
if [[ -z "$CPUABILIST64" ]]
then
ARCHITEC="i386"
CPUABI="x86"
else
ARCHITEC="x86_64"
CPUABI="x86_64"
fi
}
_CHOOSEABIx86_(){
CPUABILIST64="$(getprop ro.product.cpu.abilist64)"
CPUABI="$(getprop ro.product.cpu.abi)"
if [[ $CPUABI == *86* ]]
then
_OPT1_ "$@"
_INTRO_ "$@"
else
_CHOOSEABI_
_OPT1_ "$@"
_QEMU_
_INTRO_ "$@"
fi
}
_COREFILES_() {
[[ -f archlinuxconfig.bash ]] && [[ -f espritfunctions.bash ]] && [[ -f getimagefunctions.bash ]] && [[ -f knownconfigurations.bash ]] && [[ -f maintenanceroutines.bash ]] && [[ -f necessaryfunctions.bash ]] && [[ -f printoutstatements.bash ]] && [[ -f setupTermuxArch ]]
}
_COREFILESDO_() {
cd "$WFDIR" # change directory to working file directory
if _COREFILES_
then
_COREFILESLOAD_
else
cd "$TAMPDIR"
_DWNL_
_CHKDWN_
_CHK_ "$@"
fi
}
_COREFILESLOAD_() {
printf "\\e[?25l\\e[0m"
. archlinuxconfig.bash
. espritfunctions.bash
. getimagefunctions.bash
. knownconfigurations.bash
. maintenanceroutines.bash
. necessaryfunctions.bash
. printoutstatements.bash
if [[ "$OPT" = MANUAL ]]
then
_MANUAL_
fi
if [[ "$OPT" = BLOOM ]]
then
rm -f termuxarchchecksum.sha512
fi
}
_DEPENDDM_() { # check and set download manager
for PKG in "${!ADM[@]}"
do
if [[ -x $(command -v "${ADM[$PKG]}") ]]
then
DM="$PKG"
printf "\\nFound download tool '%s': Continuing...\\n" "$PKG"
break
fi
done
}
_DEPENDTM_() { # check and set tar manager: depreciated
for PKG in "${!ATM[@]}"
do
if [[ -x $(command -v "${ATM[$PKG]}") ]]
then
tm="$PKG"
printf "\\nFound tar tool '%s': Continuing...\\n" "$PKG"
break
fi
done
}
_DEPENDIFDM_() { # check if download tool is set and set install if available
for PKG in "${!ADM[@]}" # check from available toolset and set one for install if available
do # check for both set DM and if tool exists on device.
if [[ "$DM" = "$PKG" ]] && [[ ! -x $(command -v "${ADM[$PKG]}") ]]
then # sets both download tool for install and exception check.
APTIN+="$PKG "
printf "\\nSetting download tool '%s' for install: Continuing...\\n" "$PKG"
fi
done
}
_DEPENDS_() { # check for missing commands
if [[ -z "${VLORALCR:-}" ]]
then
PKGS=(bsdtar proot)
else
PKGS=(pulseaudio bsdtar proot)
fi
printf "\\e[1;34mChecking prerequisites...\\n\\e[1;32m"
ADM=([aria2]=aria2c [axel]=axel [curl]=curl [lftp]=lftpget [wget]=wget)
ATM=([bsdtar]=bsdtar)
if [[ "$DM" != "" ]]
then
_DEPENDIFDM_
fi
if [[ "$DM" = "" ]]
then
_DEPENDDM_
fi
# set and install lftp if nothing else was found
if [[ "$DM" = "" ]]
then
DM=lftp
APTIN+="lftp "
printf "Setting download tool 'lftp' for install: Continuing...\\n"
fi
for PKG in "${PKGS[@]}"
do # check for missing commands
COMMANDP="$(command -v "$PKG")" || printf "\\e[1;38;5;124mCommand %s not found: Continuing...\\e[0m\\n" "$PKG" # test if command exists
COMMANDPF="${COMMANDP##*/}"
if [[ "$COMMANDPF" != "$PKG" ]]
then
_INPKGS_
fi
done
printf "\\nUsing %s to manage downloads.\\n" "${DM:-lftp}"
printf "\\n\\e[0;34m 🕛 > 🕧 \\e[1;34mPrerequisites: \\e[1;32mOK \\e[1;34mDownloading TermuxArch...\\n\\n\\e[0;32m"
}
_DEPENDSBLOCK_() {
_DEPENDS_ || _PSGI1ESTRING_ "_DEPENDS_ _DEPENDSBLOCK_ ${0##*/}"
_COREFILESDO_
}
_DWNL_() { # download TermuxArch from Github
if [[ "$DFL" = "/gen" ]]
then # get development version from:
FILE[sha]="https://raw.githubusercontent.com/TermuxArch/gensTermuxArch/master/setupTermuxArch.sha512"
FILE[tar]="https://raw.githubusercontent.com/TermuxArch/gensTermuxArch/master/setupTermuxArch.tar.gz"
else # get stable version from:
FILE[sha]="https://raw.githubusercontent.com/TermuxArch/TermuxArch/master/setupTermuxArch.sha512"
FILE[tar]="https://raw.githubusercontent.com/TermuxArch/TermuxArch/master/setupTermuxArch.tar.gz"
fi
if [[ "$DM" = aria2 ]]
then # use https://github.com/aria2/aria2
"${ADM[aria2]}" -Z "${FILE[sha]}" "${FILE[tar]}"
elif [[ "$DM" = axel ]]
then # use https://github.com/mopp/Axel
"${ADM[axel]}" -a "${FILE[sha]}"
"${ADM[axel]}" -a "${FILE[tar]}"
elif [[ "$DM" = curl ]]
then # use https://github.com/curl/curl
"${ADM[curl]}" "$DMVERBOSE" -O {"${FILE[sha]},${FILE[tar]}"}
elif [[ "$DM" = wget ]]
then # use https://github.com/mirror/wget
_DOADMWGET_() {
"${ADM[wget]}" "$DMVERBOSE" -N --show-progress "${FILE[sha]}" "${FILE[tar]}"
}
_DOADMWGET_ || (au wget && "$PREFIX/bin/wget" "$DMVERBOSE" -N --show-progress "${FILE[sha]}" "${FILE[tar]}") || _PSGI1ESTRING_ "_DOADMWGET_ _DWNL_ ${0##*/}"
else # use https://github.com/lavv17/lftp
"${ADM[lftp]}" -c "${FILE[sha]}" "${FILE[tar]}"
fi
printf "\\n\\e[1;32m"
}
_EDITORCHOOSER_() {
if [[ -z "${EDITOR:-}" ]]
then
if command -v editor 1>/dev/null
then
USEREDIT="editor"
fi
elif [[ ! -z "${EDITOR:-}" ]]
then
USEREDIT="$EDITOR"
fi
if [[ -z "${EDITOR:-}" ]]
then
USEREDIT="nano"
fi
}
_INTRO_() {
printf "\033]2;%s\007" "bash ${0##*/} $ARGS 📲"
_SETROOT_EXCEPTION_
if [[ -d "$INSTALLDIR" ]] && [[ -d "$INSTALLDIR"/root/bin ]] && [[ -d "$INSTALLDIR"/var/binds ]] && [[ -f "$INSTALLDIR"/bin/we ]] && [[ -f "$INSTALLDIR"/usr/bin/env ]]
then
printf "\\n\\e[0;33m%s\\e[1;33m%s\\e[0;33m.\\e[0m\\n\\n" "TermuxArch WARNING! " "The root directory structure of ~/${INSTALLDIR##*/} is correct; Cannot continue '${0##*/} install' to install Arch Linux in Termux PRoot! Commands '${0##*/} h[e[lp]]' and '$STARTBIN h[elp]' have more information"
exit 205
fi
_PRINTINTRO_ "will attempt to install Linux in " "~/${INSTALLDIR##*/}" ". Arch Linux in Termux PRoot will be available upon successful completion"
_DEPENDSBLOCK_ "$@"
if [[ "$LCC" = "1" ]]
then
_LOADIMAGE_ "$@"
else
_MAINBLOCK_
fi
}
_INTROBLOOM_() { # BLOOM = setupTermuxArch manual verbose
OPT=BLOOM
printf "\033]2;%s\007" "bash ${0##*/} bloom 📲"
_PRINTINTRO_ "bloom option" "" ""
_PREPTERMUXARCH_
_DEPENDSBLOCK_ "$@"
_BLOOM_
}
_INPKGS_() { # install missing packages
STRNGB="\\e[1;38;5;146m%s\\e[0m\\n"
STRNGC="\\e[1;38;5;124m%s\\e[0m\\n"
if [[ "$COMMANDIF" = au ]] # enables rollback https://wae.github.io/au/
then # use 'au' to install missing packages
au "${PKGS[@]}" || printf ""$STRNGC "$STRING2"
elif [[ "$COMMANDIF" = pkg ]]
then # use 'pkg' to install missing packages
pkg install ${PKGS[@]} && printf "$STRNGB" "$STRING1" || printf "$STRNGC" "$STRING2"
elif [[ "$COMMANDIF" = apt ]]
then # use 'apt' to install missing packages
apt install "${PKGS[@]}" --yes && printf "$STRNGC" "$STRING1" || printf "$STRNGC" "$STRING2"
else
printf ""$STRNGC "$STRING1" && printf "$STRNGC" "$STRING2"
fi
}
_INTROSYSINFO_() {
printf "\033]2;%s\007" "bash ${0##*/} sysinfo 📲"
_SETROOT_EXCEPTION_
_PRINTINTRO_ "will create a system information file" "" ""
_DEPENDSBLOCK_ "$@"
_SYSINFO_ "$@"
}
_DODIRCHK_() {
_SETROOT_EXCEPTION_
if [[ ! -d "$INSTALLDIR" ]] || [[ ! -d "$INSTALLDIR/root/bin" ]] || [[ ! -d "$INSTALLDIR/var/binds" ]] || [[ ! -f "$INSTALLDIR/bin/we" ]] || [[ ! -f "$INSTALLDIR/usr/bin/env" ]]
then
printf "\\n\\e[0;33m%s\\e[1;33m%s\\e[0;33m.\\e[0m\\n\\n" "TermuxArch WARNING! " "The root directory structure is of ~/${INSTALLDIR##*/} is incorrect; Cannot continue '${0##*/} $ARGS'! These commands '${0##*/} help' and '$STARTBIN help' have more information"
if [[ -d "$INSTALLDIR"/tmp ]]
then # check for superfluous tmp directory
DIRCHECK=0
DIRNAME=(dev etc home opt proc root sys usr var)
for IDIRNAME in ${DIRNAME[@]}
do
if [[ ! -d "$INSTALLDIR/$IDIRNAME" ]]
then
DIRCHECK=1
else
DIRCHECK=0
fi
done
fi
if [[ -z "${DIRCHECK:-}" ]]
then
printf "‰s\\n" "Variable DIRCHECK is unbound."
elif [[ "$DIRCHECK" -eq 1 ]]
then # delete superfluous tmp dir
rm -rf "$INSTALLDIR"/tmp
rmdir "$INSTALLDIR" || _PSGI1ESTRING_ "rmdir INSTALLDIR _DODIRCHK_ ${0##*/}"
fi
exit 204
fi
_PRINTINTRO_ "will refresh your TermuxArch files in " "~/${INSTALLDIR##*/}" ". Arch Linux in Termux PRoot will be available upon successful completion"
}
_INTROREFRESH_() {
printf '\033]2; bash setupTermuxArch refresh 📲 \007'
_QEMUCFCK_
_DODIRCHK_
_DEPENDSBLOCK_ "$@"
_REFRESHSYS_ "$@"
}
_LOADCONF_() {
if [[ -f "${WDIR}setupTermuxArchConfigs.bash" ]]
then
. "${WDIR}setupTermuxArchConfigs.bash"
_PRINTCONFLOADED_
else
. knownconfigurations.bash
fi
}
_MANUAL_() {
printf '\033]2; bash setupTermuxArch manual 📲 \007'
if [[ -f "${WDIR}setupTermuxArchConfigs.bash" ]]
then
$USEREDIT "${WDIR}setupTermuxArchConfigs.bash"
_LOADCONF_
else
cp knownconfigurations.bash "${WDIR}setupTermuxArchConfigs.bash"
sed -i "7s/.*/\# The architecture of this device is $CPUABI; Adjust configurations in the appropriate section. Change CMIRROR (https:\/\/wiki.archlinux.org\/index.php\/Mirrors and https:\/\/archlinuxarm.org\/about\/mirrors) to desired geographic location to resolve 404 and checksum issues. /" "${WDIR}setupTermuxArchConfigs.bash"
$USEREDIT "${WDIR}setupTermuxArchConfigs.bash"
. "${WDIR}setupTermuxArchConfigs.bash"
_PRINTCONFLOADED_
fi
}
_NAMEINSTALLDIR_() {
if [[ "$ROOTDIR" = "" ]]
then
ROOTDIR=arch
fi
INSTALLDIR="$(printf "%s\\n" "$HOME/${ROOTDIR%/}" | sed 's#//*#/#g')"
}
_NAMESTARTARCH_() {
DARCH="$(printf "%s\\n" "${ROOTDIR%/}"|sed 's#//*#/#g')" # ${@%/} removes trailing slash
if [[ "$DARCH" = "/arch" ]]
then
AARCH=""
STARTBI2=arch
else
AARCH="$(printf "%s\\n" "$DARCH" | sed 's/\//\+/g')"
STARTBI2=arch
fi
STARTBIN=start"$STARTBI2$AARCH"
}
_OPT1_() {
if [[ -z "${2:-}" ]]
then
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
elif [[ "$2" = [Bb]* ]]
then
shift
printf "%s\\n" "Setting mode to bloom."
_INTROBLOOM_ "$@"
elif [[ "$2" = [Dd]* ]] || [[ "$2" = [Ss]* ]]
then
shift
printf "%s\\n" "Setting mode to sysinfo."
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
elif [[ "$2" = [Ii]* ]]
then
shift
printf "%s\\n" "Setting mode to install."
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
elif [[ "$2" = [Mm]* ]]
then
shift
printf "%s\\n" "Setting mode to manual."
OPT=MANUAL
_OPT2_ "$@"
elif [[ "${2//-}" = [Rr][Ee][Ff][Rr][Ee]* ]]
then
shift
_PRPREFRESH_ "5"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "${2//-}" = [Rr][Ee][Ff][Rr]* ]]
then
shift
_PRPREFRESH_ "4"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "${2//-}" = [Rr][Ee][Ff]* ]]
then
shift
_PRPREFRESH_ "3"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "$2" = [Rr][Ee]* ]]
then
shift
printf "\\n%s\\n" "Setting mode to minimal refresh and refresh user directories."
_PRPREFRESH_ "2"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "$2" = [Rr]* ]]
then
shift
printf "\\n\\e[1;32m%s\\e[1;34m: \\e[0;32m%s '%s' %s\\n\\e[0m" "Setting mode" "minimal refresh; You can use" "${0##*/} re[fresh]" "for full system refresh."
_PRPREFRESH_ "1"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
else
_OPT2_ "$@"
fi
}
_OPT2_() {
if [[ -z "${3:-}" ]]
then
shift
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
elif [[ "$3" = [Ii]* ]]
then
shift 2
printf "%s\\n" "Setting mode to install."
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTRO_ "$@"
elif [[ "${3//-}" = [Rr][Ee][Ff][Rr][Ee]* ]]
then
shift 2
_PRPREFRESH_ "5"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "${3//-}" = [Rr][Ee][Ff][Rr]* ]]
then
shift 2
_PRPREFRESH_ "4"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "${3//-}" = [Rr][Ee][Ff]* ]]
then
shift 2
_PRPREFRESH_ "3"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "$3" = [Rr][Ee]* ]]
then
shift 2
printf "\\n%s\\n" "Setting mode to minimal refresh and refresh user directories."
_PRPREFRESH_ "2"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
elif [[ "$3" = [Rr]* ]]
then
shift 2
printf "\\n\\e[1;32m%s\\e[1;34m: \\e[0;32m%s '%s' %s\\n\\e[0m" "Setting mode" "minimal refresh; Use" "${0##*/} re[fresh]" "for full system refresh."
_PRPREFRESH_ "1"
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
_INTROREFRESH_ "$@"
else
shift
_ARG2DIR_ "$@"
_PREPTERMUXARCH_
fi
}
_PREPTMPDIR_() {
[[ ! -d "$INSTALLDIR/tmp" ]] && mkdir -p "$INSTALLDIR/tmp" && chmod 777 "$INSTALLDIR/tmp" && chmod +t "$INSTALLDIR/tmp"
TAMPDIR="$INSTALLDIR/tmp/setupTermuxArch$$$RANDOM$PPID$SECONDS"
[[ ! -d "$TAMPDIR" ]] && mkdir -p "$TAMPDIR"
}
_PREPTERMUXARCH_() {
_NAMEINSTALLDIR_
_NAMESTARTARCH_
_PREPTMPDIR_ || _PSGI1ESTRING_ "_PREPTMPDIR_ _PREPTERMUXARCH_ ${0##*/}"
_EDITORCHOOSER_
}
_PRINTERRORMSG_() {
printf "\\e[1;31m%s\\e[1;37m%s\\e[1;32m%s\\e[1;37m%s\\n\\n" "Signal generated in '$1' : Cannot complete task : " "Continuing..."
printf "\\e[1;34m%s\\e[0;34m%s\\e[1;34m%s\\e[0m\\n\\n" " If you can improvements for " "${0##*} " "please open an issue and an accompanying pull request. A PR can assist in shedding more light on an issue."
}
_PRPREFRESH_() {
printf "\\n%s\\n" "Refresh mode is set to refresh mode $1; Initializing system refresh..."
LCR="$1"
}
_PRINTCONFLOADED_() {
printf "\\n\\e[0;34m%s \\e[1;34m%s \\e[0;32m%s\\e[1;32m%s \\e[1;34m%s \\e[1;32m%s\\n" " 🕛 > 🕑" "TermuxArch configuration" "$WDIR" "setupTermuxArchConfigs.bash" "loaded:" "OK"
}
_PRINTSHA512SYSCHKER_() {
printf "\\n\\e[07;1m\\e[31;1m\\n%s \\e[34;1m\\e[30;1m%s \\n\\e[0;0m\\n" " 🔆 WARNING sha512sum mismatch! Setup initialization mismatch!" " Try again, initialization was not successful this time. Wait a little while. Then run the command 'bash ${0##*/} $ARGS' again..."
printf '\033]2; Run %s again...\007' "bash ${0##*/} $ARGS"
exit 124
}
_PRINTSTARTBIN_USAGE_() {
_NAMESTARTARCH_
if [[ -x "$(command -v "$STARTBIN")" ]]
then
printf "\\e[1;38;5;155m\\n%s\\e[0m\\n" "$STARTBIN help"
"$STARTBIN" help
printf "\\n"
else
printf "\\n"
fi
}
_PRINTUSAGE_() {
printf "\\n\\e[1;32m %s \\e[0;32mcommands \\e[1;32m%s \\e[0;32m%s\\n" "HELP" "'${0##*/} he[lp]'" "show this help screen"
printf "\\n\\e[1;32m %s \\e[0;32mcommand \\e[1;32m%s \\e[0;32m%s\\n" "TERSE" "'${0##*/} he[lp]'" "shows the terse help screen"
printf "\\n\\e[1;32m %s \\e[0;32mcommand \\e[1;32m%s \\e[0;32m%s\\n" "VERBOSE" "'${0##*/} h'" "shows the verbose help screen"
printf "\\n\\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\n\\n%s \\e[1;32m%s\\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s\\e[0;32m%s\\n" "Usage information for" "${0##*/}" "$VERSIONID. Some arguments can be abbreviated to one, two and three letters each; Two and three letter arguments are acceptable. For example" "'bash ${0##*/} cs'" "will use" "'curl'" "to download TermuxArch and produce a file like" "'setupTermuxArchSysInfo$STIME.log'" "populated with system information. If you have a new smartphone that you are not familiar with, this file" "'setupTermuxArchSysInfo$STIME.log'" "might make for an interesting read in order to find out more about the device you might be holding in the palm of your hand right at this moment." "User configurable variables are in file" "'setupTermuxArchConfigs.bash'" ". To create this file from file" "knownconfigurations.bash" "in the working directory, execute" "'bash ${0##*/} manual'" "to create and edit file" "setupTermuxArchConfigs.bash" "."
printf "\\n\\e[1;32m %s\\e[0;32m %s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s\\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s\\n" "INSTALL" "You can run" "${0##*/}" "without arguments in a bash shell to install Arch Linux in Termux PRoot container in a smartphone, smartTV, table, wearable and more... Command" "'bash ${0##*/} curl'" "will envoke" "curl" "as the download manager. You can copy" "knownconfigurations.bash" "to" "setupTermuxArchConfigs.bash" "with the command" "'bash ${0##*/} manual'" "to edit your preferred CMIRROR site, refine the init statement and to access more options. Change CMIRROR to desired geographic location to resolve download, 404 and checksum issues should these occur. After editing" "setupTermuxArchConfigs.bash" ", you can run" "'bash ${0##*/}'" "and" "setupTermuxArchConfigs.bash" "loads automatically from the working directory. User configurable variables are present in this file for your convenience." " This link https://github.com/SDRausty/TermuxArch/issues/212 at GitHub has the most current information about setting Arch Linux in Termux PRoot as the default login shell in Termux in your smartphone, tablet, smartTV, wearable and more. If you choose to, or are simply curious about setting Arch Linux in Termux PRoot as the default login shell, please be well acquainted with safe mode; Long tapping on NEW SESSION will open a new session in safe mode. This mode can be used to reset the default shell."
printf "\\n\\e[1;32m %s \\e[0;32mcommand \\e[1;32m%s \\e[0;32m%s\\n" "PURGE" "'${0##*/} purge'" "uninstalls Arch Linux in PRoot from Termux"
printf "\\n\\e[1;32m %s \\e[0;32mcommand \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s \\e[0;32m%s \\e[1;32m%s\\e[0;32m%s\\e[1;32m%s\\e[0;32m%s\\n\\n" "SYSINFO" "'${0##*/} sysinfo'" "creates a system information file; A file like" "setupTermuxArchSysInfo$STIME.log" "will be populated with device and system information in the working directory. Please post information from this file along with details at" "https://github.com/TermuxArch/TermuxArch/issues" " if questions or comments are related to a particular device; Should screenshots help in resolving an issue, include these with information from this system information log file as well. If you are sharing an issue please consider creating a pull request at " "https://github.com/TermuxArch/TermuxArch/pulls" " also. A pull request can give a much better perspective of how an issue can be easily resolved."
if [[ "$LCC" = 1 ]]
then
printf "\\e[1;38;5;150m%s\\n\\n" "$(sed -n '600,1240p;1240p' "$0" | grep "^##" | sed 's/## /\n /g')"
printf "\\e[0;32m Command \\e[1;32m%s\\e[0;32m has \\e[1;32m%s\\e[0;32m usage information:\\n" "'$STARTBIN help'" "'$STARTBIN'"
_PRINTSTARTBIN_USAGE_
else
printf "\\e[0;32m Command \\e[1;32m%s\\e[0;32m has \\e[1;32m%s\\e[0;32m usage information.\\n\\n" "'$STARTBIN help'" "'$STARTBIN'"
fi
}
_PRINTINTRO_() {
printf "\\n\\e[0;34m 🕛 > 🕛 \\e[1;34mTermuxArch %s $1\\e[1;32m$2\\e[1;34m$3. You can use '!!' to run this BASH script again with options. Please check the wireless connection if you do not see one o'clock 🕐 below and ensure background data is not restricted. The command \\e[1;32mbash %s help \\e[1;34mhas additional information about \\e[1;32m%s\\e[1;34m. \\e[0;34m" "$VERSIONID" "${0##*/}" "${0##*/}"
}
_PSGI1ESTRING_() { # print signal generated in arg 1 format
printf "\\e[1;33mSIGNAL GENERATED in %s\\e[1;34m : \\e[1;32mCONTINUING... \\e[0;34mExecuting \\e[0;32m%s\\e[0;34m in the native shell once the installation and configuration process completes will attempt to finish the autoconfiguration and installation if the installation and configuration processes were not completely successful. Should better solutions for \\e[0;32m%s\\e[0;34m be found, please open an issue and accompanying pull request if possible.\\nThe entire script can be reviewed by creating a \\e[0;32m%s\\e[0;34m directory with the command \\e[0;32m%s\\e[0;34m which can be used to access the entire installation script. This option does NOT configure and install the root file system. This command transfers the entire script into the home directory for hacking, modification and review. The command \\e[0;32m%s\\e[0;34m has more information about how to use use \\e[0;32m%s\\e[0;34m in an effective way.\\e[0;32m%s\\e[0m\\n" "'$1'" "'bash ${0##*/} refresh'" "'${0##*/}'" "'~/TermuxArchBloom/'" "'setupTermuxArch b'" "'setupTermuxArch help'" "'${0##*/}'"
}
_QEMU_() {
_INST_() { # check for neccessary commands
COMMS="$1"
COMMANDR="$(command -v au)" || (printf "%s\\n\\n" "$STRING1")
COMMANDIF="${COMMANDR##*/}"
STRING1="COMMAND \`au\` enables rollback, available at https://wae.github.io/au/ IS NOT FOUND: Continuing... "
STRING2="Cannot update ~/${0##*/} prerequisite: Continuing..."
PKG="$2"
_INPKGS_() {
printf "%s\\n" "Beginning qemu '$ARCHITEC' setup:"
if [ "$COMMANDIF" = au ]
then
au "$PKG" || printf "%s\\n" "$STRING2"
else
apt install "$PKG" || printf "%s\\n" "$STRING2"
fi
}
if ! command -v "$COMMS"
then
_INPKGS_
fi
}
_QEMUCFCK_
if [[ -z "${ARCHITEC:-}" ]]
then
# user chooses qemu architecture to installed
printf "Command '%s' version %s; Setting install mode with QEMU emulation; Please select the architecture to install by number (1-5) from this list:\\n" "${0##*/}" "$VERSIONID"
select ARCHITECTURE in armeabi armeabi-v7a arm64-v8a x86 x86_64 exit;
do
CPUABI="$ARCHITECTURE"
if [[ "$ARCHITECTURE" == armeabi ]] || [[ "$ARCHITECTURE" == armeabi-v7a ]]
then
ARCHITEC="arm"
elif [[ "$ARCHITECTURE" == arm64-v8a ]]
then
ARCHITEC="aarch64"
elif [[ "$ARCHITECTURE" == x86 ]]
then
ARCHITEC="i386"
elif [[ "$ARCHITECTURE" == x86_64 ]]
then
ARCHITEC="x86_64"
elif [[ "$ARCHITECTURE" == exit ]]
then
exit
fi
[[ $CPUABI == *arm* ]] || [[ $CPUABI == *86* ]] && printf "%s\\n" "Option ($REPLY) with architecture $CPUABI ($ARCHITEC) was picked from this list; The chosen Arch Linux architecture for installation with emulation is $CPUABI ($ARCHITEC): " && INCOMM="qemu-user-$ARCHITEC" && QEMUCR=0 && break || printf "%s\\n" "Answer ($REPLY) was chosen; Please select the architecture by number from this list: (1) armeabi, (2) armeabi-v7a, (3) arm64-v8a, (4) x86, (5) x86_64 or choose option (6) exit to exit command '${0##*/}':"
done
else
INCOMM="qemu-user-$ARCHITEC" && QEMUCR=0
fi
if ! command -v "${INCOMM//-user}"
then
_INST_ "${INCOMM//-user}" "$INCOMM" "${0##*/}" || _PSGI1ESTRING_ "_INST_ _QEMU_ setupTermuxArch ${0##*/}"
fi
}
_QEMUCFCK_() {
if [[ -f "$INSTALLDIR/$STARTBIN" ]] && grep -q qemu- "$INSTALLDIR/$STARTBIN"
then # set installed qemu architecture
ARCHITEC="$(ARCTEVAR="$(grep -m1 qemu $INSTALLDIR/$STARTBIN)" && ARCTFVAR=${ARCTEVAR#*qemu-} && cut -d" " -f1 <<< $ARCTFVAR)" && CPUABI="$ARCHITEC" && INCOMM="qemu-user-$ARCHITEC" && QEMUCR=0
printf "Detected architecture is %s; Install architecture is set to %s.\\n" "$(getprop ro.product.cpu.abi)" "$ARCHITEC"
fi
}
_RMARCHQ_() {
printf "\\n\\e[0;33m %s \\e[1;33m%s \\e[0;33m%s\\n\\n\\e[1;30m%s\\n" "TermuxArch:" "DIRECTORY WARNING! ~/${INSTALLDIR##*/}/" "directory detected." "Purge '$INSTALLDIR' as requested?"
if [[ -z "${PURGELCR:-}" ]]
then
PURGEMETHOD="quick "
else
PURGEMETHOD=""
fi
printf "\\e[1;30m"
while true; do
read -n 1 -p "Uninstall '~/${INSTALLDIR##*/}/' with ${PURGEMETHOD}purge? [Y|n] " RUANSWER
if [[ "$RUANSWER" = [Ee]* ]] || [[ "$RUANSWER" = [Nn]* ]] || [[ "$RUANSWER" = [Qq]* ]]
then
printf "\\n%s\\n" "No was answered: uninstalling '~/${INSTALLDIR##*/}/': nothing to do for '~/${INSTALLDIR##*/}/'."
break
elif [[ "$RUANSWER" = [Yy]* ]] || [[ "$RUANSWER" = "" ]]
then
printf "\\e[30m%s\\n" "Uninstalling '~/${INSTALLDIR##*/}/'..."
if grep -q ^pacmd "$PREFIX/etc/profile" && grep -q ^pulseaudio "$PREFIX/etc/profile"
then
awk '!/^pulseaudio/' "$PREFIX/etc/profile" > "$TAMPDIR/profile$FTIME"
awk '!/^pacmd/' "$TAMPDIR/profile$FTIME" > "$PREFIX/etc/profile"
fi
if [[ -d "$INSTALLDIR" ]]
then
_RMARCHRM_
else
printf "%s\\n" "Uninstalling '~/${INSTALLDIR##*/}/': nothing to do for '~/${INSTALLDIR##*/}/'."
fi
if [[ -e "$PREFIX/bin/$STARTBIN" ]]
then
rm -f "$PREFIX/bin/$STARTBIN"
else
printf "%s\\n" "Uninstalling '$PREFIX/bin/$STARTBIN': nothing to do for '$PREFIX/bin/$STARTBIN'."
fi
if [[ -e "$HOME/bin/$STARTBIN" ]]
then
rm -f "$HOME/bin/$STARTBIN"
else
printf "%s\\n" "Uninstalling '$HOME/bin/$STARTBIN': nothing to do for '$HOME/bin/$STARTBIN'."
fi
printf "%s \\e[1;32mDONE\\e[30m\\n\\n" "Uninstalling '~/${INSTALLDIR##*/}/':"
break
else
printf "\\nYou answered \\e[33;1m%s\\e[30m.\\n\\nAnswer \\e[32mYes\\e[30m or \\e[1;31mNo\\e[30m. [\\e[32my\\e[30m|\\e[1;31mn\\e[30m]\\n" "$RUANSWER"
fi
done
}
_RMARCHRM_() {
_RMARCHCRRM_() { # remove installation
chmod -R 777 "$INSTALLDIR" || _PSGI1ESTRING_ "chmod -R 777 INSTALLDIR _RMARCHRM_ ${0##*/}"
find "$INSTALLDIR" -type l -delete || _PSGI1ESTRING_ "find INSTALLDIR _RMARCHRM_ ${0##*/}"
rm -rf "$INSTALLDIR" || _PSGI1ESTRING_ "rm -rf INSTALLDIR _RMARCHRM_ ${0##*/}"
}
_DOEXONSTGE_() { # remove empty storage directories
printf "\\e[0;35m"
for EXONSTGEM in ${EXONSTGE[@]:-}
do
find "$EXONSTGEM" -type l -delete && rmdir "$EXONSTGEM" || (printf "\\e[1;31m%s\\e[1;35m%s\\n" "Exit signal recieved:" " attempting to 'rmdir $EXONSTGEM' exception; Please remove directory $EXONSTGEM manually; Exiting..." && exit 206)
done
printf "\\e[1;30m"
}
_SETROOT_EXCEPTION_
declare -a EXONSTGE
EXONSTGE=("$(find "$INSTALLDIR" -name storage -type d || printf "")")
if [[ ! -z "${EXONSTGE:-}" ]]
then
chmod 777 $EXONSTGE
fi
if [[ ! -z "${EXONSTGE:-}" ]]
then
_DOEXONSTGE_
fi
_RMARCHCRRM_
}
_SETROOT_EXCEPTION_() {
if [[ "$INSTALLDIR" = "$HOME" ]] || [[ "$INSTALLDIR" = "$HOME"/ ]] || [[ "$INSTALLDIR" = "$HOME"/.. ]] || [[ "$INSTALLDIR" = "$HOME"/../ ]] || [[ "$INSTALLDIR" = "$HOME"/../.. ]] || [[ "$INSTALLDIR" = "$HOME"/../../ ]]
then
printf '\033]2;%s\007' "Rootdir exception. Run bash ${0##*/} $ARGS again with different options..."
printf "\\n\\e[1;31m%s\\n\\n\\e[0m" "Rootdir exception. Run the script $ARGS again with different options..."
exit 125
fi
}
_TAMATRIXEXIT_() { # run when Matrix presentation ends
if [[ ! -z "${TAMATRIXENDLCR:-}" ]]
then
_TAMATRIXEND_
fi
}
## USER INFORMATION: Configurable variables such as mirrors and download manager options are in 'setupTermuxArchConfigs.bash'. Working with 'knownconfigurations.bash' in the working directory is simple. The command 'bash setupTermuxArch manual' will create 'setupTermuxArchConfigs.bash' in the working directory for editing; The command 'setupTermuxArch help' has more information.
declare -A ADM # declare associative array for download tools
declare -A ATM # declare associative array for tar tools
declare -A FILE # declare associative array
declare -a ECLAVARR # declare array for arrays and variables
declare -a QEMUUSER # declare array for qemu user tools
declare -a PRFXTOLS # declare array for device tools that should be accessible in the PRoot environment
declare -A EMPARIAS # declare associative array for empty variables
EMPARIAS=([APTIN]="# apt install string" [COMMANDIF]="" [COMMANDG]="" [CPUABI]="" [DFL]="# used for development" [DM]="" [USEREDIT]="" [FSTND]="" [INSTALLDIR]="" [LCC]="" [LCP]="" [OPT]="" [QEMUCR]="" [ROOTDIR]="" [WDIR]="" [SDATE]="" [STI]="# generates pseudo random number" [STIME]="# generates pseudo random number")
# set empty variables
for PKG in ${!EMPARIAS[@]} ; do declare "$PKG"="" ; done
declare -a LC_TYPE # declare array for locale types
ECLAVARR=(ARGS APTIN BINFNSTP COMMANDIF COMMANDR COMMANDG CPUABI CPUABI5 CPUABI7 CPUABI8 CPUABIX86 CPUABIX86_64 DFL DMVERBOSE DM EDO01LCR ELCR USEREDIT FSTND INSTALLDIR LCC LCP LCR OPT ROOTDIR WDIR SDATE STI STIME STRING1 STRING2)
for ECLAVARS in ${ECLAVARR[@]} ; do declare $ECLAVARS ; done
ARGS="${@%/}"
CPUABI5="armeabi" # used for development; 'getprop ro.product.cpu.abi' ascertains architecture
CPUABI7="armeabi-v7a" # used for development
CPUABI8="arm64-v8a" # used for development
CPUABIX86="x86" # used for development
CPUABIX86_64="x86_64" # used for development
DMVERBOSE="-q" # -v for verbose download manager output from curl and wget; for verbose output throughout runtime also change in 'setupTermuxArchConfigs.bash' when using 'setupTermuxArch m[anual]'
ELCR=1
[[ -z "${TAMPDIR:-}" ]] && TAMPDIR=""
ROOTDIR="/arch"
STRING1="COMMAND 'au' enables auto upgrade and rollback. Available at https://wae.github.io/au/ IS NOT FOUND: Continuing... "
STRING2="Cannot update '${0##*/}' prerequisite: Continuing..."
## TERMUXARCH FEATURES INCLUDE:
## 1) Create aliases and commands that aid in using the command line, and assist in accessing the more advanced features like the commands 'pikaur' and 'yay' easily; The files '.bashrc' '.bash_profile' and 'bin/README.md' have detailed information about this feature,
## 2) Set timezone and locales from device,
## 3) Test for correct OS,
_COMMANDGNE_() { printf "\\n\\e[1;48;5;138m%s\\e[0m\\n\\n" "TermuxArch WARNING: Run '${0##*/}' and 'bash ${0##*/}' from the native BASH shell in Termux: EXITING..." && exit 126 ; }
COMMANDG="$(command -v getprop)" || _COMMANDGNE_
_IFBINEXT_() {
if [ -d "$HOME/bin" ] && grep "$HOME/bin" <<< "$PATH"
then
curl -L "https://raw.githubusercontent.com/WAE/au/master/$SCMD" -o "$HOME/bin/$SCMD" && chmod 700 "$HOME/bin/$SCMD" || _PSGI1ESTRING_ "curl au to HOME/bin setupTermuxArch ${0##*/}"
else
curl -L "https://raw.githubusercontent.com/WAE/au/master/$SCMD" -o "$PREFIX/bin/$SCMD" && chmod 700 "$PREFIX/bin/$SCMD" || _PSGI1ESTRING_ "curl au to PREFIX/bin setupTermuxArch ${0##*/}"
fi
}
SCMD="au"
if ! command -v "$SCMD" > /dev/null
then
printf "\\e[1;38;5;124mCommand \\e[1;38;5;148m%s\\e[1;38;5;124m not found: \\e[1;38;5;150mContinuing...\\n" "'$SCMD'" ; _IFBINEXT_ ; printf "\\e[0m"
fi
COMMANDR="$(command -v au)" || COMMANDR="$(command -v pkg)" || COMMANDR="$(command -v apt)"
COMMANDIF="${COMMANDR##*/}"
## 4) Generate pseudo random number to create uniq strings,
SDATE="$(date +%s)" || SDATE="$(shuf -i 0-99999999 -n 1)" || _PSGI1ESTRING_ "SDATE setupTermuxArch ${0##*/}"
if [[ -r /proc/sys/kernel/random/uuid ]]
then
STIME="$(cat /proc/sys/kernel/random/uuid)" && STIME="${STIME//-}" && STIME="${STIME//[[:alpha:]]}" && STIME="${STIME:0:3}"
else
STIME="$SDATE" && STIME="$(rev <<< "${STIME:7:4}")"
fi
ONESA="${SDATE: -1}"
FTIME="$(date +%F%H%M%S)"
STIME="$ONESA$STIME"
## 5) Get device information via the 'getprop' command,
## 6) Determine its own name and location of invocation,
WDIR="$PWD/" && WFDIR="$(realpath "$0")" || _PSGI1ESTRING_ "please try using an absolute PATH or prepending your PATH to file '${0##*/}' with a tilda ~ for file '$0'."
WFDIR="${WFDIR%/*}"
## 7) Create a default Arch Linux in Termux PRoot user account with the TermuxArch command 'addauser' which configures user accounts for use with the Arch Linux 'sudo' command,
## 8) Install alternate architectures with QEMU in your smartphone with two taps,
## 9) Make the Arch Linux aur installer 'yay' with TermuxArch command 'makeyay',
## 10) All options are optional for install!
## >>>>>>>>>>>>>>>>>>
## >> HELP OPTIONS >>
## >>>>>>>>>>>>>>>>>>
## Please open an issue and accompanying pull request at GitHub if you would like to have these options amended.
## [] Run default Arch Linux install.
if [[ -z "${1:-}" ]]
then
_PREPTERMUXARCH_
_INTRO_ "$@"
## [./path/systemimage.tar.gz [customdir]] Install directory argument is optional. Network install can be substituted by copying systemimage.tar.gz and systemimage.tar.gz.md5 files with 'setupTermuxArch ./[path/]systemimage.tar.gz' and 'setupTermuxArch /absolutepath/systemimage.tar.gz'. Both '*.tar.gz' and '*.tar.gz.md5' files are required for this process to complete successfully. Installation for many versions of Linux that publish a root file sysytem is supported with this TermuxArch festure. Download and configuration is not presently implemented, and hopefully will be in the future. Create an issue and pull request at GitHub to implement these features.
elif [[ "${ARGS:0:1}" = . ]]
then
printf "\\n%s\\n" "Setting mode to copy system image."
GFILE="$1"
LCC="1"
LCP="1"
_OPT1_ "$@"
_PREPTERMUXARCH_
_INTRO_ "$@"
## [systemimage.tar.gz [customdir]] Install directory argument is optional. Network install can be substituted by copying systemimage.tar.gz and systemimage.tar.gz.md5 files with 'setupTermuxArch systemimage.tar.gz'. Both '*.tar.gz' and '*.tar.gz.md5' files are required for this process to complete successfully. Installation for many versions of Linux that publish a root file sysytem is supported with this TermuxArch festure. Download and configuration is not presently implemented, and hopefully will be in the future. Create an issue and pull request at GitHub to implement these features.
elif [[ "$ARGS" = *.tar.gz* ]]
then
printf "\\n%s\\n" "Setting mode to copy system image."
GFILE="$1"
LCC="1"
LCP="0"
_OPT1_ "$@"
_PREPTERMUXARCH_
_INTRO_ "$@"
## [axd|axs] Get device system information with 'axel'.
elif [[ "${1//-}" = [Aa][Xx][Dd]* ]] || [[ "${1//-}" = [Aa][Xx][Ss]* ]]
then
printf "\\nGetting device system information with 'axel'.\\n"
DM=axel
shift
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
## [ax[el] [customdir]|axi [customdir]] Install Arch Linux with 'axel'.
elif [[ "${1//-}" = [Aa][Xx]* ]] || [[ "${1//-}" = [Aa][Xx][Ii]* ]]
then
printf "\\nSetting 'axel' as download manager.\\n"
DM=axel
_OPT1_ "$@"
_INTRO_ "$@"
## [ad|as] Get device system information with 'aria2c'.
elif [[ "${1//-}" = [Aa][Dd]* ]] || [[ "${1//-}" = [Aa][Ss]* ]]
then
printf "\\nGetting device system information with 'aria2c'.\\n"
DM=aria2
shift
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
## [a[ria2c] [customdir]|ai [customdir]] Install Arch Linux with 'aria2c'.
elif [[ "${1//-}" = [Aa]* ]]
then
printf "\\nSetting 'aria2c' as download manager.\\n"
DM=aria2
_OPT1_ "$@"
_INTRO_ "$@"
## [bl[oom]] Create a local copy of TermuxArch in TermuxArchBloom and create the TermuxArch root tree skeleton and skeleton files. Useful for running a customized setupTermuxArch locally and for developing and hacking TermuxArch. This command only installs TermuxArch components. It does NOT install the root file system.
elif [[ "${1//-}" = [Bb][Ll]* ]]
then
printf "\\nSetting mode to bloom. \\n"
_BLOOMSKEL_
## [b[loom]] Create a local copy of TermuxArch in TermuxArchBloom. Useful for running a customized setupTermuxArch locally and for developing and hacking TermuxArch.
elif [[ "${1//-}" = [Bb]* ]]
then
printf "\\nSetting mode to bloom. \\n"
_INTROBLOOM_ "$@"
## [cd|cs] Get device system information with 'curl'.
elif [[ "${1//-}" = [Cc][Dd]* ]] || [[ "${1//-}" = [Cc][Ss]* ]]
then
printf "\\nGetting device system information with 'curl'.\\n"
DM=curl
shift
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
## [c[url] [customdir]|ci [customdir]] Install Arch Linux with 'curl'.
elif [[ "${1//-}" = [Cc][Ii]* ]] || [[ "${1//-}" = [Cc]* ]]
then
printf "\\nSetting 'curl' as download manager.\\n"
DM=curl
_OPT1_ "$@"
_INTRO_ "$@"
## [d[ebug]|s[ysinfo]] Generate system information.
elif [[ "${1//-}" = [Dd]* ]] || [[ "${1//-}" = [Ss]* ]]
then
printf "\\nSetting mode to sysinfo.\\n"
shift
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
## [he[lp] [customdir]] Display terse builtin help.
elif [[ "${1//-}" = [Hh][Ee]* ]]
then
_ARG2DIR_ "$@"
_PRINTUSAGE_ "$@"
## [h [customdir]] Display verbose builtin help.
elif [[ "${1//-}" = [Hh]* ]]
then
LCC="1"
_ARG2DIR_ "$@"
_PRINTUSAGE_ "$@"
## [i[nstall] [customdir]] Install Arch Linux in a custom directory. Instructions: Install in userspace. The HOME directory is appended to the installation directory. To install Arch Linux in HOME/customdir use 'bash setupTermuxArch install customdir'. In the BASH shell you can use './setupTermuxArch install customdir'. All options can be abbreviated to one, two and three letters. Hence './setupTermuxArch install customdir' can be run as './setupTermuxArch i customdir' in BASH.
elif [[ "${1//-}" = [Ii]* ]]
then
printf "\\nSetting mode to install.\\n"
_ARG2DIR_ "$@"
_INTRO_ "$@"
## [ld|ls] Get device system information with 'lftp'.
elif [[ "${1//-}" = [Ll][Dd]* ]] || [[ "${1//-}" = [Ll][Ss]* ]]
then
printf "\\nGetting device system information with 'lftp'.\\n"
DM=lftp
shift
_ARG2DIR_ "$@"
_INTROSYSINFO_ "$@"
## [l[ftp] [customdir]] Install Arch Linux with 'lftp'.
elif [[ "${1//-}" = [Ll]* ]]
then
printf "\\nSetting 'lftp' as download manager.\\n"
DM=lftp
_OPT1_ "$@"
_INTRO_ "$@"
## [matr[ix]] Print TermuxArch source code as Matrix loop
elif [[ "${1//-}" = [Mm][Aa][Tt][Rr]* ]]
then
printf "\\nSetting mode to matrix loop.\\n"
MATRIXLCR=0
_PREPTERMUXARCH_
_DEPENDSBLOCK_ "$@"
_TAMATRIX_