-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulle-bashfunctions-all.sh
executable file
·6637 lines (5083 loc) · 115 KB
/
mulle-bashfunctions-all.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
#
# Copyright (c) 2015-2021 Nat! - Mulle kybernetiK
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Mulle kybernetiK nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#
if ! [ ${MULLE_BASHGLOBAL_SH+x} ]
then
MULLE_BASHGLOBAL_SH='included'
DEFAULT_IFS="${IFS}" # as early as possible
if [ ${ZSH_VERSION+x} ]
then
setopt sh_word_split
setopt POSIX_ARGZERO
set -o GLOB_SUBST # neede for [[ $i == $pattern ]]
fi
if [ -z "${MULLE_EXECUTABLE:-}" ]
then
MULLE_EXECUTABLE="${BASH_SOURCE[0]:-${(%):-%x}}"
case "${MULLE_EXECUTABLE##*/}" in
mulle-bash*.sh)
MULLE_EXECUTABLE="$0"
;;
esac
fi
case "${MULLE_EXECUTABLE##*/}" in
mulle-bash*.sh)
echo "MULLE_EXECUTABLE fail" >&2
exit 1
;;
esac
if [ -z "${MULLE_EXECUTABLE_NAME:-}" ]
then
MULLE_EXECUTABLE_NAME="${MULLE_EXECUTABLE##*/}"
fi
if [ -z "${MULLE_USER_PWD:-}" ]
then
MULLE_USER_PWD="${PWD}"
export MULLE_USER_PWD
fi
MULLE_USAGE_NAME="${MULLE_USAGE_NAME:-${MULLE_EXECUTABLE_NAME}}"
MULLE_EXECUTABLE_PWD="${PWD}"
MULLE_EXECUTABLE_FAIL_PREFIX="${MULLE_EXECUTABLE_NAME}"
MULLE_EXECUTABLE_PID="$$"
if [ -z "${MULLE_UNAME:-}" ]
then
case "${BASH_VERSION:-}" in
[0123]*)
MULLE_UNAME="`uname | tr '[:upper:]' '[:lower:]'`"
;;
*)
MULLE_UNAME="${_MULLE_UNAME:-`uname`}"
if [ ${ZSH_VERSION+x} ]
then
MULLE_UNAME="${MULLE_UNAME:l}"
else
MULLE_UNAME="${MULLE_UNAME,,}"
fi
;;
esac
MULLE_UNAME="${MULLE_UNAME%%_*}"
MULLE_UNAME="${MULLE_UNAME%[36][24]}" # remove 32 64 (hax)
case "${MULLE_UNAME}" in
linux)
MULLE_UNAME="android"
if [ -r /proc/sys/kernel/osrelease ]
then
read -r MULLE_UNAME < /proc/sys/kernel/osrelease
case "${MULLE_UNAME}" in
*-[Mm]icrosoft-*)
MULLE_UNAME="windows" # wsl2, this is super slow on NTFS
;;
*-[Mm]icrosoft)
MULLE_UNAME="windows" # wsl1
;;
*-android-*|*-android)
MULLE_UNAME="android"
;;
*)
MULLE_UNAME="linux"
;;
esac
fi
;;
msys|cygwin)
MULLE_UNAME='msys'
;;
esac
fi
if [ "${MULLE_UNAME}" = "windows" ]
then
MULLE_EXE_EXTENSION=".exe"
fi
if [ -z "${MULLE_HOSTNAME:-}" ]
then
MULLE_HOSTNAME="${HOSTNAME}"
case "${MULLE_UNAME}" in
'mingw'|'msys'|'sunos')
MULLE_HOSTNAME="${MULLE_HOSTNAME:-`hostname 2> /dev/null`}"
;;
*) # on AARCH hostname does not exist anymore (sigh)
MULLE_HOSTNAME="${MULLE_HOSTNAME:-`hostname -s 2> /dev/null`}"
;;
esac
MULLE_HOSTNAME="${MULLE_HOSTNAME:-`grep -E -v '^#' "/etc/hostname" 2> /dev/null`}"
MULLE_HOSTNAME="${MULLE_HOSTNAME:-nautilus}"
case "${MULLE_HOSTNAME}" in
\.*)
MULLE_HOSTNAME="_${MULLE_HOSTNAME}"
;;
esac
fi
if [ -z "${MULLE_USERNAME:-}" ]
then
MULLE_USERNAME="${MULLE_USERNAME:-${USERNAME}}" # mingw
MULLE_USERNAME="${MULLE_USERNAME:-${USER}}"
MULLE_USERNAME="${MULLE_USERNAME:-${LOGNAME}}"
MULLE_USERNAME="${MULLE_USERNAME:-`id -nu 2> /dev/null`}"
MULLE_USERNAME="${MULLE_USERNAME:-cptnemo}"
fi
fi
if ! [ ${MULLE_BASHLOADER_SH+x} ]
then
MULLE_BASHLOADER_SH='included'
r_uppercase()
{
case "${BASH_VERSION:-}" in
[0123]*)
RVAL="`printf "%s" "$1" | tr '[:lower:]' '[:upper:]'`"
;;
*)
if [ ${ZSH_VERSION+x} ]
then
RVAL="${1:u}"
else
RVAL="${1^^}"
fi
;;
esac
}
r_include_path()
{
local executable="$1"
local filename="$2"
local libexec_define="$3"
local value
if [ ${ZSH_VERSION+x} ]
then
value="${(P)libexec_define}"
else
value="${!libexec_define}"
fi
if [ -z "${value}" ]
then
value="`"${executable}" libexec-dir`" || fail "Could not execute ${executable} libexec-dir successfully ($PATH)"
printf -v "${libexec_define}" "%s" "${value}"
eval export "${libexec_define}"
fi
RVAL="${value}/${filename}"
}
include_executable_library()
{
local includeguard="$4"
local value
if [ ${ZSH_VERSION+x} ]
then
value="${(P)includeguard}"
else
value="${!includeguard}"
fi
if [ ! -z "${value}" ]
then
return
fi
r_include_path "$@"
. "${RVAL}" || exit 1
printf -v "${includeguard}" 'YES'
}
__parse_include_specifier()
{
local s="$1"
local default_namespace="${2:-mulle}" # default namespace (mulle)
local name
name="${s##*::}"
local upper_name
r_identifier "${name}"
r_uppercase "${RVAL}"
upper_name="${RVAL}"
if [ "${name}" = "${s}" ]
then
if [ "${default_namespace}" = "mulle" ]
then
_executable="mulle-bashfunctions"
_filename="mulle-${name}.sh"
_libexecdir="MULLE_BASHFUNCTIONS_LIBEXEC_DIR"
_includeguard="MULLE_${upper_name}_SH"
return 0
fi
r_identifier "${default_namespace}"
upper_default_namespace="${RVAL}"
_executable="${default_namespace}-bashfunctions"
_filename="${default_namespace}-${name}.sh"
_libexecdir="${upper_default_namespace}_BASHFUNCTIONS_LIBEXEC_DIR"
_includeguard="${upper_default_namespace}_${upper_name}_SH"
return 0
fi
local tool
tool="${s%::*}"
local namespace
case "${tool}" in
*-*)
namespace="${tool%%-*}"
tool="${tool#*-}"
;;
*)
namespace="${default_namespace}"
;;
esac
r_concat "${namespace}" "${tool}" "-"
tool="${RVAL}"
local upper_tool
r_identifier "${tool}"
r_uppercase "${RVAL}"
upper_tool="${RVAL}"
_executable="${tool}"
_filename="${tool}-${name}.sh"
_libexecdir="${upper_tool}_LIBEXEC_DIR"
_includeguard="${upper_tool}_${upper_name}_SH"
}
include()
{
local _executable
local _filename
local _libexecdir
local _includeguard
__parse_include_specifier "$@"
include_executable_library "${_executable}" \
"${_filename}" \
"${_libexecdir}" \
"${_includeguard}"
}
__bashfunctions_loader()
{
if [ -z "${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}" -a ! -z "$0" ]
then
local tmp
tmp="${0%/*}"
if [ -f "${tmp}/mulle-bashfunctions.sh" ]
then
MULLE_BASHFUNCTIONS_LIBEXEC_DIR="${tmp}"
fi
fi
[ -z "${MULLE_BASHFUNCTIONS_LIBEXEC_DIR}" ] \
&& echo "MULLE_BASHFUNCTIONS_LIBEXEC_DIR not set" >&2 \
&& exit 1
:
}
__bashfunctions_loader || exit 1
fi
if ! [ ${MULLE_COMPATIBILITY_SH+x} ]
then
MULLE_COMPATIBILITY_SH='included'
function shell_enable_pipefail()
{
set -o pipefail
}
function shell_disable_pipefail()
{
set +o pipefail
}
function shell_is_pipefail_enabled()
{
case "$-" in
*f*)
return 1
;;
esac
return 0
}
function shell_enable_extglob()
{
if [ ${ZSH_VERSION+x} ]
then
setopt kshglob
setopt bareglobqual
else
shopt -s extglob
fi
}
function shell_disable_extglob()
{
if [ ${ZSH_VERSION+x} ]
then
unsetopt bareglobqual
unsetopt kshglob
else
shopt -u extglob
fi
}
function shell_is_extglob_enabled()
{
if [ ${ZSH_VERSION+x} ]
then
[[ -o kshglob ]]
return $?
fi
shopt -q extglob
}
function shell_enable_nullglob()
{
if [ ${ZSH_VERSION+x} ]
then
setopt nullglob
else
shopt -s nullglob
fi
}
function shell_disable_nullglob()
{
if [ ${ZSH_VERSION+x} ]
then
unsetopt nullglob
else
shopt -u nullglob
fi
}
function shell_is_nullglob_enabled()
{
if [ ${ZSH_VERSION+x} ]
then
[[ -o nullglob ]]
return $?
fi
shopt -q nullglob
}
function shell_enable_glob()
{
if [ ${ZSH_VERSION+x} ]
then
unsetopt noglob
else
set +f
fi
}
function shell_disable_glob()
{
if [ ${ZSH_VERSION+x} ]
then
setopt noglob
else
set -f
fi
}
function shell_is_glob_enabled()
{
if [ ${ZSH_VERSION+x} ]
then
if [[ -o noglob ]]
then
return 1
fi
return 0
fi
case "$-" in
*f*)
return 1
;;
esac
return 0
}
function shell_is_function()
{
if [ ${ZSH_VERSION+x} ]
then
case "`type "$1" `" in
*function*)
return 0
;;
esac
return 1
fi
[ "`type -t "$1"`" = "function" ]
return $?
}
function shell_is_builtin_command()
{
if [ ${ZSH_VERSION+x} ]
then
case "`LC_C=C whence -w "$1" `" in
*:*builtin)
return 0
;;
esac
return 1
fi
[ "`type -t "$1"`" = "builtin" ]
return $?
}
function r_shell_indirect_expand()
{
local key="$1"
if [ ${ZSH_VERSION+x} ]
then
RVAL="${(P)key}"
else
RVAL="${!key}"
fi
}
function shell_is_variable_defined()
{
local key="$1"
if [ ${ZSH_VERSION+x} ]
then
[[ -n ${(P)key} ]]
return $?
fi
[ "${!key}" ]
}
unalias -a
if [ ${ZSH_VERSION+x} ]
then
setopt aliases
alias .for="setopt noglob; for"
alias .foreachline="setopt noglob; IFS=$'\n'; for"
alias .foreachword="setopt noglob; IFS=' '$'\t'$'\n'; for"
alias .foreachitem="setopt noglob; IFS=','; for"
alias .foreachpath="setopt noglob; IFS=':'; for"
alias .foreachpathcomponent="set -f; IFS='/'; for"
alias .foreachcolumn="setopt noglob; IFS=';'; for"
alias .foreachfile="unsetopt noglob; setopt nullglob; IFS=' '$'\t'$'\n'; for"
alias .do="do
unsetopt noglob; unsetopt nullglob; IFS=' '$'\t'$'\n'"
alias .done="done;unsetopt noglob; unsetopt nullglob; IFS=' '$'\t'$'\n'"
else
shopt -s expand_aliases
alias .for="set -f; for"
alias .foreachline="set -f; IFS=$'\n'; for"
alias .foreachword="set -f; IFS=' '$'\t'$'\n'; for"
alias .foreachitem="set -f; IFS=','; for"
alias .foreachpath="set -f; IFS=':'; for"
alias .foreachpathcomponent="set -f; IFS='/'; for"
alias .foreachcolumn="set -f; IFS=';'; for"
alias .foreachfile="set +f; shopt -s nullglob; IFS=' '$'\t'$'\n'; for"
alias .do="do
set +f; shopt -u nullglob; IFS=' '$'\t'$'\n'"
alias .done="done;set +f; shopt -u nullglob; IFS=' '$'\t'$'\n'"
fi
alias .break="break"
alias .continue="continue"
shell_enable_extglob
shell_enable_pipefail
fi
:
if ! [ ${MULLE_LOGGING_SH+x} ]
then
MULLE_LOGGING_SH='included'
_log_printf()
{
local format="$1" ; shift
if [ -z "${MULLE_EXEKUTOR_LOG_DEVICE:-}" ]
then
printf "${format}" "$@" >&2
else
printf "${format}" "$@" > "${MULLE_EXEKUTOR_LOG_DEVICE}"
fi
}
MULLE_LOG_ERROR_PREFIX=" error: "
MULLE_LOG_FAIL_ERROR_PREFIX=" fatal error: "
_log_error()
{
if [ "${MULLE_FLAG_LOG_ERROR:-YES}" = 'NO' ]
then
return
fi
_log_printf "${C_ERROR}${MULLE_EXECUTABLE_FAIL_PREFIX}${MULLE_LOG_ERROR_PREFIX}${C_ERROR_TEXT}%b${C_RESET}\n" "$*"
}
_log_fail()
{
if [ "${MULLE_FLAG_LOG_ERROR:-YES}" = 'NO' ]
then
return
fi
_log_printf "${C_ERROR}${MULLE_EXECUTABLE_FAIL_PREFIX}${MULLE_LOG_FAIL_ERROR_PREFIX}${C_ERROR_TEXT}%b${C_RESET}\n" "$*"
}
_log_warning()
{
if [ "${MULLE_FLAG_LOG_TERSE:-}" != 'YES' ]
then
_log_printf "${C_WARNING}%b${C_RESET}\n" "$*"
fi
}
_log_info()
{
if ! [ "${MULLE_FLAG_LOG_TERSE:-}" = 'YES' -o "${MULLE_FLAG_LOG_TERSE:-}" = 'WARN' ]
then
_log_printf "${C_INFO}%b${C_RESET}\n" "$*"
fi
}
_log_verbose()
{
if [ "${MULLE_FLAG_LOG_VERBOSE:-}" = 'YES' ]
then
_log_printf "${C_VERBOSE}%b${C_RESET}\n" "$*"
fi
}
_log_fluff()
{
if [ "${MULLE_FLAG_LOG_FLUFF:-}" = 'YES' ]
then
_log_printf "${C_FLUFF}%b${C_RESET}\n" "$*"
else
_log_debug "$@"
fi
}
_log_setting()
{
if [ "${MULLE_FLAG_LOG_SETTINGS:-}" = 'YES' ]
then
_log_printf "${C_SETTING}%b${C_RESET}\n" "$*"
fi
}
_log_debug()
{
if [ "${MULLE_FLAG_LOG_DEBUG:-}" != 'YES' ]
then
return
fi
case "${MULLE_UNAME}" in
'linux'|'windows')
_log_printf "${C_DEBUG}$(date "+%s.%N") %b${C_RESET}\n" "$*"
;;
*)
_log_printf "${C_DEBUG}$(date "+%s") %b${C_RESET}\n" "$*"
;;
esac
}
_log_entry()
{
if [ "${MULLE_FLAG_LOG_DEBUG:-}" != 'YES' ]
then
return
fi
local functionname="$1" ; shift
local args
local truncate
if [ $# -ne 0 ]
then
functionname="${functionname} " # add space for later
truncate="$1"
if [ "${#truncate}" -gt 200 ]
then
truncate="${truncate:0:197}..."
fi
args="'${truncate}'"
shift
fi
while [ $# -ne 0 ]
do
truncate="$1"
if [ "${#truncate}" -gt 200 ]
then
truncate="${truncate:0:197}..."
fi
args="${args}, '${truncate}'"
shift
done
case "${MULLE_UNAME}" in
'linux'|'windows')
_log_printf "${C_DEBUG}$(date "+%s.%N") %s%s${C_RESET}\n" "${functionname}" "${args}"
;;
*)
_log_printf "${C_DEBUG}$(date "+%s") %s%s${C_RESET}\n" "${functionname}" "${args}"
;;
esac
}
_log_trace()
{
case "${MULLE_UNAME}" in
linux)
_log_printf "${C_TRACE}$(date "+%s.%N") %b${C_RESET}\n" "$*"
;;
*)
_log_printf "${C_TRACE}$(date "+%s") %b${C_RESET}\n" "$*"
;;
esac
}
alias log_debug='_log_debug'
alias log_entry='_log_entry'
alias log_error='_log_error'
alias log_fluff='_log_fluff'
alias log_info='_log_info'
alias log_setting='_log_setting'
alias log_trace='_log_trace'
alias log_verbose='_log_verbose'
alias log_warning='_log_warning'
log_set_trace_level()
{
alias log_debug='_log_debug'
alias log_entry='_log_entry'
alias log_error='_log_error'
alias log_fluff='_log_fluff'
alias log_info='_log_info'
alias log_setting='_log_setting'
alias log_trace='_log_trace'
alias log_verbose='_log_verbose'
alias log_warning='_log_warning'
if [ "${MULLE_FLAG_LOG_DEBUG:-}" != 'YES' ]
then
alias log_entry=': #'
alias log_debug=': #'
fi
if [ "${MULLE_FLAG_LOG_SETTINGS:-}" != 'YES' ]
then
alias log_setting=': #'
fi
if [ "${MULLE_FLAG_LOG_FLUFF:-}" != 'YES' ]
then
if [ "${MULLE_FLAG_LOG_DEBUG:-}" = 'YES' ]
then
alias log_fluff='log_debug'
else
alias log_fluff=': #'
fi
fi
if [ "${MULLE_FLAG_LOG_VERBOSE:-}" != 'YES' ]
then
alias log_verbose=': #'
fi
if [ "${MULLE_FLAG_LOG_TERSE:-}" = 'YES' -o "${MULLE_FLAG_LOG_TERSE:-}" = 'WARN' ]
then
alias log_info=': #'
fi
if [ "${MULLE_FLAG_LOG_TERSE:-}" = 'YES' ]
then
alias log_warning=': #'
fi
:
}
if [ ${ZSH_VERSION+x} ]
then
function caller()
( # sic!
local i="${1:-1}"
set +u
i=$((i+1))
local file=${funcfiletrace[$((i))]%:*}
local line=${funcfiletrace[$((i))]##*:}
local func=${funcstack[$((i + 1))]}
if [ -z "${func## }" ]
then
return 1
fi
printf "%s %s %s\n" "$line" "$func" "${file##*/}"
return 0
) # sic!
fi
stacktrace()
{
case "$-" in
*x*)
return
;;
esac
local i
local line
local max
i=1
max=100
while line="`caller $i`"
do
_log_printf "${C_CYAN}%b${C_RESET}\n" "$i: #${line}"
i=$((i + 1))
[ $i -gt $max ] && break
done
}
function fail()
{
if [ ! -z "$*" ]
then
_log_fail "$@"
fi
if [ "${MULLE_FLAG_LOG_DEBUG:-}" = 'YES' ]
then
stacktrace
fi
exit 1
}
MULLE_INTERNAL_ERROR_PREFIX=" *** internal error ***:"
function _internal_fail()
{
_log_printf "${C_ERROR}${MULLE_EXECUTABLE_FAIL_PREFIX}${MULLE_INTERNAL_ERROR_PREFIX}${C_ERROR_TEXT}%b${C_RESET}\n" "$*"
stacktrace
exit 1
}
_fatal()
{
_internal_fail "$@"
}
logging_reset()
{
printf "%b" "${C_RESET}" >&2
}
logging_trap_install()
{
trap 'logging_reset ; exit 1' TERM INT
}
logging_trap_uninstall()
{
trap - TERM INT
}
logging_initialize_color()
{
case "${TERM:-}" in
dumb)
MULLE_NO_COLOR='YES'
;;
esac
if [ -z "${NO_COLOR:-}" -a "${MULLE_NO_COLOR:-}" != 'YES' ] && [ ! -f /dev/stderr ]
then
C_RESET="\033[0m"
C_RED="\033[0;31m" C_GREEN="\033[0;32m"
C_BLUE="\033[0;34m" C_MAGENTA="\033[0;35m"
C_CYAN="\033[0;36m"
C_BR_RED="\033[0;91m"
C_BR_GREEN="\033[0;92m"
C_BR_BLUE="\033[0;94m"
C_BR_CYAN="\033[0;96m"
C_BR_MAGENTA="\033[0;95m"
C_BOLD="\033[1m"
C_FAINT="\033[2m"
C_UNDERLINE="\033[4m"
C_SPECIAL_BLUE="\033[38;5;39;40m"
if [ "${MULLE_LOGGING_TRAP:-}" != 'NO' ]
then
logging_trap_install
fi
fi
C_RESET_BOLD="${C_RESET}${C_BOLD}"
C_ERROR="${C_BR_RED}${C_BOLD}"
C_WARNING="${C_RED}${C_BOLD}"
C_INFO="${C_CYAN}${C_BOLD}"
C_VERBOSE="${C_GREEN}${C_BOLD}"
C_FLUFF="${C_GREEN}${C_BOLD}"
C_SETTING="${C_GREEN}${C_FAINT}"
C_TRACE="${C_FLUFF}${C_FAINT}"
C_TRACE2="${C_RESET}${C_FAINT}"
C_DEBUG="${C_SPECIAL_BLUE}"
C_ERROR_TEXT="${C_RESET}${C_BR_RED}${C_BOLD}"
}
logging_deinitialize_color()
{
C_RESET=
C_RED=
C_GREEN=
C_BLUE=
C_MAGENTA=
C_CYAN=
C_BR_RED=
C_BR_GREEN=
C_BR_BLUE=
C_BR_CYAN=
C_BR_MAGENTA=
C_BOLD=