-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·9960 lines (7456 loc) · 336 KB
/
compile.sh
File metadata and controls
executable file
·9960 lines (7456 loc) · 336 KB
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
if [[ "$ubDEBUG" == "true" ]] ; then set +x ; set +E ; set +o functrace ; set +o errtrace ; export -n SHELLOPTS 2>/dev/null || true ; trap '' RETURN ; trap - RETURN ; fi
[[ "$PATH" != *"/usr/local/bin"* ]] && [[ -e "/usr/local/bin" ]] && export PATH=/usr/local/bin:"$PATH"
[[ "$PATH" != *"/usr/bin"* ]] && [[ -e "/usr/bin" ]] && export PATH=/usr/bin:"$PATH"
[[ "$PATH" != *"/bin:"* ]] && [[ -e "/bin" ]] && export PATH=/bin:"$PATH"
if [[ "$ub_setScriptChecksum" != "" ]]
then
export ub_setScriptChecksum=
fi
_ub_cksum_special_derivativeScripts_header() {
local currentFile_cksum
if [[ "$1" == "" ]]
then
currentFile_cksum="$0"
else
currentFile_cksum="$1"
fi
head -n 30 "$currentFile_cksum" | env CMD_ENV=xpg4 cksum | cut -f1 -d\ | tr -dc '0-9'
}
_ub_cksum_special_derivativeScripts_contents() {
local currentFile_cksum
if [[ "$1" == "" ]]
then
currentFile_cksum="$0"
else
currentFile_cksum="$1"
fi
tail -n +45 "$currentFile_cksum" | env CMD_ENV=xpg4 cksum | cut -f1 -d\ | tr -dc '0-9'
}
##### CHECKSUM BOUNDARY - 30 lines
[[ "$ubDEBUG" == "true" ]] && export ub_setScriptChecksum_disable='true'
#export ub_setScriptChecksum_disable='true'
( [[ -e "$0".nck ]] || [[ "${BASH_SOURCE[0]}" != "${0}" ]] || [[ "$1" == '--profile' ]] || [[ "$1" == '--script' ]] || [[ "$1" == '--call' ]] || [[ "$1" == '--return' ]] || [[ "$1" == '--devenv' ]] || [[ "$1" == '--shell' ]] || [[ "$1" == '--bypass' ]] || [[ "$1" == '--parent' ]] || [[ "$1" == '--embed' ]] || [[ "$1" == '--compressed' ]] || [[ "$0" == "/bin/bash" ]] || [[ "$0" == "-bash" ]] || [[ "$0" == "/usr/bin/bash" ]] || [[ "$0" == "bash" ]] ) && export ub_setScriptChecksum_disable='true'
export ub_setScriptChecksum_header='3620520443'
export ub_setScriptChecksum_contents='1451046043'
# CAUTION: Symlinks may cause problems. Disable this test for such cases if necessary.
# WARNING: Performance may be crucial here.
#[[ -e "$0" ]] && ! [[ -h "$0" ]] && [[ "$ub_setScriptChecksum" != "" ]]
if [[ -e "$0" ]] && [[ "$ub_setScriptChecksum_header" != "" ]] && [[ "$ub_setScriptChecksum_contents" != "" ]] && [[ "$ub_setScriptChecksum_disable" != 'true' ]] #&& ! ( [[ -e "$0".nck ]] || [[ "${BASH_SOURCE[0]}" != "${0}" ]] || [[ "$1" == '--profile' ]] || [[ "$1" == '--script' ]] || [[ "$1" == '--call' ]] || [[ "$1" == '--return' ]] || [[ "$1" == '--devenv' ]] || [[ "$1" == '--shell' ]] || [[ "$1" == '--bypass' ]] || [[ "$1" == '--parent' ]] || [[ "$1" == '--embed' ]] || [[ "$1" == '--compressed' ]] || [[ "$0" == "/bin/bash" ]] || [[ "$0" == "-bash" ]] || [[ "$0" == "/usr/bin/bash" ]] || [[ "$0" == "bash" ]] )
then
[[ $(_ub_cksum_special_derivativeScripts_header) != "$ub_setScriptChecksum_header" ]] && exit 1
[[ $(_ub_cksum_special_derivativeScripts_contents) != "$ub_setScriptChecksum_contents" ]] && exit 1
fi
##### CHECKSUM BOUNDARY - 45 lines
_ub_cksum_special_derivativeScripts_write() {
local current_ub_setScriptChecksum_header
local current_ub_setScriptChecksum_contents
current_ub_setScriptChecksum_header=$(_ub_cksum_special_derivativeScripts_header "$1")
current_ub_setScriptChecksum_contents=$(_ub_cksum_special_derivativeScripts_contents "$1")
sed -i 's/'#'#'###uk4uPhB663kVcygT0q-UbiquitousBash-ScriptSelfModify-SetScriptChecksumHeader-UbiquitousBash-uk4uPhB663kVcygT0q#####'/'"$current_ub_setScriptChecksum_header"'/' "$1"
sed -i 's/'#'#'###uk4uPhB663kVcygT0q-UbiquitousBash-ScriptSelfModify-SetScriptChecksumContents-UbiquitousBash-uk4uPhB663kVcygT0q#####'/'"$current_ub_setScriptChecksum_contents"'/' "$1"
}
#Universal debugging filesystem.
_user_log-ub() {
# DANGER Do NOT create automatically, or reference any existing directory!
! [[ -d "$HOME"/.ubcore/userlog ]] && cat - > /dev/null 2>&1 && return 0
#Terminal session may be used - the sessionid may be set through .bashrc/.ubcorerc .
if [[ "$sessionid" != "" ]]
then
cat - >> "$HOME"/.ubcore/userlog/u-"$sessionid".log
return 0
fi
cat - >> "$HOME"/.ubcore/userlog/u-undef.log
return 0
}
#Cyan. Harmless status messages.
_messagePlain_nominal() {
echo -e -n '\E[0;36m '
echo -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
#Blue. Diagnostic instrumentation.
_messagePlain_probe() {
echo -e -n '\E[0;34m '
echo -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
#Blue. Diagnostic instrumentation.
_messagePlain_probe_expr() {
echo -e -n '\E[0;34m '
echo -e -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
#Blue. Diagnostic instrumentation.
_messagePlain_probe_var() {
echo -e -n '\E[0;34m '
echo -n "$1"'= '
eval echo -e -n \$"$1"
echo -e -n ' \E[0m'
echo
return 0
}
_messageVar() {
_messagePlain_probe_var "$@"
}
#Green. Working as expected.
_messagePlain_good() {
echo -e -n '\E[0;32m '
echo -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
#Yellow. May or may not be a problem.
_messagePlain_warn() {
echo -e -n '\E[1;33m '
echo -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
#Red. Will result in missing functionality, reduced performance, etc, but not necessarily program failure overall.
_messagePlain_bad() {
echo -e -n '\E[0;31m '
echo -n "$@"
echo -e -n ' \E[0m'
echo
return 0
}
##Parameters
#"--shell", ""
#"--profile"
#"--parent", "--embed", "--return", "--devenv"
#"--call", "--script" "--bypass"
#if [[ "$ub_import" != "" ]]
#then
#[[ "$ub_import" != "" ]] && export ub_import="" && unset ub_import
#[[ "$importScriptLocation" != "" ]] && export importScriptLocation= && unset importScriptLocation
#[[ "$importScriptFolder" != "" ]] && export importScriptFolder= && unset importScriptFolder
#fi
#[[ "$ub_import" != "" ]] && export ub_import="" && unset ub_import
#[[ "$ub_import_param" != "" ]] && export ub_import_param="" && unset ub_import_param
#[[ "$ub_import_script" != "" ]] && export ub_import_script="" && unset ub_import_script
#[[ "$ub_loginshell" != "" ]] && export ub_loginshell="" && unset ub_loginshell
ub_import=
ub_import_param=
ub_import_script=
ub_loginshell=
# ATTENTION: Apparently (Portable) Cygwin Bash interprets correctly.
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && ub_import="true"
( [[ "$1" == '--profile' ]] || [[ "$1" == '--script' ]] || [[ "$1" == '--call' ]] || [[ "$1" == '--return' ]] || [[ "$1" == '--devenv' ]] || [[ "$1" == '--shell' ]] || [[ "$1" == '--bypass' ]] || [[ "$1" == '--parent' ]] || [[ "$1" == '--embed' ]] || [[ "$1" == '--compressed' ]] ) && ub_import_param="$1" && shift
( [[ "$0" == "/bin/bash" ]] || [[ "$0" == "-bash" ]] || [[ "$0" == "/usr/bin/bash" ]] || [[ "$0" == "bash" ]] ) && ub_loginshell="true" #Importing ubiquitous bash into a login shell with "~/.bashrc" is the only known cause for "_getScriptAbsoluteLocation" to return a result such as "/bin/bash".
[[ "$ub_import" == "true" ]] && ! [[ "$ub_loginshell" == "true" ]] && ub_import_script="true"
_messagePlain_probe_expr '$0= '"$0"'\n ''$1= '"$1"'\n ''ub_import= '"$ub_import"'\n ''ub_import_param= '"$ub_import_param"'\n ''ub_import_script= '"$ub_import_script"'\n ''ub_loginshell= '"$ub_loginshell" | _user_log-ub
# DANGER Prohibited import from login shell. Use _setupUbiquitous, call from another script, or manually set importScriptLocation.
# WARNING Import from shell can be detected. Import from script cannot. Asserting that script has been imported is possible. Asserting that script has not been imported is not possible. Users may be protected from interactive mistakes. Script developers are NOT protected.
if [[ "$ub_import_param" == "--profile" ]]
then
if ( [[ "$profileScriptLocation" == "" ]] || [[ "$profileScriptFolder" == "" ]] ) && _messagePlain_bad 'import: profile: missing: profileScriptLocation, missing: profileScriptFolder' | _user_log-ub
then
return 1 >/dev/null 2>&1
exit 1
fi
elif ( [[ "$ub_import_param" == "--parent" ]] || [[ "$ub_import_param" == "--embed" ]] || [[ "$ub_import_param" == "--return" ]] || [[ "$ub_import_param" == "--devenv" ]] )
then
if ( [[ "$scriptAbsoluteLocation" == "" ]] || [[ "$scriptAbsoluteFolder" == "" ]] || [[ "$sessionid" == "" ]] ) && _messagePlain_bad 'import: parent: missing: scriptAbsoluteLocation, missing: scriptAbsoluteFolder, missing: sessionid' | _user_log-ub
then
return 1 >/dev/null 2>&1
exit 1
fi
elif [[ "$ub_import_param" == "--call" ]] || [[ "$ub_import_param" == "--script" ]] || [[ "$ub_import_param" == "--bypass" ]] || [[ "$ub_import_param" == "--shell" ]] || [[ "$ub_import_param" == "--compressed" ]] || ( [[ "$ub_import" == "true" ]] && [[ "$ub_import_param" == "" ]] )
then
if ( [[ "$importScriptLocation" == "" ]] || [[ "$importScriptFolder" == "" ]] ) && _messagePlain_bad 'import: call: missing: importScriptLocation, missing: importScriptFolder' | _user_log-ub
then
return 1 >/dev/null 2>&1
exit 1
fi
elif [[ "$ub_import" != "true" ]] #"--shell", ""
then
_messagePlain_warn 'import: undetected: cannot determine if imported' | _user_log-ub
true #no problem
else #FAIL, implies [[ "$ub_import" == "true" ]]
_messagePlain_bad 'import: fall: fail' | _user_log-ub
return 1 >/dev/null 2>&1
exit 1
fi
#Override.
# DANGER: Recursion hazard. Do not create override alias/function without checking that alternate exists.
# Seems Ubuntu 20 used an 'alias' for 'python', which may not be usable by shell scripts.
if ! type python > /dev/null 2>&1 && type python3 > /dev/null 2>&1
then
python() {
python3 "$@"
}
fi
# ATTENTION: NOTICE: https://nixos.wiki/wiki/Locales
# WARNING: May conflict with 'export LANG=C' or similar.
# Workaround for very minor OS misconfiguration. Setting this variable at all may be undesirable however. Consider enabling and generating all locales with 'sudo dpkg-reconfigure locales' or similar .
#[[ "$LC_ALL" == '' ]] && export LC_ALL="en_US.UTF-8"
# WARNING: Do NOT use 'ubKeep_LANG' unless necessary!
# nix-shell --run "locale -a" -p bash
# C C.utf8 POSIX
[[ "$ubKeep_LANG" != "true" ]] && [[ "$LANG" != "C" ]] && export LANG="C"
# WARNING: Only partially compatible.
if ! type md5sum > /dev/null 2>&1 && type md5 > /dev/null 2>&1
then
md5sum() {
md5 "$@"
}
fi
# DANGER: No production use. Testing only.
# WARNING: Only partially compatible.
#if ! type md5 > /dev/null 2>&1 && type md5sum > /dev/null 2>&1
#then
# md5() {
# md5sum "$@"
# }
#fi
# WARNING: DANGER: Compatibility may not be guaranteed!
if ! type unionfs-fuse > /dev/null 2>&1 && type unionfs > /dev/null 2>&1 && man unionfs | grep 'unionfs-fuse - A userspace unionfs implementation' > /dev/null 2>&1
then
unionfs-fuse() {
unionfs "$@"
}
fi
if ! type qemu-arm-static > /dev/null 2>&1 && type qemu-arm > /dev/null 2>&1
then
qemu-arm-static() {
qemu-arm "$@"
}
fi
if ! type qemu-armeb-static > /dev/null 2>&1 && type qemu-armeb > /dev/null 2>&1
then
qemu-armeb-static() {
qemu-armeb "$@"
}
fi
# ATTENTION: Highly irregular. Workaround due to gsch2pcb installed by nix package manager not searching for installed footprints.
#if [[ "$NIX_PROFILES" != "" ]]
#then
if [[ -e "$HOME"/.nix-profile/bin/gsch2pcb ]] && [[ -e /usr/local/share/pcb/newlib ]] && [[ -e /usr/local/lib/pcb_lib ]]
then
gsch2pcb() {
"$HOME"/.nix-profile/bin/gsch2pcb --elements-dir /usr/local/share/pcb/newlib --elements-dir /usr/local/lib/pcb_lib "$@"
}
elif [[ -e /usr/share/pcb/pcblib-newlib ]]
then
gsch2pcb() {
"$HOME"/.nix-profile/bin/gsch2pcb --elements-dir /usr/share/pcb/pcblib-newlib "$@"
}
fi
#fi
# Only production use is Inter-Process Communication (IPC) loops which may be theoretically impossible to make fully deterministic under Operating Systems which do not have hard-real-time kernels and/or may serve an unlimited number of processes.
_here_header_bash_or_dash() {
if [[ -e /bin/dash ]]
then
cat << 'CZXWXcRMTo8EmM8i4d'
#!/bin/dash
CZXWXcRMTo8EmM8i4d
else
cat << 'CZXWXcRMTo8EmM8i4d'
#!/usr/bin/env bash
CZXWXcRMTo8EmM8i4d
fi
}
# Delay to attempt to avoid InterProcess-Communication (IPC) problems caused by typical UNIX/MSW Operating System kernel latency and/or large numbers of processes/threads.
# Widely deployed Linux compatible hardware and software is able to run with various 'preemption' 'configured'/'patched' kernels. Detecting such kernels may allow reduction of this arbitrary delay.
# CAUTION: Merely attempts to avoid a problem which may be inherently unavoidably unpredictable.
_sleep_spinlock() {
# CAUTION: Spinlocks on the order of 8s are commonly observed with 'desktop' operating systems. Do NOT reduce this delay without thorough consideration! Theoretically, it may not be possible to determine whether the parent of a process is still running in less than spinlock time, only the existence of the parent process guarantees against PID rollover, and multiple spinlocks may occur between the necessary IPC events to determine any of the above.
# ATTENTION: Consider setting this to the worst-case acceptable latency for a system still considered 'responsive' (ie. a number of seconds greater than that which would cause a user or other 'watchdog' to forcibly reboot the system).
local currentWaitSpinlock
let currentWaitSpinlock="$RANDOM"%4
#let currentWaitSpinlock="$currentWaitSpinlock"+12
let currentWaitSpinlock="$currentWaitSpinlock"+10
sleep "$currentWaitSpinlock"
}
_____special_live_hibernate_rmmod_remainder-vbox_procedure() {
local currentLine
sudo -n lsmod | grep '^vbox.*$' | cut -f1 -d\ | while read currentLine
do
#echo "$currentLine"
sudo -n rmmod "$currentLine"
done
}
_____special_live_hibernate_rmmod_remainder-vbox() {
local currentIterations
currentIterations=0
while [[ "$currentIterations" -lt 2 ]]
do
let currentIterations="$currentIterations + 1"
_____special_live_hibernate_rmmod_remainder-vbox_procedure "$@" > /dev/null 2>&1
done
_____special_live_hibernate_rmmod_remainder-vbox_procedure "$@"
}
# CAUTION: Do not alow similarity of this function name to other commonly used function names . Unintended tab completion could significantly and substantially impede user , particularly if 'disk' hibernation is not properly available .
_____special_live_hibernate() {
! _mustGetSudo && exit 1
_messageNormal 'init: _____special_live_hibernate'
local currentIterations
_messagePlain_nominal 'attempt: swapon'
sudo -n swapon /dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17
free -m
_messagePlain_nominal 'detect: vboxguest'
sudo -n lsmod | grep vboxguest > /dev/null 2>&1 && export ub_current_special_live_consider_vbox='true'
[[ "$ub_current_special_live_consider_vbox" == 'true' ]] && _messagePlain_good 'good: detected: vboxguest'
if [[ "$ub_current_special_live_consider_vbox" == 'true' ]]
then
_messagePlain_nominal 'attempt: terminate: VBoxService , VBoxClient'
sudo -n pkill VBoxService
sudo -n pkill VBoxClient
pgrep ^VBox && sleep 0.1 && pgrep ^VBox && sleep 0.3 && pgrep ^VBox && sleep 1
sudo -n pkill -KILL VBoxService
sudo -n pkill -KILL VBoxClient
pgrep ^VBox && sleep 0.3
_messagePlain_nominal 'attempt: rmmod (vbox)'
sleep 0.05
sudo -n rmmod vboxsf
sudo -n rmmod vboxvideo
sudo -n rmmod vboxguest
_____special_live_hibernate_rmmod_remainder-vbox
sleep 0.02
sudo -n rmmod vboxsf
sudo -n rmmod vboxvideo
sudo -n rmmod vboxguest
_____special_live_hibernate_rmmod_remainder-vbox
fi
_messagePlain_nominal 'attempt: HIBERNATE'
sudo -n journalctl --rotate
sudo -n journalctl --vacuum-time=1s
sudo -n systemctl hibernate
# ~1.0s
sleep 1.1
currentIterations=0
while [[ "$currentIterations" -lt 3 ]]
do
sudo -n systemctl status hibernate.target | tail -n2 | head -n1 | grep ' Reached ' > /dev/null 2>&1 && _messagePlain_probe 'Reached'
sudo -n systemctl status hibernate.target | tail -n1 | grep ' Stopped ' > /dev/null 2>&1 && _messagePlain_probe 'Stopped'
sudo -n systemctl status hibernate.target | grep 'inactive (dead)' > /dev/null 2>&1 && _messagePlain_probe 'inactive'
sudo -n systemctl status hibernate.target | tail -n2 | head -n1 | grep ' Reached ' > /dev/null 2>&1 &&
sudo -n systemctl status hibernate.target | tail -n1 | grep ' Stopped ' > /dev/null 2>&1 &&
sudo -n systemctl status hibernate.target | grep 'inactive (dead)' > /dev/null 2>&1 &&
break
_messagePlain_good 'delay: resume'
let currentIterations="$currentIterations + 1"
sleep 0.3
done
_messagePlain_nominal 'delay: spinlock (optimistic)'
# Expected to result in longer delay if system is not idle.
# ~2s
currentIterations=0
while [[ "$currentIterations" -lt 6 ]]
do
let currentIterations="$currentIterations + 1"
sleep 0.3
done
# 0.5s
currentIterations=0
while [[ "$currentIterations" -lt 5 ]]
do
let currentIterations="$currentIterations + 1"
sleep 0.1
done
# 0.15s
currentIterations=0
while [[ "$currentIterations" -lt 15 ]]
do
let currentIterations="$currentIterations + 1"
sleep 0.01
done
#_messagePlain_nominal 'delay: spinlock (arbitrary)'
#sleep 1
#_messagePlain_nominal 'delay: spinlock (pessimistic)'
#_sleep_spinlock
if [[ "$ub_current_special_live_consider_vbox" == 'true' ]]
then
_messagePlain_nominal 'attempt: modprobe (vbox)'
sudo -n modprobe vboxsf
sudo -n modprobe vboxvideo
sudo -n modprobe vboxguest
sleep 0.1
_messagePlain_nominal 'attempt: VBoxService'
sudo -n VBoxService --pidfile /var/run/vboxadd-service.sh
# 0.3s
currentIterations=0
while [[ "$currentIterations" -lt 3 ]]
do
let currentIterations="$currentIterations + 1"
sleep 0.1
done
_messagePlain_nominal 'attempt: VBoxClient'
#sudo -n VBoxClient --vmsvga
#sudo -n VBoxClient --seamless
#sudo -n VBoxClient --draganddrop
#sudo -n VBoxClient --clipboard
sudo -n VBoxClient-all
fi
disown -a -h -r
disown -a -r
_messageNormal 'done: _____special_live_hibernate'
return 0
}
_____special_live_bulk_rw() {
! _mustGetSudo && exit 1
_messageNormal 'init: _____special_live_bulk_rw'
sudo -n mkdir -p /mnt/bulk
_messagePlain_nominal 'detect: mount: bulk'
if ! mountpoint /mnt/bulk
then
_messagePlain_nominal 'mount: rw: bulk'
sudo -n mount -o rw /dev/disk/by-uuid/f1edb7fb-13b1-4c97-91d2-baf50e6d65d8 /mnt/bulk
fi
! mountpoint /mnt/bulk && _messagePlain_bad 'fail: detect: mount: bulk' && exit 1
_messagePlain_nominal 'remount: rw: bulk'
sudo -n mount -o remount,rw /mnt/bulk
_messageNormal 'done: _____special_live_bulk_rw'
return 0
}
# No production use. Not expected to be desirable. Any readonly files could be added, compressed, to the 'live' 'root' .
_____special_live_bulk_ro() {
! _mustGetSudo && exit 1
_messageNormal 'init: _____special_live_bulk_ro'
sudo -n mkdir -p /mnt/bulk
_messagePlain_nominal 'detect: mount: bulk'
if ! mountpoint /mnt/bulk
then
_messagePlain_nominal 'mount: ro: bulk'
sudo -n mount -o ro /dev/disk/by-uuid/f1edb7fb-13b1-4c97-91d2-baf50e6d65d8 /mnt/bulk
fi
! mountpoint /mnt/bulk && _messagePlain_bad 'fail: detect: mount: bulk' && exit 1
_messagePlain_nominal 'remount: ro: bulk'
sudo -n mount -o remount,ro /mnt/bulk
_messageNormal 'done: _____special_live_bulk_ro'
return 0
}
# DANGER: Simultaneous use of any 'rw' mounted filesystem with any 'restored' hibernation file/partition is expected to result in extreme filesystem corruption! Take extra precautions to avoid this mistake!
# CAUTION: Do not alow similarity of this function name to other commonly used function names . Unintended tab completion could significantly and substantially impede user.
_____special_live_dent_backup() {
! _mustGetSudo && exit 1
_messageNormal 'init: _____special_live_dent_backup'
_messagePlain_nominal 'attempt: mount: dent'
sudo -n mkdir -p /mnt/dent
! mountpoint /mnt/dent && sudo -n mount -o ro /dev/disk/by-uuid/d82e3d89-3156-4484-bde2-ccc534ca440b /mnt/dent
! mountpoint /mnt/dent && exit 1
sudo -n mount -o remount,rw /mnt/dent
_messagePlain_nominal 'attempt: copy: hint'
if type -p 'pigz' > /dev/null 2>&1
then
sudo -n dd if=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M | pigz --fast | sudo -n tee /mnt/dent/hint_bak.gz > /dev/null
elif type -p 'gzip' > /dev/null 2>&1
then
sudo -n dd if=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M | gzip --fast | sudo -n tee /mnt/dent/hint_bak.gz > /dev/null
else
sudo -n dd if=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M | sudo -n tee /mnt/dent/hint_bak > /dev/null
fi
sync
_messagePlain_nominal 'attempt: mount: ro: bulk'
sudo -n mkdir -p /mnt/bulk
! mountpoint /mnt/bulk && sudo -n mount -o ro /dev/disk/by-uuid/f1edb7fb-13b1-4c97-91d2-baf50e6d65d8 /mnt/bulk
! mountpoint /mnt/bulk && exit 1
_messagePlain_nominal 'attempt: copy: bulk'
sudo -n mkdir -p /mnt/dent/bulk_bak
[[ ! -e /mnt/dent/bulk_bak ]] && exit 1
[[ ! -d /mnt/dent/bulk_bak ]] && exit 1
sudo -n rsync -ax --delete /mnt/bulk/. /mnt/dent/bulk_bak/.
_messagePlain_nominal 'attempt: umount: dent'
sudo -n mount -o remount,ro /mnt/dent
sync
sudo -n umount /mnt/dent
sync
_messageNormal 'done: _____special_live_dent_backup'
return 0
}
# DANGER: Simultaneous use of any 'rw' mounted filesystem with any 'restored' hibernation file/partition is expected to result in extreme filesystem corruption! Take extra precautions to avoid this mistake!
# CAUTION: Do not alow similarity of this function name to other commonly used function names . Unintended tab completion could significantly and substantially impede user.
# WARNING: By default does not restore contents of '/mnt/bulk' assuming simultaneous use of persistent storage and hibernation backup is sufficiently unlikely and risky that a request to the user is preferable.
_____special_live_dent_restore() {
! _mustGetSudo && exit 1
_messageNormal 'init: _____special_live_dent_restore'
_messagePlain_nominal 'attempt: mount: dent'
sudo -n mkdir -p /mnt/dent
! mountpoint /mnt/dent && sudo -n mount -o ro /dev/disk/by-uuid/d82e3d89-3156-4484-bde2-ccc534ca440b /mnt/dent
! mountpoint /mnt/dent && exit 1
#sudo -n mount -o remount,ro /mnt/dent
_messagePlain_nominal 'attempt: copy: hint'
#sudo -n dd if=/dev/zero of=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M
if type -p 'pigz' > /dev/null 2>&1 || type -p 'gzip' > /dev/null 2>&1
then
sudo -n gzip -d -c /mnt/dent/hint_bak.gz | sudo -n dd of=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M
else
sudo cat /mnt/dent/hint_bak | sudo -n dd of=/dev/disk/by-uuid/469457fc-293f-46ec-92da-27b5d0c36b17 bs=1M
fi
sync
#_messagePlain_nominal 'attempt: mount: rw: bulk'
#sudo -n mkdir -p /mnt/bulk
#! mountpoint /mnt/bulk && sudo -n mount -o ro /dev/disk/by-uuid/f1edb7fb-13b1-4c97-91d2-baf50e6d65d8 /mnt/bulk
#! mountpoint /mnt/bulk && exit 1
#sudo -n mount -o remount,rw /mnt/bulk
#_messagePlain_nominal 'attempt: copy: bulk'
#sudo -n mkdir -p /mnt/dent/bulk_bak
#[[ ! -e /mnt/dent/bulk_bak ]] && exit 1
#[[ ! -d /mnt/dent/bulk_bak ]] && exit 1
#sudo -n rsync -ax --delete /mnt/dent/bulk_bak/. /mnt/bulk/.
_messagePlain_nominal 'attempt: umount: dent'
sudo -n mount -o remount,ro /mnt/dent
sync
sudo -n umount /mnt/dent
sync
_messagePlain_request 'request: consider restoring /mnt/bulk (not overwritten by default)'
_messageNormal 'done: _____special_live_dent_restore'
return 0
}
#Override (Program).
#Override, cygwin.
# WARNING: Multiple reasons to instead consider direct detection by other commands - ' uname -a | grep -i cygwin > /dev/null 2>&1 ' , ' [[ -e '/cygdrive' ]] ' , etc .
_if_cygwin() {
if uname -a 2>/dev/null | grep -i cygwin > /dev/null 2>&1
then
return 0
fi
return 1
}
# WARNING: What is otherwise considered bad practice may be accepted to reduce substantial MSW/Cygwin inconvenience .
#/usr/local/bin:/usr/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/usr/bin:/usr/lib/lapack:/cygdrive/x:/cygdrive/x/_bin:/cygdrive/x/_bundle:/opt/ansible/bin:/opt/nodejs/current:/opt/testssl:/home/root/bin
#/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/usr/bin:/usr/lib/lapack:/cygdrive/x:/cygdrive/x/_bin:/cygdrive/x/_bundle:/opt/ansible/bin:/opt/nodejs/current:/opt/testssl:/home/root/bin
if [[ "$PATH" == "/cygdrive"* ]] || ( [[ "$PATH" == *"/cygdrive"* ]] && [[ "$PATH" != *"/usr/local/bin"* ]] )
then
if [[ "$PATH" == "/cygdrive"* ]]
then
export PATH=/usr/local/bin:/usr/bin:/bin:"$PATH"
fi
[[ "$PATH" != *"/usr/local/bin"* ]] && export PATH=/usr/local/bin:"$PATH"
[[ "$PATH" != *"/usr/bin"* ]] && export PATH=/usr/bin:"$PATH"
[[ "$PATH" != *"/bin:"* ]] && export PATH=/bin:"$PATH"
fi
# ATTENTION: Workaround - Cygwin Portable - append MSW PATH if reasonable.
# NOTICE: Also see '_test-shell-cygwin' .
# MSWEXTPATH lengths up to 33, 38, are known reasonable values.
# As of 2025-05-20 , a development system, VSCode PowerShell terminal, has been known to impose 45 such lines on MSWEXTPATH , other PowerShell terminal imposed 41 such lines. Limit of 44 lines at the time was exceeded.
if [[ "$MSWEXTPATH" != "" ]] && ( [[ "$PATH" == *"/cygdrive"* ]] || [[ "$PATH" == "/cygdrive"* ]] ) && [[ "$convertedMSWEXTPATH" == "" ]] && _if_cygwin
then
if [[ $(echo "$MSWEXTPATH" | grep -o ';' | wc -l | tr -dc '0-9') -le 99 ]] && [[ $(echo "$PATH" | grep -o ':' | wc -l | tr -dc '0-9') -le 99 ]]
then
export convertedMSWEXTPATH=$(cygpath -p "$MSWEXTPATH")
export PATH=/usr/bin:"$convertedMSWEXTPATH":"$PATH"
fi
fi
# ATTENTION: Workaround - Cygwin Portable - change directory to current directory as detected by 'ubcp.cmd' .
if [[ "$CWD" != "" ]] && [[ "$cygwin_CWD_onceOnly_done" != 'true' ]] && uname -a | grep -i cygwin > /dev/null 2>&1
then
! cd "$CWD" && exit 1
export cygwin_CWD_onceOnly_done='true'
fi
# ATTENTION: Workaround - Cygwin Portable - symlink home directory if nonexistent .
# https://stackoverflow.com/questions/39551802/how-to-fix-cygwin-using-wrong-ssh-directory-no-matter-what-i-do
# 'OpenSSH never honors $HOME.'
# https://sourceware.org/legacy-ml/cygwin/2016-06/msg00404.html
# 'OpenSSH never honors $HOME.'
# https://cygwin.com/cygwin-ug-net/ntsec.html
if [[ "$HOME" == "/home/root" ]] && [[ ! -e /home/"$USER" ]] && _if_cygwin
then
ln -s --no-target-directory "/home/root" /home/"$USER" > /dev/null 2>&1
fi
# Forces Cygwin symlinks to best compatibility. Should be set by default elsewhere. Use sparingly only if necessary (eg. _setup_ubcp) .
_force_cygwin_symlinks() {
! _if_cygwin && return 0
[[ "$CYGWIN" != *"winsymlinks:lnk"* ]] && export CYGWIN="winsymlinks:lnk ""$CYGWIN"
}
# ATTENTION: User must launch "tmux" (no parameters) in a graphical Cygwin terminal.
# Launches graphical application through "tmux new-window" if available.
# https://superuser.com/questions/531787/starting-windows-gui-program-in-windows-through-cygwin-sshd-from-ssh-client
_workaround_cygwin_tmux() {
if pgrep -u "$USER" ^tmux$ > /dev/null 2>&1
then
tmux new-window "$@"
return "$?"
fi
"$@"
return "$?"
}
# DANGER: Severely differing functionality. Intended only to stand in for "ip addr show" and similar.
if ! type ip > /dev/null 2>&1 && type 'ipconfig' > /dev/null 2>&1 && uname -a | grep -i cygwin > /dev/null 2>&1
then
ip() {
if [[ "$1" == "addr" ]] && [[ "$2" == "show" ]]
then
ipconfig
return $?
fi
return 1
}
fi
if _if_cygwin
then
# ATTRIBUTION-AI: ChatGPT 4.5-preview 2025-04-11 with knowledge ubiquitous_bash, etc
# Prioritizes native git binaries if available. Mostly a disadvantage over the Cygwin/MSW git binaries, but adds more usable git-lfs , and works surprisingly well, apparently still defaulting to: Cygwin HOME '.gitconfig' , Cygwin '/usr/bin/ssh' , correctly understanding the overrides of '_gitBest' , etc.
# Alternatives:
# git-lfs compiled for Cygwin/MSW - requires installing 'go' compiler for Cygwin/MSW
# git fetch commands - manual effort
# wrapper script to detect git lfs error and retry with subsequent separate fetch - technically possible
# avoid git-lfs - usually sufficient
_override_msw_git() {
local git_path="/cygdrive/c/Program Files/Git/cmd"
# Optionally iterate through additional drive letters:
# for drive in c ; do
# for drive in c d e f g h i j k l m n o p q r s t u v w D E F G H I J K L M N O P Q R S T U V W ; do
# local git_path="/cygdrive/${drive}/Program Files/Git/cmd"
# if [ -d "${git_path}" ]; then
# break
# fi
# done
[ -d "$git_path" ] || return 0 # Return quietly if the git_path is not a directory
# ATTENTION: To use with 'ops.sh' or similar if necessary, appropriate, and safe.
export PATH_pre_override_git="$PATH"
local path_entry entry IFS=':'
local new_path=""
for entry in $PATH ; do
# Skip adding if this entry matches git_path exactly
[ "$entry" = "$git_path" ] && continue
# Append current entry to the new_path
if [ -z "$new_path" ]; then
new_path="$entry"
else
new_path="${new_path}:${entry}"
fi
done
# Finally, explicitly prepend the git path
export PATH="${git_path}:${new_path}"
#( _messagePlain_probe_var PATH >&2 ) > /dev/null
#( _messagePlain_probe_var PATH_pre_override_git >&2 ) > /dev/null
# CAUTION: DANGER: MSW native git binaries can perceive 'parent directories' outside the 'root' directory provided by Cygwin, equivalent to calling git binaries through remote (eg. SSH, etc) commands to a filesystem encapsulating a ChRoot !
# This function limits that behavior, especially for 'ubiquitous_bash' projects with MSW installers shipping standalone 'ubcp' environments.
_override_msw_git_CEILING() {
# On the unusual occasion "$scriptLocal" is defined as something other than "$scriptAbsoluteFolder"/_local, the 'ubcp' directory is not expected to have been included as a standard subdirectory under any other definition of "$scriptLocal" . Since this information is only used to add redundant configuration (ie. directories are not created, etc), no issues should be possible.
#current_script_ubcp_msw=$(cygpath -w "$scriptLocal")
current_script_ubcp_msw=$(cygpath -w "$scriptAbsoluteFolder"/_local)
current_script_ubcp_msw_escaped="${current_script_ubcp_msw//\\/\\\\}"
current_script_ubcp_msw_slash="${current_script_ubcp_msw//\\/\/}"
# ONLY for the MSW git binaries override case (if "$git_path" is not valid, this function will already return before this)
export GIT_CEILING_DIRECTORIES="/home/root/.ubcore/ubiquitous_bash;/home/root/.ubcore;/home/root;/cygdrive;/cygdrive/d/a/ubiquitous_bash/ubiquitous_bash;/cygdrive/c/a/ubiquitous_bash/ubiquitous_bash;C:\core\infrastructure\ubcp\cygwin;C:\q\p\zCore\infrastructure\ubiquitous_bash\_local\ubcp\cygwin;C:\core\infrastructure\extendedInterface\_local\ubcp;C:\core\infrastructure\ubDistBuild\_local\ubcp"
[[ "$scriptAbsoluteFolder" != "" ]] && export GIT_CEILING_DIRECTORIES="$GIT_CEILING_DIRECTORIES"';'"$current_script_ubcp_msw"
}
#export -f _override_msw_git_CEILING
_override_msw_git_CEILING
}
# CAUTION: Early in the script for a reason! Changing the PATH drastically later has been known to cause WSL 'bash' to override Cygwin 'bash' with very obviously unpredictable results.
# ATTENTION: There would be a '_test' function in 'ubiquitous_bash' for this, but the state of 'wsl' which may not be installed with 'ubdist', etc, is not necessarily predictable enough for a simple PASS/FAIL .
#if [[ "$1" != "_setupUbiquitous" ]] && [[ "$ub_under_setupUbiquitous" != "true" ]]
#then
_override_msw_git
#_override_msw_git_CEILING
#fi
# ATTRIBUTION-AI: ChatGPT 4.5-preview 2025-04-11 with knowledge ubiquitous_bash, etc (partially)
# ATTRIBUTION-AI: ChatGPT 4o 2025-04-12 web search (partially)
# ATTRIBUTION-AI: ChatGPT o3-mini-high 2025-04-12
_write_configure_git_safe_directory_if_admin_owned_sequence() {
local functionEntryPWD="$PWD"
# DUBIOUS
local functionEntry_GIT_DIR="$GIT_DIR"
local functionEntry_GIT_WORK_TREE="$GIT_WORK_TREE"
local functionEntry_GIT_INDEX_FILE="$GIT_INDEX_FILE"
local functionEntry_GIT_OBJECT_DIRECTORY="$GIT_OBJECT_DIRECTORY"
#local functionEntry_GIT_ALTERNATE_OBJECT_DIRECTORIES="$GIT_ALTERNATE_OBJECT_DIRECTORIES"
local functionEntry_GIT_CONFIG="$GIT_CONFIG"
local functionEntry_GIT_CONFIG_GLOBAL="$GIT_CONFIG_GLOBAL"
local functionEntry_GIT_CONFIG_SYSTEM="$GIT_CONFIG_SYSTEM"
local functionEntry_GIT_CONFIG_NOSYSTEM="$GIT_CONFIG_NOSYSTEM"
#local functionEntry_GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"
#local functionEntry_GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"
#local functionEntry_GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE"
#local functionEntry_GIT_COMMITTER_NAME="$GIT_COMMITTER_NAME"
#local functionEntry_GIT_COMMITTER_EMAIL="$GIT_COMMITTER_EMAIL"
#local functionEntry_GIT_COMMITTER_DATE="$GIT_COMMITTER_DATE"
#local functionEntry_GIT_EDITOR="$GIT_EDITOR"
#local functionEntry_GIT_PAGER="$GIT_PAGER"
local functionEntry_GIT_NAMESPACE="$GIT_NAMESPACE"
local functionEntry_GIT_CEILING_DIRECTORIES="$GIT_CEILING_DIRECTORIES"
local functionEntry_GIT_DISCOVERY_ACROSS_FILESYSTEM="$GIT_DISCOVERY_ACROSS_FILESYSTEM"
#local functionEntry_GIT_SSL_NO_VERIFY="$GIT_SSL_NO_VERIFY"
#local functionEntry_GIT_SSH="$GIT_SSH"
#local functionEntry_GIT_SSH_COMMAND="$GIT_SSH_COMMAND"
git config --global --add safe.directory "$1"
#if [[ $(type -p git) != '/usr/bin/git' ]]
#then
##git config --global --add safe.directory "$2"
git config --global --add safe.directory "$3"
git config --global --add safe.directory "$4"
#fi
cd "$functionEntryPWD"
# DUBIOUS
GIT_DIR="$functionEntry_GIT_DIR"
GIT_WORK_TREE="$functionEntry_GIT_WORK_TREE"
GIT_INDEX_FILE="$functionEntry_GIT_INDEX_FILE"
GIT_OBJECT_DIRECTORY="$functionEntry_GIT_OBJECT_DIRECTORY"
#GIT_ALTERNATE_OBJECT_DIRECTORIES="$functionEntry_GIT_ALTERNATE_OBJECT_DIRECTORIES"
GIT_CONFIG="$functionEntry_GIT_CONFIG"
GIT_CONFIG_GLOBAL="$functionEntry_GIT_CONFIG_GLOBAL"
GIT_CONFIG_SYSTEM="$functionEntry_GIT_CONFIG_SYSTEM"
GIT_CONFIG_NOSYSTEM="$functionEntry_GIT_CONFIG_NOSYSTEM"
#GIT_AUTHOR_NAME="$functionEntry_GIT_AUTHOR_NAME"
#GIT_AUTHOR_EMAIL="$functionEntry_GIT_AUTHOR_EMAIL"
#GIT_AUTHOR_DATE="$functionEntry_GIT_AUTHOR_DATE"
#GIT_COMMITTER_NAME="$functionEntry_GIT_COMMITTER_NAME"
#GIT_COMMITTER_EMAIL="$functionEntry_GIT_COMMITTER_EMAIL"
#GIT_COMMITTER_DATE="$functionEntry_GIT_COMMITTER_DATE"
#GIT_EDITOR="$functionEntry_GIT_EDITOR"
#GIT_PAGER="$functionEntry_GIT_PAGER"
GIT_NAMESPACE="$functionEntry_GIT_NAMESPACE"
GIT_CEILING_DIRECTORIES="$functionEntry_GIT_CEILING_DIRECTORIES"
GIT_DISCOVERY_ACROSS_FILESYSTEM="$functionEntry_GIT_DISCOVERY_ACROSS_FILESYSTEM"
#GIT_SSL_NO_VERIFY="$functionEntry_GIT_SSL_NO_VERIFY"
#GIT_SSH="$functionEntry_GIT_SSH"
#GIT_SSH_COMMAND="$functionEntry_GIT_SSH_COMMAND"
return 0
}
# ATTRIBUTION-AI: ChatGPT 4.5-preview 2025-04-11 with knowledge ubiquitous_bash, etc (partially)
# CAUTION: NOT sufficient to call this function only during installation (as Administrator, which is what normally causes this issue). If the user subsequently installs native 'git for Windows', additional '.gitconfig' entries are needed, with the different MSWindows native style path format.
# Historically this was apparently at least mostly not necessary until prioritizing native git binaries (if available) instead of relying on Cygwin/MSW git binaries.
_write_configure_git_safe_directory_if_admin_owned() {
local current_path="$1"
local win_path win_path_escaped win_path_slash cygwin_path
win_path="$(cygpath -w "$current_path")"
#cygwin_path="$(cygpath -u "$current_path")" # explicit Cygwin POSIX path
win_path_escaped="${win_path//\\/\\\\}"
win_path_slash="${win_path//\\/\/}"
# Single call to verify Administrators ownership explicitly (fast Windows API call)
local owner_line
owner_line="$(icacls "$win_path" 2>/dev/null)"
if [[ "$owner_line" != *"BUILTIN\\Administrators"* ]]; then
# Not Administrators-owned, no further action needed, immediate return
return 0
fi
# Read "$HOME"/.gitconfig just once (efficient builtin file reading)
local gitconfig_content
if [[ -e "$HOME"/.gitconfig ]]; then
gitconfig_content="$(< "$HOME"/.gitconfig)"
## Check 1: Exact Windows path (C:\...)
#if [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path"* ]]; then
#return 0
#fi
## Check 2: Double-backslash-escaped Windows path (C:\\...)
#win_path_escaped="${win_path//\\/\\\\}"
#if [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_escaped"* ]]; then
#return 0
#fi
## Check 3: Normal-slash Windows path (C:/...)
#win_path_slash="${win_path//\\/\/}"
#if [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_slash"* ]]; then
#return 0
#fi
## Check 4: Original Cygwin POSIX path (/cygdrive/c/...)
#if [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $cygwin_path"* ]]; then
#return 0
#fi
#( [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path"* ]] || [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_escaped"* ]] || [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_slash"* ]] ) && ( [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $cygwin_path"* ]] ) && return 0
# Slightly more performance efficient. No expected scenario in which a MSW path has been added but a UNIX path has not.
( [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path"* ]] || [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_escaped"* ]] || [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $win_path_slash"* ]] ) && return 0
cygwin_path="$(cygpath -u "$current_path")" # explicit Cygwin POSIX path
( [[ "$gitconfig_content" == *"[safe]"* && "$gitconfig_content" == *"directory = $cygwin_path"* ]] ) && return 0
fi
# Explicit message clearly communicating safe-configuration action for transparency
#echo "Administrators ownership detected; configuring git safe.directory entry."
# perform safe git configuration exactly once after all efficient checks
# CAUTION: Tested to create functionally identical log entries through both '/usr/bin/git' and native git binaries. Ensure that remains the case if making any changes.
#"$scriptAbsoluteLocation" _write_configure_git_safe_directory_if_admin_owned_sequence "$cygwin_path" "$win_path_escaped" "$win_path_slash" "$win_path"
( _write_configure_git_safe_directory_if_admin_owned_sequence "$cygwin_path" "$win_path_escaped" "$win_path_slash" "$win_path" )
}
# Must be later, after set global variable "$scriptAbsoluteFolder" .
#_write_configure_git_safe_directory_if_admin_owned "$scriptAbsoluteFolder"
# NOTICE: Recent versions of Cygwin seem to have replaced or omitted '/usr/bin/gpg.exe', possibly in favor of a symlink to '/usr/bin/gpg2.exe' .
# CAUTION: This override is specifically to ensure availability of 'gpg' binary through a function, but that could have the effect of presenting an incorrect gpg2 CLI interface to software expecting a gpg1 CLI interface.
# In practice, Debian Linux seem to impose gpg v2 as the CLI interface for gpg - 'gpg --version' responds v2 .
# WARNING: All of which is a good reason to always automatically prefer a specified major version binary of gpg (ie. gpg2) in other software.
if ! type -p gpg > /dev/null && type -p gpg2 > /dev/null
then
gpg() {
gpg2 "$@"
}
fi
# WARNING: Since MSW/Cygwin is hardly suitable for mounting UNIX/tmpfs/ramfs/etc filesystems, 'mountpoint' 'safety checks' are merely disabled.
mountpoint() {
true
}
losetup() {
false
}
tc() {
false
}
wondershaper() {
false
}
ionice() {
false
}
# ATTENTION: Sets the priority for '_wsl' as well as 'u' shortcuts. Override with '_bashrc' or similar as desired (eg. replace 'ubdist_embedded' with some specialized 3D printer firwmare/klipper dist/OS, etc).
_wsl() {
local currentBin_wsl
#currentBin_wsl=$(type -p wsl)
currentBin_wsl="wsl"
if ( [[ "$1" != "-"* ]] || [[ "$1" == "-u" ]] || [[ "$1" == "-e" ]] || [[ "$1" == "--exec" ]] ) && ( [[ "$1" != "-d" ]] || [[ "$2" != "-d" ]] || [[ "$3" != "-d" ]] || [[ "$4" != "-d" ]] || [[ "$5" != "-d" ]] || [[ "$6" != "-d" ]] )
then