-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveUsb1.sh
executable file
·3251 lines (2606 loc) · 103 KB
/
LiveUsb1.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
#!/bin/bash
## LiveUsb1
## #!/bin/env -iS bash
## Note, Putting a `LN="$nL"` (LINENO) or `main_lineno="$nL"` assignment preceding an `exit` command lets
#+ the value of LN or main_lineno match the line number of the `exit` command.
## Note, idempotent script
## Note, the symbol "<>" marks code as for deburging purpoeses only
## Note, ...undocumented feature??
#+ Use `env -i` or else the script\s execution environment will inherit any exported anything,
#+ including and especially functions, from its caller, e.g., any locally defined functions (such as `rm`)
#+ which might be intended to shadow any builtins or commands or to supplant any of the aliases which some
#+ of the various Linux distributions often define and provide for users\ convenience. These exported
#+ functions which are received from the caller\s environment get printed above the script\s shebang in
#+ xtrace when xtrace and vebose are both enabled on the shebang line. ...but exported variables do not
#+ print.
#+ ...also, using `env` messes up vim\s default bash-colorizations
## Note, style, function definition syntax, "(){ :" makes plain xtrace easier to read
## Note, style, "! [[ -e" doesn\t show the "!" in xtrace, whereas "[[ ! -e" does, and yet, for `grep`.....
## Note, timestamps, `find`, `stat` and `[[` (and `ls`) don\t effect ext4 timestamps, as tested, but
#+ idempotent `chown` and `chmod` do, and of course `touch` does; if there\s no change in the file,
#+ `rsync` doesn\t, but if the file changes, it does. Also, "btime" on ext4 still isn\t consistent.
#+ `grep` has no effect on times; `cp -a` effects "ctimes" even if file contents do not change.
## Reportable burg. `command -p kill "$AA"` executes the bash builtin, judging by the output of `command
#+ -p kill` without any operands. The output of `$( type -P kill )"` without operands is the same as the
#+ output of /usr/bin/kill without operands. The documentation is ...somewhat unclear on these points.
#+ `help command`: "Runs COMMAND with ARGS suppressing shell function lookup...." It seems that what
#+ is intended is, "...suppressing shell function lookup, but still allowing builtins to be executed,"
#+ and possibly also aliases and keywords, though I haven\t tested those. The description of the "-p"
#+ option is particularly misleading: "use a default value for PATH that is guaranteed to find all of
#+ the standard utilities." That "guarantee" sounds as if use of the "-p" option "shall" (using the
#+ POSIX defition of the word) result in a binary utility being used, when actually that is not the
#+ case.
#+ Binary `kill` has a few options not available with the builtin, such as "--timeout", which can be
#+ used to avoid writing an extra for loop...
#+
#+ sudo -- "$( type -P kill )" --verbose \
#+ --timeout 1000 HUP \
#+ --timeout 1000 USR1 \
#+ --timeout 1000 TERM \
#+ --timeout 1000 KILL -- "$WW"
#+
#+ Otherwise, it would be useful, IMO, if `kill --help` showed the help file for /bin/kill, since
#+ using that syntax most likely indicates that intention :-\
## TODO, lock file, bc ^z
## TODO, add colors to xtrace comments
## TODO, systemd services to disable, bluetooth, cups, [ systemd-resolved ? ]
## TODO, systemd services to possibly enable, sshd, sssd
## Start the script
function start_script(){
#__function_boundary_in__
#__enable_local_xtrace__
## Get & print script start time
script_start_time=$( date +%H:%M:%S )
readonly script_start_time
## Print script start time
printf '%s - Executing %s \n' "${script_start_time}" "$0"
## Set up non-deburg shell options
hash -r
shopt -s expand_aliases
umask 077
#__function_boundary_out_0__
}
start_script
# <>
#exit $LINENO
#set -x
function setup_aliases(){
: "${C_Comment} Line ${nL}, Aliases, non-deburg ${C_AttrOff}"
local -gnx nL=L\INENO
: "${C_CmntSub} Line ${nL}, Aliases TOC, non-deburg ${C_AttrOff}"
## Alias name
#+ ~~~~~~~~~~
#+ __die__
: "${C_CmntSub} Define alias __die__ onto function error_and_exit() ${C_AttrOff}"
als_di__def_lineno="$((nL+1))"
alias __die__='
: "${C_AlsFnBndry}" Line ${nL}, alias __die__, begin, def Line ${als_di__def_lineno}
error_and_exit "${nL}"
: "${C_AlsFnBndry}" Line ${nL}, alias __die__, end "${C_AttrOff}"'
}
setup_aliases
# <>
#exit "$LINENO"
#set -x
## <> Enable debugging (ie, "deburging")
function enable_deburg_params(){
## Set up deburg shell options
local -
#builtin set -x
: "$( tput setaf 12 ) Deburging $( tput sgr0 )"
# shellcheck disable=SC1001
## <> Note, this assignment is repeated here; originally it\s located in setup_vars()
local -gnx nL=L\INENO
# shellcheck disable=SC2218
{
set -a # <> All export
set -C # <> No clobber
set -u # <> No unset
set -T # <> Trace
set -e # <> Err + exit
set -o pipefail # <>
}
# <>
#exit "$LINENO"
#set -x
## Set up deburg colors
[[ -o xtrace ]] &&
: "$( tput setaf 12 ) Set up colors for xtrace comments $( tput sgr0 )"
C_AttrOff="$( tput sgr0 )"
readonly C_AttrOff
unset II aa_colors
declare -A aa_colors
## Array nm ## Var sub-name ## Digit Color ## Execution of code regarding...
#################################################################################################
aa_colors+=( ["Comment"]=" 12 blue" ## Explanatory comments, per major sections
["CmntSub"]=" 10 light_green" ## Explanatory comments, per-subsection
["CmntSubSub"]=" 226 yellow" ## Explanatory comments, per-sub-subsection
["AlsFnBndry"]=" 14 light_blue" ## Aliases at function boundaries
["FnBndry"]=" 11 orange" ## Function boundary lines in xtrace
["XtrAls"]=" 3 brown" ## Aliases in xtrace
["TechCmnt"]=" 4 purple" ## Technical comments
["Errors"]=" 8 brick_red" ) ## Errors
for II in "${!aa_colors[@]}"
do
# <>
#declare -p II # <>
#echo 'II:' "$II" 'aa_colors[$II]:' "${aa_colors[$II]}" # <>
unset -n NN
declare -n NN="C_${II}"
unset DD
DD="$( awk '{ print $1 }' <<< "${aa_colors[$II]}" )"
# <>
#declare -p DD # <>
#declare -p NN
# shellcheck disable=SC2034
printf -v NN '%b' "$( tput setaf "${DD}" )"
readonly C_"${II}"
tput sgr0
# <>
#exit $nL
#unset TT; TT="$( awk '{ print $2 }' <<< "${aa_colors[$II]}" )"; printf '%b %d \t %s \t %s %b\n' "${NN}" "${DD}" "${II}" "${TT}" "${C_AttrOff}"
done
unset -n NN
unset II DD aa_colors
# <>
#readonly
#declare -p C_AlsFnBndry C_Comment C_Errors C_CmntSub C_CmntSubSub C_TechCmnt C_FnBndry C_XtrAls C_AttrOff
#exit "$LINENO"
#set -x
: "${C_Comment} Variables, Function boundary parameters ${C_AttrOff}"
#fn_bndry_sh="${C_FnBndry} ~~~ ~~~ ~~~ ${C_AttrOff}"
#fn_bndry_lo="${C_FnBndry} ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ${C_AttrOff}"
fn_bndry_sh=" ~~~ ~~~ ~~~ "
fn_bndry_lo=" ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ "
readonly fn_bndry_sh fn_bndry_lo
fn_lvl=0
#print_function_boundaries=do_prFnBndrys
}
enable_deburg_params
# <>
#exit "$LINENO"
#set -x
function enable_deburg_aliases(){
: "${C_Comment} Line ${nL}, Aliases, deburg ${C_AttrOff}"
## Bug, separate alias definitions to a subsection above function definitions. Defining of alias B can
#+ occur before the defining of function A which is contained within in (alias B)
: "${C_CmntSub} Line ${nL}, Aliases, deburg - TOC ${C_AttrOff}"
## Alias name
#+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#+ __call_fn__
#+ __debug_break__
#+ __enable_local_xtrace__
#+ __enable_global_xtrace__
#+ __function_boundary_in__
#+ __function_boundary_out_0__
#+ __function_boundary_out_1__
#+ __pause2ck__
#+ __xtr_read_and_on__
#+ __xtr_restore__
## Note, as I recall, these variable assignments all need to be on the first line of this array
: "${C_CmntSub} Define alias __call_fn__ ${C_AttrOff}"
## Note, Usage: -|__call_fn__ \
#+ -|[function name]
#+ Reason: so that the alias can be added to a script via sed/awk.
als_cl_fn__def_lineno="$((nL+1))"
alias __call_fn__='_="${C_XtrAls} alias __call_fn__, begin" als_cl_fn__call_line="$nL" als_def_line="${als_cl_fn__def_lineno}" _="alias __call_fn__, end ${C_AttrOff}" '
: "${C_CmntSub} Define alias __debug_break__ ${C_AttrOff}"
## Note, this alias is in intended to function as a
als_dbg_brk__def_lineno="$((nL+1))"
alias __debug_break__='
: "${C_XtrAls}" Line ${nL}, alias __debug_break__, begin, def Line ${als_dbg_brk__def_lineno}
: If xtrace is already enabled, then disable xtrace and exit the script
if [[ -o xtrace ]]
then
builtin set -
EC=101
main_lineno="${nL}" exit
else
printf "%b\n" "${C_XtrAls} Line ${nL}, alias __debug_break__, begin, def Line ${als_dbg_brk__def_lineno}"
__enable_global_xtrace__
fi
: "${C_XtrAls}" Line ${nL}, alias __debug_break__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __enable_global_xtrace__ ${C_AttrOff}"
## Note, this alias is in intended to function as a
als_enbl_glbl_xtr__def_lineno="$((nL+1))"
alias __enable_global_xtrace__='
: "${C_XtrAls}" Line ${nL}, alias __enable_global_xtrace__, begin, def Line ${als_enbl_glbl_xtr__def_lineno}
: If xtrace is already enabled, then exit the script
if ! [[ -o xtrace ]]
then
printf "%b\n" "${C_XtrAls} Line ${nL}, alias __enable_global_xtrace__, begin, def Line ${als_enbl_glbl_xtr__def_lineno}"
print_function_boundaries=do_prFnBndrys
export print_function_boundaries
printf "%b Line %d, Enabling global xtrace %b\n" "${C_TechCmnt}" "${nL}" "${C_AttrOff}"
builtin set -x
fi
: "${C_XtrAls}" Line ${nL}, alias __enable_global_xtrace__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __enable_local_xtrace__ ${C_AttrOff}"
als_enbl_loc_xtr__def_lineno="$((nL+1))"
alias __enable_local_xtrace__='
: "${C_XtrAls}" Line ${nL}, alias __enable_local_xtrace__, begin, def Line ${als_enbl_loc_xtr__def_lineno}
if ! [[ -o xtrace ]]
then
local -Ig print_function_boundaries=do_prFnBndrys
export print_function_boundaries
printf "%b Enabling function-local xtrace %b\n" "${C_TechCmnt}" "${C_AttrOff}"
local -
builtin set -x
: "${C_XtrAls}" Line ${nL}, alias __enable_local_xtrace__, begin, def Line ${als_enbl_loc_xtr__def_lineno}, end
: "${C_XtrAls}" Line $fn_def_lineno, function definition: "${FUNCNAME[0]}()"
: fn_lvl: ${fn_lvl}
: local_hyphn: $local_hyphn
: prev_cmd_exit_code: $prev_cmd_exit_code
fi
: "${C_XtrAls}" Line ${nL}, alias __enable_local_xtrace__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __function_boundary_in__ ${C_AttrOff}"
## Note, s\b all one line
# shellcheck disable=SC2142
als_fn_bdry_in__def_lineno="$((nL+1))"
alias __function_boundary_in__='
_="${C_FnBndry} ${fn_bndry_lo} function ${FUNCNAME[0]}() BEGINS ${fn_bndry_sh} ${fn_lvl} to $(( ++fn_lvl )) ${C_AlsFnBndry}"
_="${C_AlsFnBndry} alias __function_boundary_in__, begin"
als_fn_bndry_in__call_line=${nL}
als_def_line="${als_fn_bdry_in__def_lineno}"
fn_call_lineno=$(( ${als_cl_fn__call_line:-} +1))
fn_def_lineno="${nL:-}"
local_hyphn="$-"
prev_cmd_exit_code="${EC:-$?}";
: alias __function_boundary_in__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __function_boundary_out_0__ ${C_AttrOff}"
als_fn_bdry_out_0__def_lineno="$((nL+1))"
alias __function_boundary_out_0__='
_="${C_AlsFnBndry} alias __function_boundary_out_0__ begin" als_call_line=$nL als_def_line=${als_fn_bdry_out_0__def_lineno}
_="alias __function_boundary_out_0__, end"
_="${C_FnBndry} ${fn_bndry_lo} function ${FUNCNAME[0]}() ENDS ${fn_bndry_sh} ${fn_lvl} to $(( --fn_lvl )) ${C_AttrOff}"
'
#: "${C_CmntSub} Define alias __function_boundary_out_1__ ${C_AttrOff}"
#als_fn_bdry_out_1__def_lineno="$((nL+1))"
#alias __function_boundary_out_1__='
#: "${C_AlsFnBndry}" Line ${nL}, alias __function_boundary_out_1__, begin, def Line ${als_fn_bdry_out_1__def_lineno} "${C_FnBndry}";
##[[ $print_function_boundaries == do_prFnBndrys ]] &&
##builtin set -x &&
#_="${fn_bndry_lo} function ${FUNCNAME[1]}() ENDS ${fn_bndry_sh} ${fn_lvl} to $(( --fn_lvl ))"
##builtin set -
#: "${C_AlsFnBndry}" Line ${nL}, alias __function_boundary_out_1__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __pause2ck__ ${C_AttrOff}"
als_ps2ck__def_lineno="$((nL+1))"
alias __pause2ck__='
: "${C_AlsFnBndry}" Line ${nL}, alias __pause2ck__, begin, def Line ${als_ps2ck__def_lineno}
pause_to_check "${nL}"
: "${C_AlsFnBndry}" Line ${nL}, alias __pause2ck__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __xtr_read_and_on__ ${C_AttrOff}"
als_xtr_read_on__def_lineno="$((nL+1))"
alias __xtr_read_and_on__='
: "${C_XtrAls}" Line ${nL}, alias __xtr_read_and_on__, begin, def Line ${als_xtr_read_on__def_lineno}
if [[ $- == *x* ]]
then
xtr_state=on
else
xtr_state=off
fi
export xtr_state
builtin set -x
: "${C_XtrAls}" Line ${nL}, alias __xtr_read_and_on__, end "${C_AttrOff}"'
: "${C_CmntSub} Define alias __xtr_restore__ ${C_AttrOff}"
# shellcheck disable=SC2154
als_xtr_rstr__def_lineno="$((nL+1))"
alias __xtr_restore__='
: "${C_XtrAls}" Line ${nL}, alias __xtr_restore__, begin, def Line ${als_xtr_rstr__def_lineno}
local -
builtin set +x
if [[ -z ${xtr_state} ]]
then
__die__ Some state must have been established
elif [[ ${xtr_state} == on ]]
then
builtin set -x
elif ! [[ ${xtr_state} == off ]]
then
__die__
fi
: "${C_XtrAls}" Line ${nL}, alias __xtr_restore__, end "${C_AttrOff}"'
## <> Testing global and local xtrace
#builtin set -x
#alias __enable_local_xtrace__ __enable_global_xtrace__
## Note, if global xtrace is enabled, then from within a function local xtrace can also be enabled without any negative effects.
#__enable_global_xtrace__
#: "baz"
#builtin exit "$nL"
#: "Define fn_test()"
#function fn_test(){
#__enable_local_xtrace__
#: "inside function fn_test foo"
## Note, from within a function, global xtrace cannot be enabled if local xtrace has been previously enabled in the same function.
#__enable_global_xtrace__
#: "inside function fn_test bar"
#: "exiting function"
#}
#: "outside and before function call"
#fn_test
#: "outside and after function call"
#: "quux"
#builtin exit "$nL"
## <> End
: "${C_CmntSub} Line ${nL}, Aliases, Deburg - Complete ${C_AttrOff}"
}
enable_deburg_aliases
# <>
#exit "$LINENO"
#set -x
function enable_deburg_functions(){
: "${C_Comment} Line ${nL}, Functions, Deburg ${C_AttrOff}"
: "${C_CmntSub} Line ${nL}, Functions, Deburg - TOC ${C_AttrOff}"
## Function name
#+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#+ enable_git_deburg_settings()
#+ pause_to_check()
#+ set()
#+ xtr_duck()
: "${C_CmntSub} Define enable_git_deburg_settings() ${C_AttrOff}"
function enable_git_deburg_settings(){ __function_boundary_in__
#__enable_local_xtrace__
: "${C_CmntSub} Variables -- Global git deburg settings ${C_AttrOff}"
# shellcheck disable=SC2034
{
GIT_TRACE=true
GIT_CURL_VERBOSE=true
GIT_SSH_COMMAND="ssh -vvv"
GIT_TRACE_PACK_ACCESS=true
GIT_TRACE_PACKET=true
GIT_TRACE_PACKFILE=true
GIT_TRACE_PERFORMANCE=true
GIT_TRACE_SETUP=true
GIT_TRACE_SHALLOW=true
}
[[ -f ~/.gitconfig ]] &&
git config --global --list --show-origin --show-scope |
cat -n
__function_boundary_out_0__
}
: "${C_CmntSub} Define pause_to_check() ${C_AttrOff}"
## Usage, pause_to_check "${nL}"
function pause_to_check(){ __function_boundary_in__
#__enable_local_xtrace__
#local -I EC=101 LN="$1" ## Q, Why inherit attributes and values when you assign values anyway?
local -I EC=101 ## Q, Why inherit attributes and values when you assign values anyway?
#shift
local -a KK=( "$@" )
local reply
[[ -n ${KK[*]:0:1} ]] &&
printf '\n%s, %s(), %s\n' "${scr_nm}" "${FUNCNAME[0]}" "${KK[@]}" >&2
printf '\n[Y|y|(enter)|(space)] is yes\nAnything else is { no and exit }\n' >&2
if ! read -N1 -p $'\nReady?\n' -rst 600 reply >&2
then
printf '\nExiting, line %d\n\n' "${KK}" >&2
builtin exit
fi
case "${reply}" in
Y* | y* | $'\n' | \ )
printf '\nOkay\n\n' >&2
;; #
* )
printf '\nExiting, line %d\n\n' "${KK}" >&2
builtin exit
;; #
esac
unset KK
## TODO: copy out this construct to the rest of the functions, re bndry_cmd
## SAVE this block
#local bndry_cmd
#if [[ $hyphn =~ x ]]; then bndry_cmd="echo"; else bndry_cmd="true"; fi
#"${bndry_cmd}" "${fn_bndry} ${FUNCNAME[0]}() ENDS ${fn_bndry} ${fn_lvl} to $(( --fn_lvl ))"
__function_boundary_out_0__
}
# <>
#exit "$LINENO"
#set -x
: "${C_CmntSub} Define set() ${C_AttrOff}"
function set(){ __function_boundary_in__
## The global variable $fn_lvl is pulled in from the global scope and is set to effect the global
#+ scope as well
local -Ig fn_lvl
#: "${C_TechCmnt}" $'This \x60set\x60 effects global scope' "${C_AttrOff}"
#builtin set "$@"
#: "${C_TechCmnt}" $'This \x60set\x60 effects local scope' "${C_AttrOff}"
#local -
#builtin set -x
local local_hyphn
local_hyphn="${local_hyphn:-"$-"}"
local -aIg qui__ ver__
qui__=("${qui__[@]}")
ver__=("${ver__[@]}")
#declare -p global_hyphn local_hyphn qui__ ver__
if [[ -o xtrace ]]
then
qui__=( [0]="--" )
ver__=( [0]="--verbose" [1]="--" )
else
qui__=( [0]="--quiet" [1]="--" )
ver__=( [0]="--" )
fi
export qui__ ver__
__function_boundary_out_0__
}
## Buggy?
#: "${C_CmntSub} Define xtr_duck() ${C_AttrOff}"
#function xtr_duck(){ __function_boundary_in__
#__enable_local_xtrace__
### Turns xtrace off after recording previous state
#[[ -o xtrace ]] &&
#xon=yes &&
#builtin set +x &&
#__function_boundary_out_0__ &&
#return
### Turns xtrace on after recording previous state
#[[ ${xon:=} = yes ]] &&
#builtin set -x &&
#__function_boundary_out_0__ &&
#return
#}
: "${C_Comment} Line ${nL}, Functions, Deburg - Complete ${C_AttrOff}"
}
enable_deburg_functions
# <>
#set -x
#exit "$LINENO"
builtin set -x
: "${C_CmntSub} Define setup_variables() ${C_AttrOff}"
function setup_variables(){ __function_boundary_in__
#__enable_local_xtrace__
:
: "${C_Comment} Line ${nL}, Variables ...likely to change or early-definition required ${C_AttrOff}"
:
: "${C_CmntSub} Variables, colors, non-deburg ${C_AttrOff}"
[[ -v C_AlsFnBndry ]] || C_AlsFnBndry="${C_AlsFnBndry:=}"
[[ -v C_AttrOff ]] || C_AttrOff="${C_AttrOff:=}"
[[ -v C_CmntSub ]] || C_CmntSub="${C_CmntSub:=}"
[[ -v C_CmntSubSub ]] || C_CmntSubSub="${C_CmntSubSub:=}"
[[ -v C_Comment ]] || C_Comment="${C_Comment:=}"
[[ -v C_Errors ]] || C_Errors="${C_Error:=}"
[[ -v C_FnBndry ]] || C_FnBndry="${C_FnBndry:=}"
[[ -v C_TechCmnt ]] || C_TechCmnt="${C_TechCmnt:=}"
[[ -v C_XtrAls ]] || C_XtrAls="${C_XtrAls:=}"
:
# <>
#exit "$nL"
builtin set -x
:
: "${C_CmntSub} Variables, Error handling ${C_AttrOff}"
## Bug, only way to export namerefs? `declare -nx nL=...`
## Note, variable assignments, backslash escape bc sed -i
# shellcheck disable=SC1001
local -gnx nL=L\INENO
:
: "${C_CmntSub} Variables, PATH ${C_AttrOff}"
PATH="/usr/bin:/usr/sbin"
export PATH
:
: "${C_CmntSub} Variables, Other environment variables ${C_AttrOff}"
## Note, Initialize some env vars found in sourced files, as a workaround for nounset
## Note, local style, inline comments, ie, ": foo ## Note, blah", are useful for rebutting false positives
#+ from ShellCheck
LC_ALL=""
PS1=""
:
## Note, /etc/bashrc and /etc/profile.d/colorls.*sh on Fedora 38
# shellcheck disable=SC2034
local -g BASHRCSOURCED USER_LS_COLORS
:
: "${C_CmntSub} Variables, Login UID and GID ${C_AttrOff}"
## Note, ps(1), "The real group ID identifies the group of the user who created the process" and "The
#+ effective group ID describes the group whose file access permissions are used by the process"
#+ See output of, `ps ax -o euid,ruid,egid,rgid,pid,ppid,stat,cmd | awk '$1 !~ $2 || $3 !~ $4'`
## Note, sudo(1), "SUDO_UID: Set to the user-ID of the user who invoked sudo."
if [[ -z ${login_uid:=} ]]
then
login_uid=$( id -u "$( logname )" )
fi
:
if [[ -z ${login_gid:=} ]]
then
login_gid=$( id -g "$( logname )" )
fi
#saved_SUDO_UID=$( sudo printenv SUDO_UID )
#saved_SUDO_GID=$( sudo printenv SUDO_GID )
:
# shellcheck disable=SC2034
{
: "${C_CmntSub} Variables, Script metadata ${C_AttrOff}"
global_hyphn=$-
export global_hyphn
:
: "${C_CmntSub} Variables, Repo info ${C_AttrOff}"
scr_repo_nm="LiveUsb"
scr_nm="LiveUsb1.sh"
datadir_basenm="skel-LiveUsb"
datdir_idfile=".${scr_repo_nm}_id-key"
readonly scr_repo_nm scr_nm datadir_basenm datdir_idfile
:
: "${C_CmntSub} Variables, File and partition data and metadata ${C_AttrOff}"
sha256_of_repo_readme="da016cc2869741834138be9f5261f14a00810822a41e366bae736bd07fd19b7c"
data_pttn_uuid="7fcfd195-01"
data_dir_id_sha256="7542c27ad7c381b059009e2b321155b8ea498cf77daaba8c6d186d6a0e356280"
readonly sha256_of_repo_readme data_pttn_uuid data_dir_id_sha256
:
: "${C_CmntSub} Variables, User info ${C_AttrOff}"
user_real_name="Wiley Young"
user_github_email_address="84648683+wileyhy@users.noreply.github.com"
user_github_gpg_key="E287D0CF528591CE"
readonly user_real_name user_github_email_address user_github_gpg_key
:
: "${C_CmntSub} Variables, Required RPM\s ${C_AttrOff}"
list_of_minimum_reqd_rpms+=( [0]="ShellCheck"
[1]="firewall-config"
[2]="geany"
[3]="gh"
[4]="git"
[5]="vim-enhanced" )
readonly list_of_minimum_reqd_rpms
:
: "${C_Comment} Line ${nL}, Files, Required files lists ${C_AttrOff}"
:
## Note, the "indexed array," $arrays_of_conf_files , is a meta-array containing a list of names of more
#+ "indexed arrays." The array names, $files_for_use_with_github_depth_* , each have the same format and
#+ are numbered sequentially are created here on one line only and have values assigned to each of them
#+ within the next ~50 lines. The list of index numbers is created just once, so the indices in the
#+ assignment section below must match the indices created here.
arrays_of_conf_files+=( [0]="files_for_use_with_github_depth_0"
[1]="files_for_use_with_github_depth_1"
[2]="files_for_use_with_github_depth_2"
[3]="files_for_use_with_github_depth_3" )
readonly arrays_of_conf_files
:
: 'Unset each value of the array'
unset "${arrays_of_conf_files[@]}"
:
## Note, this is really a lot of manually entered data ...of filenames -- it\s a lot to maintain. :-\
#+ Wouldn\t it be better to just always keep the data directory... in proper intended order...?
#+ But then the data dir can be changed and there wouldn\t be any process of making sure the DACs
#+ are correct. On the other hand, it\s easier to maintain a simple set of files. ...but their state
#+ wouldn\t necessarily have been documented, which is valuable in and of itself. Otherwise, if they
#+ were changed accidentally, how would you know any change had occurred?
## TODO
#: " Files, firefox"
#files_for_use_with_github_depth_0+=( ~/.mozilla )
:
: "${C_CmntSub} Files, gh (cli) ${C_AttrOff}"
files_for_use_with_github_depth_2+=( ~/.config/gh/{config.yml,gpg-agent.conf,hosts.yml,pubring.kbx,trustdb.gpg} )
files_for_use_with_github_depth_3+=( ~/.config/gh/openpgp-revocs.d/421C6CBB253AED9D0390ABE7E287D0CF528591CE.rev )
files_for_use_with_github_depth_3+=( ~/.config/gh/private-keys-v1.d/58C9C0ACBE45778C05DE9623560AC4465D8C46C8.key )
: "${C_CmntSub} Files, gpg ${C_AttrOff}"
files_for_use_with_github_depth_1+=( ~/.gnupg/{gpg-agent.conf,pubring.kbx,tofu.db,trustdb.gpg} )
files_for_use_with_github_depth_2+=( ~/.gnupg/crls.d/DIR.txt )
files_for_use_with_github_depth_2+=( ~/.gnupg/openpgp-revocs.d/421C6CBB253AED9D0390ABE7E287D0CF528591CE.rev )
files_for_use_with_github_depth_2+=( ~/.gnupg/private-keys-v1.d/58C9C0ACBE45778C05DE9623560AC4465D8C46C8.key )
: "${C_CmntSub} Files, ssh ${C_AttrOff}"
files_for_use_with_github_depth_1+=( ~/.ssh/{id_ed25519{,.pub},known_hosts} )
: "${C_CmntSub} Files, top ${C_AttrOff}"
files_for_use_with_github_depth_2+=( ~/.config/procps/toprc )
: "${C_CmntSub} Files, vim ${C_AttrOff}"
files_for_use_with_github_depth_0+=( ~/.vimrc )
: "${C_CmntSub} End of Files lists ${C_AttrOff}"
:
}
__function_boundary_out_0__
}
__call_fn__ \
setup_variables
: "${C_Comment} Line ${nL}, \
# Testing testing testing \
${C_AttrOff}"
exit "$nL"
builtin set -x
: "${C_Comment} Line ${nL}, Functions ${C_AttrOff}"
: "${C_CmntSub} Line ${nL}, Functions TOC ${C_AttrOff}"
## Function name
#+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#+ __vte_osc7()
#+ __vte_prompt_command()
#+ clone_repo()
#+ error_and_exit()
#+ get_pids_for_restarting()
#+ gh_auth_login_command()
#+ increase_disk_space()
#+ min_necc_packages()
#+ must_be_root()
#+ reqd_user_files()
#+ rsync_install_if_missing()
#+ setup_bashrc()
#+ setup_dnf()
#+ setup_gh_cli()
#+ setup_git()
#+ setup_git_user_dirs()
#+ setup_gpg()
#+ setup_network()
#+ setup_ssh()
#+ setup_systemd()
#+ setup_temp_dirs()
#+ setup_time()
#+ setup_vim()
#+ test_dns()
#+ test_os()
#+ trap_err()
#+ trap_exit()
#+ trap_return()
#+ write_bashrc_strings()
#+ write_ssh_conf()
#: "Define __vte_osc7() -- for bashrc only"
# shellcheck disable=SC2317
#function __vte_osc7(){ __function_boundary_in__
#__enable_local_xtrace__
#local cmd urlencode_o
#cmd=$( PATH="${PATH}:/usr/libexec:/usr/lib:/usr/lib64" command -v vte-urlencode-cwd )
#[[ -n ${cmd} ]] || return
#urlencode_o=$( "${cmd}" )
#printf 'file://%s%s\n' "${HOSTNAME}" "${urlencode_o:-"${PWD}"}"
#printf '\033]7;file://%s%s\033' "${HOSTNAME}" "${urlencode_o:-"${PWD}"}"
#}
#: "Define __vte_prompt_command() -- for bashrc only"
# shellcheck disable=SC2317
#function __vte_prompt_command(){ __function_boundary_in__
#__enable_local_xtrace__
#local fn_pwd
#fn_pwd=~
#if ! [[ ${PWD} = ~ ]]; then
#fn_pwd="${fn_pwd//[[:cntrl:]]}"
#fn_pwd="${PWD/#"${HOME}"\//\~\/}"
#fi
#printf '\033[m\033]7;%s@%s:%s\033' "${USER}" "${HOSTNAME%%.*}" "${fn_pwd}"
#printf '%s@%s:%s\n' "${USER}" "${HOSTNAME%%.*}" "${fn_pwd}"
#__vte_osc7
#}
: "${C_CmntSub} Define clone_repo() ${C_AttrOff}"
function clone_repo(){ __function_boundary_in__
#__enable_local_xtrace__
[[ ${PWD} = "${dev_d1}" ]] ||
__die__
local AA
AA=$(
sha256sum "${dev_d1}/${scr_repo_nm}/README.md" |
cut --delimiter=" " --fields=1
)
if ! [[ -d ./${scr_repo_nm} ]] ||
! [[ -f ./${scr_repo_nm}/README.md ]] ||
! [[ ${AA} == "${sha256_of_repo_readme}" ]]
then
git clone --origin github "https://github.com/wileyhy/${scr_repo_nm}" ||
__die__
fi
unset AA
__function_boundary_out_0__
}
: "${C_CmntSub} Define error_and_exit() ${C_AttrOff}"
function error_and_exit(){ __function_boundary_in__
#__enable_local_xtrace__
#declare -p local_hyphn
#declare -p local_lineno
#declare -p prev_cmd_exit_code
## Some positional parameters must exist
[[ $# -lt 1 ]] && return 1
## The first positional parameter must be a digit, and should be the LINENO from where error_and_exit() is called
if ! [[ $1 = [0-9]* ]]
then
printf '\n%b:: %s :: %s' "${C_Errors}" "${scr_nm}" "${FUNCNAME[@]}"
printf '\n:: Error :: first positional parameter must be a line number %b\n\n' "${C_AttrOff}"
return 2
fi
local local_lineno
local_lineno="$1"
shift
printf '%b%s, Error, line %d, %s%b\n' "${C_Errors}" "${scr_nm}" "${local_lineno}" "$*" "${C_AttrOff}" >&2
[[ ${prev_cmd_exit_code} = 0 ]] &&
prev_cmd_exit_code="01"
## <>
EC="${prev_cmd_exit_code}"
LN="${local_lineno}" builtin exit
__function_boundary_out_0__
}
## TODO: add a "get_distro()" function
: "${C_CmntSub} Define get_pids_for_restarting() ${C_AttrOff}"
function get_pids_for_restarting(){ __function_boundary_in__
#__enable_local_xtrace__
# shellcheck disable=SC2034
local dnf_o
local pipline0 pipline1
local -ga a_pids
a_pids=()
## Note, this pipeline was broken out into its constituent commands in order to verify the values
#+ mid-stream. Yes, some of the array names are in fact spelled uncorrectly.
## Note, this set of arrays could be a function, but `return` can only return from one function level at
#+ at time, or it could be a loop, but the array names and command strings would have to be in an
#+ associative array, and that seems like adding complexity.
## TODO, implement some improved commands,
#+ dnf --assumeno --security upgrade 2>/dev/null | grep -e ^'Install ' -e ^'Upgrade '
#+ dnf --assumeno --bugfix upgrade 2>/dev/null | grep -e ^'Install ' -e ^'Upgrade '
#+ for II in 7656 11807 17897 72230; do ps_o=$( ps aux ); printf '\n%s\n' "$( grep -Ee "\<${II}\>" <<< "${ps_o}" )"; /bin/kill -s HUP "${II}"; sleep 2; done
readarray -t dnf_o < <(
sudo -- nice --adjustment=-20 -- dnf needs-restarting 2> /dev/null ||
__die__
)
if [[ ${#dnf_o[@]} -eq 0 ]]
then
return 0
fi
declare -p dnf_o # <>
readarray -t pipline0 < <(
printf '%s\n' "${dnf_o[@]}" |
grep --invert-match --fixed-strings --regexp="/firefox/"
)
if [[ ${#pipline0[@]} -eq 0 ]]
then
return 0
fi
readarray -t pipline1 < <(
printf '%s\n' "${pipline0[@]}" |
awk '{ print $1 }'
)
if [[ ${#pipline1[@]} -eq 0 ]]
then
return 0
fi
readarray -t a_pids < <(
printf '%s\n' "${pipline1[@]}" |
grep --only-matching --extended-regexp ^"[0-9]*"$
)
if [[ ${#a_pids[@]} -eq 0 ]]
then
return 0
fi
__function_boundary_out_0__
}
: "${C_CmntSub} Define gh_auth_login_command() ${C_AttrOff}"
function gh_auth_login_command(){ __function_boundary_in__
#__enable_local_xtrace__
if gh auth status >/dev/null 2>&1
then
gh auth logout
fi
## Bug, output of `gh auth login`: "! Authentication credentials saved in plain text"
## Note, do not break this line with any backslashed newlines or it will fail and you\ll have to
#+ refresh auth manually; using short options for just this reason
gh auth login -p ssh -h github.com -s admin:public_key,read:gpg_key,admin:ssh_signing_key -w ||
__die__
__function_boundary_out_0__
}
: "${C_CmntSub} Define increase_disk_space() ${C_AttrOff}"
function increase_disk_space(){ __function_boundary_in__
builtin set -x # []
## Note, such as... /usr/lib/locale /usr/share/i18n/locales /usr/share/locale /usr/share/X11/locale , etc.
## Note, for $dirs1 , find syntax based on Mascheck\s
## Note, for $dirs2 , use of bit bucket because GVFS ‘/run/user/1000/doc’ cannot be read, even by root
## Note, for $fsos3 , "--and" is not POSIX compliant
## Note, for $fsos4 , sorts by unique inode and delimits by nulls
declare -A Aa_fsos5
readarray -d "" -t dirs1 < <(
find -- / \! -path / -prune -type d -print0
)
readarray -d "" -t dirs2 < <(
find -- "${dirs1[@]}" -type d -name "*locale*" \! -ipath "${mount_base__fedora}/*" -print0 2> /dev/null
)
readarray -d "" -t fsos3 < <(
find -- "${dirs2[@]}" -type f -size +$(( 2**16 )) \( \! -ipath "*en_*" -a \! -ipath "*/.git/*" \) -print0
)
if (( ${#fsos3[@]} > 0 ))
then
## Note, for loop is run in a process substitution subshell, so unsetting BB is unnecessary
readarray -d "" -t fsos4 < <(
{
for BB in "${fsos3[@]}"
do
printf '%s\0' "$( stat --printf='%i %n\n' -- "${BB}" )"
done
} |
sort --unique |
tr --delete '\n'
)
## Question, does this assoc array Aa_fsos5 need to be declared as such? (I don\t think so, but...)
set -- "${fsos4[@]}"
while true
do
[[ -z ${1:-} ]] &&
break 1 # <> set-u
# shellcheck disable=SC2190
Aa_fsos5+=( "${1%% *}" "${1#* }")
shift 1
(( $# == 0 )) &&
break 1
done
fi
: "${C_CmntSub} If any larger local data files were found, then remove them interactively ${C_AttrOff}"
if [[ -n ${!Aa_fsos5[*]} ]]
then
: "${C_CmntSub} Inform user of any found FSOs ${C_AttrOff}"
printf '%s, Delete these files? \n' "${scr_nm}"
declare -p Aa_fsos5
sleep 3
for AA in "${!Aa_fsos5[@]}"
do
HH=0
II=0