forked from wrljet/hercules-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hercules-buildall.sh
executable file
·4956 lines (4087 loc) · 168 KB
/
hercules-buildall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# This file is part of the Hercules-Helper project.
#
# (C) Copyright William R. Lewis, 2020-2024
#
# This software is released under the terms of the MIT License.
#
# https://github.com/wrljet/hercules-helper/blob/master/LICENSE
# Updated: 12 OCT 2024
VERSION_STR=v0.9.14+
#
# The most recent version of this project can be obtained with:
# git clone https://github.com/wrljet/hercules-helper.git
# or:
# wget https://github.com/wrljet/hercules-helper/archive/master.zip
#
# Please report errors in this project to me so everyone can benefit.
#
# Bill Lewis bill@wrljet.com
#-----------------------------------------------------------------------------
#
# To run, create a build directory and cd to it, then run this script.
#
# $ mkdir herctest && cd herctest
# $
# $ ~/hercules-helper/hercules-buildall.sh --auto
# or
# $ ~/hercules-helper/hercules-buildall.sh --verbose --prompts
# or
# $ ~/hercules-helper/hercules-buildall.sh --auto --flavor=aethra
#
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#
# The major steps are (most can be optionally skipped):
#
# dostep_detect Detect system and configuration
# dostep_packages Check for required system packages
# Check for REXX and compiler settings (needed to run Hercules tests)
# dostep_regina_rexx Build Regina REXX
# dostep_gitclone Git clone Hercules and external packages
# dostep_bldlvlck Run bldlvlck
# dostep_extpkgs Build Hercules external packages
# dostep_autogen Run autogen
# dostep_configure Run configure
# dostep_clean Run make clean
# dostep_make Run make (compile and link)
# dostep_tests Run make check
# dostep_install Run make install
# dostep_setcap setcap executables
# dostep_envscript Create script to set environment variables
# dostep_bashrc Add "source" to set environment variables from .bashrc
#
#-----------------------------------------------------------------------------
if test "$BASH" == "" || "$BASH" -uc "a=();true \"${a[@]}\"" 2>/dev/null; then
# Bash 4.4+, Zsh
# Treat unset variables as an error when substituting
set -uo pipefail
else
# Bash 4.3 and older chokes on empty arrays with set -u
set -o pipefail
fi
# Stop on error
# set -e
# Instructions on updating Bash on macOS Mojave 10.14
# https://itnext.io/upgrading-bash-on-macos-7138bd1066ba
if ((BASH_VERSINFO[0] >= 4))
then
shopt -s globstar
fi
shopt -s nullglob
shopt -s extglob # Required for MacOS
require(){ hash "$@" || exit 127; }
current_time=$(date "+%Y-%m-%d")
# Find and read in the helper functions
fns_dir="$(dirname "$0")"
fns_file="$fns_dir/helper-fns.sh"
if test -f "$fns_file" ; then
source "$fns_file"
else
echo "Helper functions script file not found!"
exit 1
fi
#------------------------------------------------------------------------------
#
# Default Configuration Parameters:
#
# Show/trace every Bash command
TRACE=${TRACE:-false} # If TRACE variable not set or null, default to FALSE
# Overall working build diretory is the current directory
opt_build_dir=${opt_build_dir:-$(pwd)}
# Custom build message
# n.b. the version number will be tacked on the end
opt_custom_build_msg=${opt_custom_buid_msg:-"Built for you with Hercules-Helper"}
# Prefix (target) directory
opt_install_dir=${opt_install_dir:-$(pwd)/herc4x}
# Git repo for Hercules
git_repo_hercules=${git_repo_hercules:-https://github.com/SDL-Hercules-390/hyperion.git}
# git_repo_hercules=https://github.com/wrljet/hyperion.git
# Git checkout branch for Hercules
git_branch_hercules=${git_branch_hercules:-""}
# git_branch_hercules="build-netbsd"
# Git checkout commit for Hercules
git_commit_hercules=${git_commit_hercules:-""}
# git_commit_hercules=cb24398
# Git repo for Hercules External Packages
git_repo_extpkgs=${git_repo_extpkgs:-https://github.com/SDL-Hercules-390}
# git_repo_extpkgs=https://github.com/wrljet
# Git checkout branch for Hercules External Packages
git_branch_extpkgs=${git_extpkgs_extpkgs:-""}
# git_branch_extpkgs="build-mods-i686"
# Regina download
opt_regina_dir=${opt_regina_dir:-"Regina-REXX-3.6"}
opt_regina_tarfile=${opt_regina_tarfile:-"Regina-REXX-3.6.tar.gz"}
opt_regina_url=${opt_regina_url:-"https://gist.github.com/wrljet/053c3bab74910d42f8775841fcc6fd3f/raw/fe7d723509356ebb77d1eb4593f15dda941949da/Regina-REXX-3.6.tar.gz"}
# opt_regina_dir="Regina-REXX-3.9.3"
# opt_regina_tarfile="Regina-REXX-3.9.3.tar.gz"
# opt_regina_url="https://gist.github.com/wrljet/dd19076064da7c3dea1aa9614fc37511/raw/e842479d63fae7af79d4aec467b8fdb148ca196a/Regina-REXX-3.9.3.tar.gz"
opt_configure=${opt_configure:-""}
opt_configure_optimization=${opt_configure_optimization:-""}
opt_cmake_defines=${opt_cmake_defines:-""}
# Print verbose progress information
opt_verbose=${opt_verbose:-false}
# Prompt the user before each major step is started
opt_prompts=${opt_prompts:-false}
# Beep to alert the user that a prompt is waiting
opt_beeps=${opt_beeps:-false}
# Run detection only and exit
opt_detect_only=${opt_detect_only:-false}
# Use 'sudo' for 'make install'
opt_usesudo=${opt_usesudo:-false}
# Use 'sudo -A' askpass helper
opt_askpass=${opt_askpass:-false}
# Accept root user
opt_accept_root=${opt_accept_root:-false}
# Sub-functions, in order of operation
#
# --no-packages skip installing required packages
# Do not install missing packages if true
opt_no_packages=${opt_no_packages:-false}
# --no-rexx skip building Regina REXX
# Do not build Regina REXX
opt_no_rexx=${opt_no_rexx:-false}
# --no-gitclone skip \'git clone\' steps
# Do not 'git clone' if true
opt_no_gitclone=${opt_no_gitclone:-false}
# --no-bldlvlck skip \'util/bldlvlck\' steps
opt_no_bldlvlck=${opt_no_bldlvlck:-false}
# --no-extpkgs skip building Hercules external packages
opt_no_extpkgs=${opt_no_extpkgs:-false}
# --no-autogen skip running \'autogen\'
opt_no_autogen=${opt_no_autogen:-true}
# --no-configure skip running \'configure\'
opt_no_configure=${opt_no_configure:-false}
# --no-clean skip running \'make clean\'
opt_no_clean=${opt_no_clean:-false}
# --no-make skip running \'make\'
opt_no_make=${opt_no_make:-false}
# --no-tests skip running \'make check\'
opt_no_tests=${opt_no_tests:-false}
# --no-install skip \'make install\' after building
# Skip 'make install' after building
opt_no_install=${opt_no_install:-false}
# --no-setcap skip running \'setcap\'
opt_no_setcap=${opt_no_setcap:-false}
# --no-envscript skip creating script to set environment variables
opt_no_envscript=${opt_no_envscript:-false}
# --no-bashrc skip modifying .bashrc to set environment variables
opt_no_bashrc=${opt_no_bashrc:-false}
# --force-pi force use of Raspberry Pi code (for systems that may conceal the CPU type)
opt_force_pi=${opt_force_pi:-false}
# Optional steps we perform
#
dostep_packages=${dostep_packages:-true} # Check for required system packages
dostep_regina_rexx=${dostep_regina_rexx:-true} # Build Regina REXX
dostep_gitclone=${dostep_gitclone:-true} # Git clone Hercules and external packages
dostep_bldlvlck=${dostep_bldlvlck:-true} # Run bldlvlck
dostep_extpkgs=${dostep_extpkgs:-true} # Build Hercules external packages
dostep_autogen=${dostep_autogen:-false} # Run autoreconf / autogen
dostep_configure=${dostep_configure:-true} # Run configure
dostep_clean=${dostep_clean:-true} # Run make clean
dostep_make=${dostep_make:-true} # Run make (compile and link)
dostep_tests=${dostep_tests:-true} # Run make check
dostep_install=${dostep_install:-true} # Run make install
dostep_setcap=${dostep_setcap:-true} # setcap executables
dostep_envscript=${dostep_envscript:-true} # Create script to set environment variables
dostep_bashrc=${dostep_bashrc:-true} # Add "source" to set environment variables from .bashrc
#-----------------------------------------------------------------------------
# Set up default empty values for our variables
debug=${debug:-""}
DEBUG=${DEBUG:-""}
version_distro=""
os_version_id=""
os_version_rpidesktop=0
os_version_wsl=0
os_version_freebsd_cpu=""
os_version_freebsd_model=""
os_version_memory_size=""
os_version_multicore_with_low_memory=false
version_regina=0
uname_system="$( (uname -s) 2>/dev/null)" || uname_system="unknown"
CC=${CC:-"cc"}
CFLAGS=${CFLAGS:-""}
CPPFLAGS=${CPPFLAGS:-""}
LD=${LD:-"ld"}
LDFLAGS=${LDFLAGS:-""}
#-----------------------------------------------------------------------------
if [[ "$*" == *"--accept-root"* ]]
then
opt_accept_root=true
else
opt_accept_root=false
fi
if [[ $opt_accept_root == false ]] ; then
if [[ "$EUID" -eq 0 ]]; then
echo # print a new line
echo "Running this as root is dangerous and can cause misconfiguration issues"
echo "or damage to your system. Run as a normal user, and the parts that need"
echo "it will ask for your sudo password (if required)."
echo # print a new line
echo "For information, see:"
echo "https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root"
echo "https://wiki.debian.org/sudo/"
echo "https://phoenixnap.com/kb/how-to-create-add-sudo-user-centos"
echo # print a new line
read -p "Hit return to exit" -n 1 -r
echo # print a new line
exit 1
fi
fi
#-----------------------------------------------------------------------------
uname_system="$( (uname -s) 2>/dev/null)" || uname_system="unknown"
# Check for Apple macOS and prerequisites
darwin_have_homebrew=false
darwin_have_macports=false
if [ "$uname_system" == "Darwin" ]; then
darwin_need_prereqs=false
# echo "Checking for Xcode command line tools ..."
xcode-select -p 1>/dev/null 2>/dev/null
if [[ $? == 2 ]] ; then
darwin_need_prereqs=true
else
# echo " Command line tools are already installed"
echo "Xcode command line tools appear to be installed"
if (cc --version 2>&1 | head -n 1 | grep -Fiqe "xcrun: error: invalid active developer path"); then
error_msg "But the C compiler does not work"
echo "$(cc --version 2>&1)"
exit 1
fi
fi
# echo "Checking for Homebrew package manager ..."
which -s brew
if [[ $? != 0 ]] ; then
echo " Homebrew is not installed"
else
darwin_need_prereqs=false
darwin_have_homebrew=true
echo " Homebrew is already installed"
fi
# echo "Checking for MacPorts package manager ..."
which -s port
if [[ $? != 0 ]] ; then
echo " MacPorts is not installed"
else
darwin_need_prereqs=false
darwin_have_macports=true
echo " MacPorts is already installed"
fi
if ( $darwin_need_prereqs == true ) ; then
echo # output a newline
echo "Please run prerequisites-macOS.sh first"
echo # output a newline
exit 1
fi
echo # output a newline
fi
#-----------------------------------------------------------------------------
# 'realpath' doesn't exist on MacOS or BSDs
# SCRIPT_PATH=$(dirname $(realpath -s $0))
# FIXME: this doesn't work if this script is running off a symlink
SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")
SCRIPT_DIR="$(dirname $SCRIPT_PATH)"
pushd "$(dirname "$0")" >/dev/null;
which_git=$(which git 2>/dev/null) || true
which_status=$?
if [ -z $which_git ]; then
# verbose_msg "git is not installed"
version_info="$VERSION_STR"
elif [ ! -d "$SCRIPT_DIR/.git" ]; then
# verbose_msg "not a git repo"
version_info="$VERSION_STR"
else
version_info="$(git describe --long --tags --dirty --always 2>/dev/null)"
fi
popd > /dev/null;
usage="Hercules-Helper $version_info
Usage: $(basename "$0") [OPTIONS]
Perform a full build, test, and installation of Hercules from git sources
Options:
-h, --help print this help
-t, --trace print every command (set -x)
-v, --verbose print lots of messages
--version prints version info and exits
-p, --prompts print a prompt before each major step
--beeps beep at each prompt
--flavor= specify major flavor: aethra, sdl-hyperion, etc.
--config=FILE specify config file containing options
-s, --sudo use 'sudo' for installing
--askpass use 'sudo -A' askpass helper
--accept-root accept running as root user
-a, --auto run everything, with --verbose (but not --prompts),
and create a full log file (this is the default)
--homebrew assume Homebrew package manager on MacOS
--macports assume MacPorts package manager on MacOS
--force-pi process for a Raspberry Pi
--prefix installation dir prefix for configure
Sub-functions (in order of operation):
--detect-only run detection only and exit
--no-packages skip installing required packages
--no-rexx skip building Regina REXX, no REXX support in Hercules
--no-gitclone skip 'git clone' steps
--no-bldlvlck skip 'util/bldlvlck' steps
--no-extpkgs skip building Hercules external packages
--autogen run 'autoreconf' and 'autogen'
--no-autogen skip running 'autogen'
--no-configure skip running 'configure'
--no-clean skip running 'make clean'
--no-make skip running 'make'
--no-tests skip running 'make check'
--no-install skip 'make install' after building
--no-setcap skip running 'setcap'
--no-envscript skip creating script to set environment variables
--no-bashrc skip modifying .bashrc to set environment variables
Please email bug reports, questions, etc. to: <bill@wrljet.com>
"
#------------------------------------------------------------------------------
# finish
#------------------------------------------------------------------------------
finish()
{
echo "finish() called, exit status = $?"
}
#------------------------------------------------------------------------------
# set_run_or_skip
#------------------------------------------------------------------------------
run_or_skip="no"
set_run_or_skip()
{
if ($1 == true); then
run_or_skip="run "
else
run_or_skip="skip"
fi
}
#------------------------------------------------------------------------------
# add_build_entry
#------------------------------------------------------------------------------
add_build_entry()
{
echo "$@" >>"$cmdsfile"
}
#------------------------------------------------------------------------------
# log_extra_info
#------------------------------------------------------------------------------
log_extra_info()
{
echo "$@" >>"$extra_file"
}
#------------------------------------------------------------------------------
# detect_pi
#------------------------------------------------------------------------------
# Table source:
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
function get_pi_version()
{
verbose_msg -n "Checking for Raspberry Pi... "
RPI_MODEL=$(awk '/Model/ {print $3}' /proc/cpuinfo)
# echo "$RPI_MODEL"
if [[ $RPI_MODEL =~ "Raspberry" ]]; then
verbose_msg "found"
os_is_supported=true
RPI_REVCODE=$(awk '/Revision/ {print $3}' /proc/cpuinfo)
verbose_msg "Raspberry Pi rev : $RPI_REVCODE"
RPI_CPUS=$(awk '/^processor/{n+=1}END{print n}' /proc/cpuinfo)
verbose_msg "CPU count : $RPI_CPUS"
else
verbose_msg "nope"
fi
}
function check_pi_version()
{
# Source:
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
local -rA RPI_REVISIONS=(
[900021]="A+ 1.1 512MB Sony UK"
[900032]="B+ 1.2 512MB Sony UK"
[900092]="Zero 1.2 512MB Sony UK"
[900093]="Zero 1.3 512MB Sony UK"
[9000c1]="Zero W 1.1 512MB Sony UK"
[9020e0]="3A+ 1.0 512MB Sony UK"
[902120]="Zero 2 W 1.0 512MB Sony UK"
[920092]="Zero 1.2 512MB Embest"
[920093]="Zero 1.3 512MB Embest"
[900061]="CM 1.1 512MB Sony UK"
[a01040]="2B 1.0 1GB Sony UK"
[a01041]="2B 1.1 1GB Sony UK"
[a02082]="3B 1.2 1GB Sony UK"
[a020a0]="CM3 1.0 1GB Sony UK"
[a020d3]="3B+ 1.3 1GB Sony UK"
[a02042]="2B (with BCM2837) 1.2 1GB Sony UK"
[a21041]="2B 1.1 1GB Embest"
[a22042]="2B (with BCM2837) 1.2 1GB Embest"
[a22082]="3B 1.2 1GB Embest"
[a220a0]="CM3 1.0 1GB Embest"
[a32082]="3B 1.2 1GB Sony Japan"
[a52082]="3B 1.2 1GB Stadium"
[a22083]="3B 1.3 1GB Embest"
[a02100]="CM3+ 1.0 1GB Sony UK"
[a03111]="4B 1.1 1GB Sony UK"
[b03111]="4B 1.1 2GB Sony UK"
[b03112]="4B 1.2 2GB Sony UK"
[b03114]="4B 1.4 2GB Sony UK"
[b03115]="4B 1.5 2GB Sony UK"
[c03111]="4B 1.1 4GB Sony UK"
[c03112]="4B 1.2 4GB Sony UK"
[c03114]="4B 1.4 4GB Sony UK"
[c03115]="4B 1.5 4GB Sony UK"
[d03114]="4B 1.4 8GB Sony UK"
[d03115]="4B 1.5 8GB Sony UK"
[c03130]="Pi 400 1.0 4GB Sony UK"
[c03131]="Pi 400 1.1 4GB Sony UK"
[a03140]="CM4 1.0 1GB Sony UK"
[b03140]="CM4 1.0 2GB Sony UK"
[c03140]="CM4 1.0 4GB Sony UK"
[d03140]="CM4 1.0 8GB Sony UK"
[d04170]="5B 1.0 8GB "
)
verbose_msg "Raspberry Pi : ${RPI_REVISIONS[$RPI_REVCODE]} ($RPI_REVCODE)"
}
function detect_pi()
{
verbose_msg " " # output a newline
# Raspberry Pi 4B, Ubuntu 20 64-bit, uname -m == aarch64
# Raspberry Pi 4B, RPiOS 32-bit, uname -m == armv7l
# Raspberry Pi Zero, RPiOS 32-bit, uname -m == armv6l
grep -iqe "Raspberry Pi" /proc/cpuinfo 2>&1
status=$?
if [ $status -eq 0 ]; then
# Raspberry Pi CPU
verbose_msg "Running on Raspberry Pi hardware"
get_pi_version
check_pi_version
# Try to detect a Raspberry Pi Zero 2 W.
# This has the same multi-core CPU as a Pi 3B, but with only 512MB RAM.
# Running parallel 'make' jobs on this will cause the Linux
# Out-Of-Memory killer to kick in.
if [[ $RPI_CPUS -gt 1 && $os_version_memory_size -lt 1000 ]]; then
verbose_msg " : Multi-core Raspberry Pi with low memory"
os_version_multicore_with_low_memory=true
fi
fi
}
#------------------------------------------------------------------------------
# detect_darwin
#------------------------------------------------------------------------------
detect_darwin()
{
# from config.guess:
# https://git.savannah.gnu.org/git/config.git
# uname -a
# Darwin Sunils-Air 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 x86_64
# Darwin xxxx.cyberlynk.net 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:31 PDT 2021; root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64
if [ "$uname_system" == "Darwin" ]; then
version_distro="darwin"
fi
}
#------------------------------------------------------------------------------
# detect_system
#------------------------------------------------------------------------------
detect_system()
{
# 27 JUL 2021
# Android 11 LineageOS 18.1 on Raspberry Pi 4B
# Linux localhost 5.4.132-v7l-gfc76364e6fe8 #1 SMP PREEMPT Tue Jul 20 15:55:44 EEST 2021 armv7l Android
# 31 JAN 2021
#
# /etc/os-release
# NAME="Alpine Linux"
# ID=alpine
# VERSION_ID=3.13.1
# PRETTY_NAME="Alpine Linux v3.13"
# HOME_URL="https://alpinelinux.org/"
# BUG_REPORT_URL="https://bugs.alpinelinux.org/"
#
# /etc/alpine-release
# 3.13.1
# $ cat /boot/issue.txt | head -1
# Raspberry Pi reference 2020-05-27
# 19 JAN 2021
#
# $ cat /etc/os-release
# NAME="Manjaro Linux"
# ID=manjaro
# ID_LIKE=arch
# BUILD_ID=rolling
# PRETTY_NAME="Manjaro Linux"
# ANSI_COLOR="32;1;24;144;200"
# HOME_URL="https://manjaro.org/"
# DOCUMENTATION_URL="https://wiki.manjaro.org/"
# SUPPORT_URL="https://manjaro.org/"
# BUG_REPORT_URL="https://bugs.manjaro.org/"
# LOGO=manjarolinux
# /etc/os-release
#
# NAME="Linux Mint"
# VERSION="20 (Ulyana)"
# ID=linuxmint
# ID_LIKE=ubuntu
# PRETTY_NAME="Linux Mint 20"
# VERSION_ID="20"
# /etc/os-release
#
# NAME="Peppermint"
# VERSION_CODENAME="chimaera"
# PRETTY_NAME="PeppermintOS Devuan"
# ID=peppermint
# /etc/os-release
#
# NAME=Fedora
# VERSION="34 (Workstation Edition)"
# ID=fedora
# VERSION_ID=34
# PRETTY_NAME="Fedora 34 (Workstation Edition)"
# /etc/os-release
#
# NAME="Red Hat Enterprise Linux"
# VERSION="9.1 (Plow)"
# ID="rhel"
# ID_LIKE="fedora"
# VERSION_ID="9.1"
# PLATFORM_ID="platform:el9"
# PRETTY_NAME="Red Hat Enterprise Linux 9.1 (Plow)"
# /etc/os-release
#
# NAME="Oracle Linux Server"
# VERSION="8.8"
# ID="ol"
# ID_LIKE="fedora"
# VARIANT="Server"
# VARIANT_ID="server"
# VERSION_ID="8.8"
# PLATFORM_ID="platform:el8"
# PRETTY_NAME="Oracle Linux Server 8.8"
verbose_msg "System detection:"
RPI_MODEL=""
os_is_supported=false
os_name=$(uname -s)
verbose_msg "OS Type : $os_name"
machine=$(uname -m)
verbose_msg "Machine Arch : $machine"
if [ "$os_name" = "Linux" ]; then
os_version_id="??? unknown ???"
os_version_id_like="??? unknown ???"
os_version_pretty_name="??? unknown ???"
os_version_str="??? unknown ???"
# First, we look for Android!
#
# LineageOS 18.1 Android 11 on Raspberry Pi 4B
# Linux localhost 5.4.132-v7l-gfc76364e6fe8 #1 SMP PREEMPT Tue Jul 20 15:55:44 EEST 2021 armv7l Android
#
# Moshix, Samsung phone
# Linux localhost 4.14.113-21644994 #1 SMP PREEMPT Fri Jun 18 16:26:54 KST 2021 aarch64 Android
# verbose_msg " uname -a : $(uname -a)"
version_uname="$(uname -a)"
if [[ "$version_uname" =~ Android ]]; then
version_id="android"
version_id_like="android"
version_pretty_name="Android"
version_str="??? unknown ???"
os_is_supported=true
fi
if [ -f /etc/os-release ]; then
# awk -F= '$1=="ID" { gsub(/"/, "", $2); print $2 ;}' /etc/os-release
os_version_id=$(awk -F= '$1=="ID" { gsub(/"/, "", $2); print $2 ;}' /etc/os-release)
# echo "VERSION_ID is $os_version_id"
os_version_id_like=$(awk -F= '$1=="ID_LIKE" { gsub(/"/, "", $2); print $2 ;}' /etc/os-release)
# echo "VERSION_ID_LIKE is $os_version_id_like"
os_version_pretty_name=$(awk -F= '$1=="PRETTY_NAME" { gsub(/"/, "", $2); print $2 ;}' /etc/os-release)
# echo "VERSION_STR is $os_os_version_str"
os_version_str=$(awk -F= '$1=="VERSION_ID" { gsub(/"/, "", $2); print $2 ;}' /etc/os-release)
# echo "VERSION_STR is $os_version_str"
fi
os_version_memory_size="$(free -m | awk '/^Mem:/{print $2}')"
verbose_msg "Memory Total (MB): $os_version_memory_size"
verbose_msg "Memory Free (MB): $(free -m | awk '/^Mem:/{print $4}')"
verbose_msg "VERSION_ID : $os_version_id"
verbose_msg "VERSION_ID_LIKE : $os_version_id_like"
verbose_msg "VERSION_PRETTY : $os_version_pretty_name"
verbose_msg "VERSION_STR : $os_version_str"
# Look for Slackware Linux
if [[ $os_version_id == slackware* ]];
then
version_distro="slackware"
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
# Look for Gentoo Linux
if [[ $os_version_id == gentoo* ]];
then
version_distro="gentoo"
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
# Look for Alpine Linux
if [[ $os_version_id == alpine* ]];
then
version_distro="alpine"
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
# Look for Orange OS
# Linux opizero2w 6.1.31-1 #1 SMP Thu Sep 7 18:21:15 CST 2023 aarch64 GNU/Linux
# VERSION_ID : archarm
# VERSION_ID_LIKE : arch
# VERSION_PRETTY : Orange OS
# VERSION_STR :
# /etc/orangepi-os-version
# opizero2w - xfce - 23.09-linux6.1.31
if [[ $os_is_supported != true && $os_version_id == arch* && $os_version_pretty_name == Orange* ]];
then
version_distro="arch"
os_version_str=$(awk -F= '$1=="DISTRIB_RELEASE" { gsub(/"/, "", $2); print $2 ;}' /etc/orangepi-os-version)
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
# Look for Manjaro
if [[ $os_is_supported != true && ($os_version_id == arch* || $os_version_id == manjaro*) ]];
then
version_distro="arch"
os_version_str=$(awk -F= '$1=="DISTRIB_RELEASE" { gsub(/"/, "", $2); print $2 ;}' /etc/lsb-release)
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
# Look for Debian/Ubuntu/Mint
if [[ $os_version_id == debian* || $os_version_id == ubuntu* || \
$os_version_id == devuan* || \
$os_version_id == linuxmint* || $os_version_id == peppermint* || \
$os_version_id == raspbian* || $os_version_id == neon* || \
$os_version_id == pop* || $os_version_id == zorin* || \
$os_version_id == sparky* ]];
then
version_distro="debian"
version_major=$(echo $os_version_str | cut -f1 -d.)
version_minor=$(echo $os_version_str | cut -f2 -d.)
verbose_msg "OS : $version_distro variant"
verbose_msg "OS Version : $version_major"
os_is_supported=true
fi
if [[ $os_version_id == raspbian* ]]; then
echo "$(cat /boot/issue.txt | head -1)"
fi
# Look for Rocky Linux
if [[ $os_version_id == rocky* ]]; then
verbose_msg "We have an Rocky Linux system"
# Rocky Linux 8.6
# $ rpm --query centos-release
# package centos-release is not installed
# $ cat /etc/redhat-release
# Rocky Linux release 8.6 (Green Obsidian)
# rockylinux_vers=$(rpm --query centos-release) || true
rockylinux_vers=$(cat /etc/redhat-release) || true
rockylinux_vers="${rockylinux_vers#*release }"
rockylinux_vers="${rockylinux_vers/ */}"
version_distro="rockylinux"
version_major=$(echo $rockylinux_vers | cut -f1 -d.)
version_minor=$(echo "$rockylinux_vers.0" | cut -f2 -d.)
verbose_msg "VERSION_MAJOR : $version_major"
verbose_msg "VERSION_MINOR : $version_minor"
os_is_supported=true
fi
# Look for AlmaLinux
if [[ $os_version_id == almalinux* ]]; then
verbose_msg "We have an AlmaLinux system"
# AlmaLinux 8.4
# $ rpm --query centos-release
# package centos-release is not installed
# $ cat /etc/redhat-release
# AlmaLinux release 8.4 (Electric Cheetah)
# almalinux_vers=$(rpm --query centos-release) || true
almalinux_vers=$(cat /etc/redhat-release) || true
almalinux_vers="${almalinux_vers#*release }"
almalinux_vers="${almalinux_vers/ */}"
version_distro="almalinux"
version_major=$(echo $almalinux_vers | cut -f1 -d.)
version_minor=$(echo "$almalinux_vers.0" | cut -f2 -d.)
verbose_msg "VERSION_MAJOR : $version_major"
verbose_msg "VERSION_MINOR : $version_minor"
os_is_supported=true
fi
# Look for CentOS
if [[ $os_version_id == centos* ]]; then
verbose_msg "We have a CentOS system"
# CENTOS_VERS="centos-release-7-8.2003.0.el7.centos.x86_64"
# CENTOS_VERS="centos-release-7.9.2009.1.el7.centos.x86_64"
# CENTOS_VERS="centos-release-8.2-2.2004.0.2.el8.x86_64"
# Centos Stream 8:
# $ rpm --query centos-release
# package centos-release is not installed
# $ cat /etc/redhat-release
# CentOS Linux release 8.2.2004
# CentOS Stream release 8
# centos_vers=$(rpm --query centos-release) || true
centos_vers=$(cat /etc/redhat-release) || true
centos_vers="${centos_vers#*release }"
centos_vers="${centos_vers/-/.}"
version_distro="redhat"
version_major=$(echo $centos_vers | cut -f1 -d.)
version_minor=$(echo "$centos_vers.0" | cut -f2 -d.)
verbose_msg "VERSION_MAJOR : $version_major"
verbose_msg "VERSION_MINOR : $version_minor"
if [[ $version_major -ge 7 ]]; then
os_is_supported=true
fi
fi
# Look for RedHat
# NAME="Red Hat Enterprise Linux"
# VERSION="9.1 (Plow)"
# ID="rhel"
# ID_LIKE="fedora"
# VERSION_ID="9.1"
# PLATFORM_ID="platform:el9"
# PRETTY_NAME="Red Hat Enterprise Linux 9.1 (Plow)"
if [[ $os_version_id == rhel* ]]; then
verbose_msg "We have a RedHat RHEL system"
# cat /etc/redhat-release
# Red Hat Enterprise Linux release 9.1 (Plow)
redhat_vers=$(cat /etc/redhat-release) || true
redhat_vers="${redhat_vers#*release }"
redhat_vers="${redhat_vers/-/.}"
version_distro="redhat"
version_major=$(echo $redhat_vers | cut -f1 -d'.')
verbose_msg "VERSION_MAJOR : $version_major"
if [[ $version_major -ge 9 ]]; then
os_is_supported=true
fi
fi
# Look for Fedora
# NAME=Fedora
# VERSION="34 (Workstation Edition)"
# ID=fedora
# VERSION_ID=34
# PRETTY_NAME="Fedora 34 (Workstation Edition)"
if [[ $os_version_id == fedora* ]]; then
verbose_msg "We have a Fedora system"
# cat /etc/redhat-release
# Fedora release 34 (Thirty Four)
fedora_vers=$(cat /etc/redhat-release) || true
fedora_vers="${fedora_vers#*release }"
fedora_vers="${fedora_vers/-/.}"
version_distro="redhat"
version_major=$(echo $fedora_vers | cut -f1 -d' ')
verbose_msg "VERSION_MAJOR : $version_major"
if [[ $version_major -ge 34 ]]; then
os_is_supported=true
fi
fi
# Look for Mageia
# VERSION_ID : mageia
# VERSION_ID_LIKE : mandriva fedora
# VERSION_PRETTY : Mageia 8
# VERSION_STR : 8
if [[ $os_version_id == mageia* ]]; then
verbose_msg "We have a Mageia system"
version_distro="redhat"
version_major=$(echo $os_version_str | cut -f1 -d' ')
verbose_msg "VERSION_MAJOR : $version_major"
if [[ $version_major -ge 8 ]]; then
os_is_supported=true
fi
fi
# Look for Oracle
# NAME="Oracle Linux Server"
# VERSION="8.8"
# ID="ol"
# ID_LIKE="fedora"
# VARIANT="Server"
# VARIANT_ID="server"
# VERSION_ID="8.8"
# PLATFORM_ID="platform:el8"
# PRETTY_NAME="Oracle Linux Server 8.8"
# cat /etc/redhat-release
# Red Hat Enterprise Linux release 8.8 (Ootpa)
if [[ $os_version_id_like == fedora* && $os_version_pretty_name == Oracle* ]]; then
verbose_msg "We have an Oracle Linux system"
os_version_id="oracle"
version_distro="redhat"
version_major=$(echo $os_version_str | cut -f1 -d'.')
verbose_msg "VERSION_MAJOR : $version_major"
if [[ $version_major -ge 8 ]]; then