-
Notifications
You must be signed in to change notification settings - Fork 0
/
ack
executable file
·831 lines (806 loc) · 24.7 KB
/
ack
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
#!/bin/bash
#
# @author Zeus Intuivo <[email protected]>
#
#
function load_colors() {
[[ -z "${CYAN:-}" ]] && CYAN="\\033[38;5;123m"
[[ -z "${PURPLE_BLUE:-}" ]] && PURPLE_BLUE="\\033[38;5;93m"
[[ -z "${YELLOW226:-}" ]] && YELLOW226="\\033[38;5;226m"
[[ -z "${GRAY241:-}" ]] && GRAY241="\\033[38;5;241m"
[[ -z "${GRAY242:-}" ]] && GRAY242="\\033[38;5;242m"
[[ -z "${GRAY243:-}" ]] && GRAY243="\\033[38;5;243m"
[[ -z "${YELLOW214:-}" ]] && YELLOW214="\\033[38;5;214m"
[[ -z "${RESET:-}" ]] && RESET="\\033[0m"
[[ -z "${RED:-}" ]] && RED="\\033[38;5;1m"
[[ -z "${BRIGHT_BLUE87:-}" ]] && BRIGHT_BLUE87="\\033[38;5;87m"
GRAYEDOUT="\033[01;30m"
RED="\033[01;31m"
GREEN="\033[01;32m"
YELLOW="\033[01;33m"
DARKBLUE="\033[01;34m"
DARKGREEN="\033[38;5;22m"
PURPLE="\033[01;35m"
CYAN="\033[01;36m"
WHITEBOLD="\033[01;37m"
LIGHTGREEN="\033[38;5;83m"
LIGHTPINK="\033[1;204m"
LIGHTYELLOW="\033[38;5;227m"
GREEN_OVER_DARKBLUE="\033[38;5;76m\033[48;5;17m"
YELLOW_OVER_DARKBLUE="\033[38;5;220m\033[48;5;20m"
DARKBLUE_OVER_DARKBLUE="\033[01;34m\033[48;5;20m"
RESET="\033[0m"
} # end load_colors
load_colors
function get_linux_architecture(){
# How to use
# FILE_TO_CALL=$(get_linux_architecture "debian")
# > _debian__64
# > _debian__32
# FILE_TO_CALL=$(get_linux_architecture "${DISTRO}")
#
local system_nick="${1}"
local return_file_to_call=""
if [[ "$(uname -i)" == "x86_64" ]] ; then
{
return_file_to_call="_${system_nick}__64"
}
elif [[ "$(uname -i)" == "i686" ]] ; then
{
return_file_to_call="_${system_nick}__32"
}
elif [[ "$(uname -i)" == "arm64" ]] ; then
{
return_file_to_call="_${system_nick}__arm64"
}
else
{
return_file_to_call="_${system_nick}__$(uname -i)"
warning "ERROR to determine "$(uname -a)" architecture (uname -i) for: <${return_file_to_call}>"
}
fi
if [ -z ${return_file_to_call} ] || [[ "${return_file_to_call}" =~ 'nknown' ]] ; then
{
if [[ "$(uname -a)" =~ 'x86_64' ]] ; then
{
return_file_to_call="_${system_nick}__64"
}
fi
if [[ "$(uname -a)" =~ 'i686' ]] ; then
{
return_file_to_call="_${system_nick}__32"
}
fi
if [[ "$(uname -a)" =~ 'arm64' ]] ; then
{
return_file_to_call="_${system_nick}__arm64"
}
fi
}
fi
echo -n ${return_file_to_call}
return 0
} # end get_linux_architecture
function get_mac_architecture(){
# How to use
# FILE_TO_CALL=$(get_mac_architecture "darwin")
# > _darwin__64
# > _darwin__32
# FILE_TO_CALL=$(get_mac_architecture "${DISTRO}")
#
local system_nick="${1}"
local return_file_to_call=""
if [[ "$(uname -m)" == "x86_64" ]] ; then
{
return_file_to_call="_${system_nick}__64"
}
elif [[ "$(uname -m)" == "i686" ]] ; then
{
return_file_to_call="_${system_nick}__32"
}
elif [[ "$(uname -m)" == "arm64" ]] ; then
{
return_file_to_call="_${system_nick}__arm64"
}
else
{
return_file_to_call="_${system_nick}__$(uname -m)"
warning "ERROR to determine "$(uname -a)" architecture (uname -m) for: <${return_file_to_call}>"
}
fi
if [ -z ${return_file_to_call} ] || [[ "${return_file_to_call}" =~ 'nknown' ]] ; then
{
if [[ "$(uname -a)" =~ 'x86_64' ]] ; then
{
return_file_to_call="_${system_nick}__64"
}
fi
if [[ "$(uname -a)" =~ 'i686' ]] ; then
{
return_file_to_call="_${system_nick}__32"
}
fi
if [[ "$(uname -a)" =~ 'arm64' ]] ; then
{
return_file_to_call="_${system_nick}__arm64"
}
fi
}
fi
echo -n ${return_file_to_call}
return 0
} # end get_mac_architecture
function _get_debian_style_version_number_maybe(){
# Sample use:
# local target_name="ubuntu"
# local _debian_style_version_number_maybe=$(_get_debian_style_version_number_maybe)
# FILE_TO_CALL=$(get_linux_architecture "${target_name}${_debian_style_version_number_maybe}")
#
trap '>&2 echo -e "${RED}" && echo "ERROR failed $0:$LINENO struct_testing _get_debian_style_version_number_maybe() " && >&1 echo -n "" && return 1' ERR
local -i _err=0
local _response=""
local -i linuxversion=0
linuxversion=$(cut -d. -f1 <<< $(cut -d'"' -f2 <<< $(grep VERSION_ID= <<< $(cat /etc/*-release) ) ) )
_err=$?
if [ ${_err} -eq 0 ] && [ ${linuxversion} -gt 0 ] ; then
{
local -i testnumber=0
testnumber=$(( linuxversion + 1 ))
testnumber=$(( testnumber - 1 ))
if [ ${testnumber} -eq ${linuxversion} ] ; then
{
_response=${linuxversion}
echo -n "_${_response}"
return 0
}
fi
}
fi
echo -n "${_response}"
return 1
} # end _get_debian_style_version_number_maybe
function _get_redhat_style_version_number_maybe(){
# Sample use:
# local target_name="fedora"
# local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
# FILE_TO_CALL=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
#
#
trap '>&2 echo -e "${RED}" && echo "ERROR failed $0:$LINENO struct_testing _get_redhat_style_version_number_maybe() " && >&1 echo -n "" && return 1' ERR
local -i _err=0
local _response=""
local -i linuxversion=0
linuxversion=$(cut -d= -f2 <<< $(grep VERSION_ID= <<< $(cat /etc/*-release) ) )
_err=$?
if [ ${_err} -eq 0 ] && [ ${linuxversion} -gt 0 ] ; then
{
local -i testnumber=0
testnumber=$(( linuxversion + 1 ))
testnumber=$(( testnumber - 1 ))
if [ ${testnumber} -eq ${linuxversion} ] ; then
{
_response=${linuxversion}
echo -n "_${_response}"
return 0
}
fi
}
fi
echo -n "${_response}"
return 1
} # end _get_redhat_style_version_number_maybe
function _get_mac_style_version_number_maybe(){
# Sample use:
# local target_name="darwin"
# local _mac_style_version_number_maybe=$(_get_mac_style_version_number_maybe)
# FILE_TO_CALL=$(get_linux_architecture "${target_name}${_mac_style_version_number_maybe}")
#
#
trap '>&2 echo -e "${RED}" && echo "ERROR failed $0:$LINENO struct_testing _get_mac_style_version_number_maybe() " && >&1 echo -n "" && return 1' ERR
local -i _err=0
local _response=""
local -i macversion1=0
local -i macversion2=0
local macversion=0
# macversion=$(cut -d. -f1 <<< $( uname -r ) )
macversion1=$(sw_vers | grep ProductVersion | cut -d: -f2 | xargs | cut -d. -f1 | sed 's/\./_/g' )
_err=$?
if [ ${_err} -eq 0 ] && [ ${macversion1} -gt 0 ] ; then
{
local -i testnumber=0
testnumber=$(( macversion1 + 1 ))
testnumber=$(( testnumber - 1 ))
if [ ${testnumber} -eq ${macversion1} ] ; then
{
macversion2=$(sw_vers | grep ProductVersion | cut -d: -f2 | xargs | cut -d. -f2 | sed 's/\./_/g' )
_err=$?
if [ ${_err} -eq 0 ] && [ ${macversion2} -gt 0 ] ; then
{
local -i testnumber=0
testnumber=$(( macversion2 + 1 ))
testnumber=$(( testnumber - 1 ))
if [ ${testnumber} -eq ${macversion2} ] ; then
{
macversion="${macversion1}_${macversion2}"
_response=${macversion}
echo -n "_${_response}"
return 0
}
fi
}
fi
}
fi
}
fi
echo -n "${_response}"
return 1
} # end _get_mac_style_version_number_maybe
export ACTION=`basename "$0"`
function determine_os_and_run_file() {
# Interface
# How to use
# First implement the target functions
# _fedora__64(){ }
# _fedora__32(){ }
# _ubuntu__64(){ }
# _ubuntu__32(){ }
# _mingw__64(){ }
# _mingw__32(){ }
# _darwin__64(){ }
# _darwin__32(){ }
# Then call this function
# determine_os_and_run_file """${*}"""
# remember to pass the """${*}""" for the parameters to pass
# If will fail is the function has not been implemented with Error message
# of the function that is missing like _archlinux__64
local FILE_TO_CALL_WITH_VERSION=""
local FILE_TO_CALL=""
local PARAMETERS="${*:-}"
local -i DEBUG=0
local -i _err=0
# Check operating systems
# echo ${@}
if [[ "$(uname)" == "Darwin" ]] ; then
{
if (( DEBUG )) ; then
echo "Darwin"
fi
# Do something under Mac OS X platform
# FILE_TO_CALL='_darwin__64'
# PARAMETERS="$@"
local target_name="darwin"
local _mac_style_version_number_maybe=$(_get_mac_style_version_number_maybe)
_err=$?
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_mac_architecture "${target_name}${_mac_style_version_number_maybe}")
}
fi
FILE_TO_CALL=$(get_mac_architecture "${target_name}")
PARAMETERS="$@"
}
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]] ; then
{
if (( DEBUG )) ; then
echo "Linux"
fi
# Do something under GNU/Linux platform
# Determine OS platform
local UNAME=$(uname | tr "[:upper:]" "[:lower:]")
if (( DEBUG )) ; then
echo "UNAME: $UNAME"
fi
local DISTRO=""
local ID=""
local VERSION_ID=""
# If Linux, try to determine specific distribution
if [[ "$UNAME" == "linux" ]]; then
{
# If available, use LSB to identify distribution
if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then
{
if ( command -v lsb_release >/dev/null 2>&1; ); then
{
if (( DEBUG )) ; then
echo "RELEASE Option: 1"
fi
DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'// | head -1)
}
else
{
if (( DEBUG )) ; then
echo "RELEASE Option: 2"
fi
DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1 | head -1)
}
fi
}
else # Otherwise, use release info file
{
if (( DEBUG )) ; then
echo "RELEASE Option: 3"
fi
DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1 | head -1)
}
fi
}
fi
if (( DEBUG )) ; then
echo "DISTRO:$DISTRO"
fi
if [[ -z "$DISTRO" ]]; then # if empty
{
if (( DEBUG )) ; then
echo "DISTRO empty"
fi
# If available, use /etc/os-release to identify distribution
if [ -f /etc/os-release ]; then
{
source /etc/os-release
# file_exists "/etc/os-release"
_assure_success
# source /etc/os-release
# $ echo $ID
# fedora
# $ echo $VERSION_ID
# 17
# $ echo $VERSION
# 17 (Beefy Miracle)
DISTRO=$ID
}
fi
}
fi
if [[ -z "$DISTRO" ]] ; then # if empty
{
echo -e "${RED} ERROR - ${YELLOW220} to determine DISTRO for this linux. uname -a, cat /etc/os-release, lsb_release -i ${RESET}"
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_TO_CALL
unset PARAMETERS
exit 1
}
fi
if [[ "$DISTRO" == *"edora"* ]]; then
{
local target_name="fedora"
local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
_err=$?
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
}
fi
FILE_TO_CALL=$(get_linux_architecture "${target_name}")
PARAMETERS="$@"
}
elif [[ "$DISTRO" == *"untu"* ]]; then
{
# ubuntu lsb_release -i | sed 's/Distributor\ ID://g' = \tUbuntu\n
local target_name="ubuntu"
local _debian_style_version_number_maybe=$(_get_debian_style_version_number_maybe)
_err=$?
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_debian_style_version_number_maybe}")
}
fi
FILE_TO_CALL=$(get_linux_architecture "${target_name}")
PARAMETERS="$@"
}
elif [[ "$DISTRO" == *"bian"* ]]; then
{
local target_name="debian"
local _debian_style_version_number_maybe=$(_get_debian_style_version_number_maybe)
_err=$?
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_debian_style_version_number_maybe}")
}
fi
FILE_TO_CALL=$(get_linux_architecture "${target_name}")
PARAMETERS="$@"
}
else
{
local target_name="${DISTRO}"
local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
_err=$?
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
}
fi
FILE_TO_CALL=$(get_linux_architecture "${target_name}")
PARAMETERS="$@"
}
fi
if (( DEBUG )) ; then
echo "FILE_TO_CALL: $FILE_TO_CALL"
echo "uname -i: $(uname -i)"
fi
# For everything else (or if above failed), just use generic identifier
unset UNAME
unset DISTRO
unset ID
}
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]] ; then
{
# Do something under Windows NT platform
if [[ "$(uname -i)" == "x86_64" ]] ; then
{
# local target_name="${DISTRO}"
# local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
# FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
# FILE_TO_CALL=$(get_linux_architecture "${target_name}")
FILE_TO_CALL='_mingw__64.exe'
PARAMETERS="$*"
}
elif [[ "$(uname -i)" == "i686" ]] ; then
{
# local target_name="${DISTRO}"
# local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
# FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
# FILE_TO_CALL=$(get_linux_architecture "${target_name}")
FILE_TO_CALL='_mingw__32.exe'
PARAMETERS="$*"
}
fi
# nothing here
}
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]] ; then
{
# Do something under Windows NT platform
if [[ "$(uname -i)" == "x86_64" ]] ; then
{
# local target_name="${DISTRO}"
# local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
# FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
# FILE_TO_CALL=$(get_linux_architecture "${target_name}")
FILE_TO_CALL='_mingw__64.exe'
PARAMETERS="$*"
}
elif [[ "$(uname -i)" == "i686" ]] ; then
{
# local target_name="${DISTRO}"
# local _redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
# FILE_TO_CALL_WITH_VERSION=$(get_linux_architecture "${target_name}${_redhat_style_version_number_maybe}")
# FILE_TO_CALL=$(get_linux_architecture "${target_name}")
FILE_TO_CALL='_mingw__32.exe'
PARAMETERS="$*"
}
fi
# nothing here
}
else
{
echo -e "${RED} ERROR - ${YELLOW220} system not recognized ${RESET}"
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_TO_CALL
unset PARAMETERS
exit 1
}
fi
if [[ -z "${FILE_TO_CALL}" ]]; then # if empty
{
echo -e "${RED} ERROR - ${YELLOW220} The following branches failed to determine FILE_TO_CALL for this OS. uname -a, cat /etc/os-release, lsb_release -i <${FILE_TO_CALL}> ${RESET}"
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_TO_CALL
unset PARAMETERS
exit 1
}
else
{
# Found
local FILE_ACTION_VERSION="${ACTION}_${FILE_TO_CALL_WITH_VERSION}"
local FILE_ACTION="${ACTION}_${FILE_TO_CALL}"
if command -v "${FILE_ACTION_VERSION}" >/dev/null 2>&1; then
{
# passed "${FILE_ACTION_VERSION}" "${PARAMETERS:-THISSCRIPTPARAMS}"
"${FILE_ACTION_VERSION}" "${PARAMETERS:-THISSCRIPTPARAMS}"
# _assure_success
}
else
{
if command -v "${FILE_ACTION}" >/dev/null 2>&1; then
{
# passed "${FILE_ACTION}" "${PARAMETERS:-THISSCRIPTPARAMS}"
"${FILE_ACTION}" "${PARAMETERS:-THISSCRIPTPARAMS}"
# _assure_success
}
else
{
echo -e "${YELLOW220} warning - ${YELLOW220} warning could not find filename with version for this OS or DISTRO: ${FILE_ACTION_VERSION}
adding would look at adding this:
${FILE_ACTION_VERSION}
Checked if we can find a nonversion function: ${FILE_ACTION}
warning could not find function for this OS or DISTRO: ${FILE_ACTION}
${RED} ERROR - ${YELLOW220} to find function for this OS or DISTRO: ${FILE_ACTION} ${PARAMETERS:-THISSCRIPTPARAMS}
Cannot proceed until you add this function above missing
${RESET}"
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_ACTION_VERSION
unset FILE_ACTION
unset FILE_TO_CALL
unset PARAMETERS
exit 1
}
fi
}
fi
}
fi
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_TO_CALL
unset PARAMETERS
} # end determine_os_and_run_file
# determine_os_and_run_file "${*}"
# check operation systems
(
if [[ "$(uname)" == "Darwin" ]] ; then
{
if (( DEBUG )) ; then
echo "Darwin"
fi
# echo $(get_mac_architecture)
# Do something under Mac OS X platform
# FILE_TO_CALL='_darwin__64'
# PARAMETERS="$@"
target_name="mac"
_mac_style_version_number_maybe=$(_get_mac_style_version_number_maybe)
_err=$?
# echo ${_mac_style_version_number_maybe}
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_mac_architecture "${target_name}${_mac_style_version_number_maybe}")
FILE_TO_CALL=$(get_mac_architecture "${target_name}")
# echo ${FILE_TO_CALL_WITH_VERSION}
if command -v ${ACTION}${FILE_TO_CALL_WITH_VERSION} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL_WITH_VERSION} "$@"
}
elif command -v ${ACTION}${FILE_TO_CALL} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL} "$@"
}
else
{
echo "bash_intuivo_cli/${ACTION} Platform $(uname -a) -- not found/not yet implemented
${ACTION}${FILE_TO_CALL_WITH_VERSION}
${ACTION}${FILE_TO_CALL}
"
exit 1
}
fi
}
fi
}
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]] ; then
{
if (( DEBUG )) ; then
echo "Linux"
fi
# Do something under GNU/Linux platform
# Determine OS platform
# local
UNAME=$(uname | tr "[:upper:]" "[:lower:]")
if (( DEBUG )) ; then
echo "UNAME: $UNAME"
fi
# local
DISTRO=""
# local
ID=""
# local
VERSION_ID=""
# If Linux, try to determine specific distribution
if [[ "$UNAME" == "linux" ]]; then
{
# If available, use LSB to identify distribution
if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then
{
if ( command -v lsb_release >/dev/null 2>&1; ); then
{
if (( DEBUG )) ; then
echo "RELEASE Option: 1"
fi
DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'// | head -1)
}
else
{
if (( DEBUG )) ; then
echo "RELEASE Option: 2"
fi
DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1 | head -1)
}
fi
}
else # Otherwise, use release info file
{
if (( DEBUG )) ; then
echo "RELEASE Option: 3"
fi
DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1 | head -1)
}
fi
}
fi
if (( DEBUG )) ; then
echo "DISTRO:$DISTRO"
fi
if [[ -z "$DISTRO" ]]; then # if empty
{
if (( DEBUG )) ; then
echo "DISTRO empty"
fi
# If available, use /etc/os-release to identify distribution
if [ -f /etc/os-release ]; then
{
source /etc/os-release
# file_exists "/etc/os-release"
# _assure_success
# source /etc/os-release
# $ echo $ID
# fedora
# $ echo $VERSION_ID
# 17
# $ echo $VERSION
# 17 (Beefy Miracle)
DISTRO=$ID
}
fi
}
fi
if [[ -z "$DISTRO" ]] ; then # if empty
{
echo -e "${RED} ERROR - ${YELLOW220} to determine DISTRO for this linux. uname -a, cat /etc/os-release, lsb_release -i ${RESET}"
unset ACTION
unset FILE_TO_CALL_WITH_VERSION
unset FILE_TO_CALL
unset PARAMETERS
exit 1
}
fi
if [[ "$DISTRO" == *"edora"* ]]; then
{
# local
target_name="fedora"
# local
_redhat_style_version_number_maybe=$(_get_redhat_style_version_number_maybe)
_err=$?
# echo ${_redhat_style_version_number_maybe}
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_mac_architecture "${target_name}${_redhat_style_version_number_maybe}")
FILE_TO_CALL=$(get_mac_architecture "${target_name}")
# echo ${FILE_TO_CALL_WITH_VERSION}
if command -v ${ACTION}${FILE_TO_CALL_WITH_VERSION} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL_WITH_VERSION} "$@"
}
elif command -v ${ACTION}${FILE_TO_CALL} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL} "$@"
}
else
{
echo "bash_intuivo_cli/${ACTION} Platform $(uname -a) -- not found/not yet implemented
${ACTION}${FILE_TO_CALL_WITH_VERSION}
${ACTION}${FILE_TO_CALL}
"
exit 1
}
fi
}
fi
}
elif [[ "$DISTRO" == *"untu"* ]]; then
{
# ubuntu lsb_release -i | sed 's/Distributor\ ID://g' = \tUbuntu\n
# local
target_name="ubuntu"
# local
_debian_style_version_number_maybe=$(_get_debian_style_version_number_maybe)
_err=$?
# echo ${_debian_style_version_number_maybe}
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_mac_architecture "${target_name}${_debian_style_version_number_maybe}")
FILE_TO_CALL=$(get_mac_architecture "${target_name}")
# echo ${FILE_TO_CALL_WITH_VERSION}
if command -v ${ACTION}${FILE_TO_CALL_WITH_VERSION} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL_WITH_VERSION} "$@"
}
elif command -v ${ACTION}${FILE_TO_CALL} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL} "$@"
}
else
{
echo "bash_intuivo_cli/${ACTION} Platform $(uname -a) -- not found/not yet implemented
${ACTION}${FILE_TO_CALL_WITH_VERSION}
${ACTION}${FILE_TO_CALL}
"
exit 1
}
fi
}
fi
}
elif [[ "$DISTRO" == *"bian"* ]]; then
{
# local
target_name="debian"
# local
_debian_style_version_number_maybe=$(_get_debian_style_version_number_maybe)
_err=$?
# echo ${_debian_style_version_number_maybe}
if [ ${_err} -eq 0 ] ; then
{
FILE_TO_CALL_WITH_VERSION=$(get_mac_architecture "${target_name}${_debian_style_version_number_maybe}")
FILE_TO_CALL=$(get_mac_architecture "${target_name}")
# echo ${FILE_TO_CALL_WITH_VERSION}
if command -v ${ACTION}${FILE_TO_CALL_WITH_VERSION} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL_WITH_VERSION} "$@"
}
elif command -v ${ACTION}${FILE_TO_CALL} >/dev/null 2>&1; then
{
${ACTION}${FILE_TO_CALL} "$@"
}
else
{
echo "bash_intuivo_cli/${ACTION} Platform $(uname -a) -- not found/not yet implemented
${ACTION}${FILE_TO_CALL_WITH_VERSION}
${ACTION}${FILE_TO_CALL}
"
exit 1
}
fi
}
fi
}
else
{
# local
target_name="${DISTRO}"
echo "bash_intuivo_cli/${ACTION} Platform ${target_name} $(uname -a) -- not found/not yet implemented
"
exit 1
}
fi
if (( DEBUG )) ; then
echo "FILE_TO_CALL: $FILE_TO_CALL"
echo "uname -i: $(uname -i)"
fi
# For everything else (or if above failed), just use generic identifier
unset UNAME
unset DISTRO
unset ID
}
# elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]] ; then
# # Do something under GNU/Linux platform
# # ubuntu lsb_release -i | sed 's/Distributor\ ID://g' = \tUbuntu\n
# if [[ "$(uname -i)" == "x86_64" ]] ; then
# pt_linux_64 "$@"
# elif [[ "$(uname -i)" == "i686" ]] ; then
# pt_linux_32 "$@"
# elif [[ "$(uname -i)" == "arm64" ]] ; then
# pt_linux_arm64 "$@"
# fi
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]] ; then
# Do something under Windows NT platform
pt_win_32 "$*"
# nothing here
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]] ; then
# Do something under Windows NT platform
pt_win_64 "$*"
# nothing here
fi
)