changeset 213: |
a7129c8e52d1 |
parent: |
91cb7ffc5945
|
child: |
98abb7f50885 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 30 Apr 2024 19:14:48 -0400 |
permissions: |
-rwxr-xr-x |
description: |
profiles, host.sxp |
19 host_config_file=host.sxp
24 get_architecture
|| return 1 26 assert_nz
"$_arch" "arch" 27 _write
";; -*- mode:skel -*-" 28 _write
":arch \"$_arch\"" 30 local _kernel_version="$RETVAL" 31 _write
":kernel \"$_kernel_version\"" 33 local _num_cpus="$RETVAL" 34 _write
":cpus $_num_cpus" 49 say
"$1" >>
$host_config_file 58 if [ -z
"$1" ]; then err
"assert_nz $2"; fi 62 command -v
"$1" >
/dev/null
2>
&1 66 if !
check_cmd
"$1"; then 67 err
"need '$1' (command not found)" 72 if !
"$@"; then err
"command failed: $*"; fi 76 # Check for /proc by looking for the /proc/self/exe link 77 # This is only run on Linux 78 if !
test -L
/proc/self/exe
; then 79 err
"fatal: Unable to find /proc/self/exe. Is /proc mounted? Installation cannot proceed without /proc." 84 # Architecture detection without dependencies beyond coreutils. 85 # ELF files start out "\x7fELF", and the following byte is 88 # The printf builtin on some shells like dash only supports octal 89 # escape sequences, so we use those. 90 local _current_exe_head
91 _current_exe_head=$(head
-c
5 /proc/self/exe
) 92 if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then 94 elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then 97 err
"unknown platform bitness" 101 is_host_amd64_elf
() { 102 # ELF e_machine detection without dependencies beyond coreutils. 103 # Two-byte field at offset 0x12 indicates the CPU, 104 # but we're interested in it being 0x3E to indicate amd64, or not that. 105 local _current_exe_machine
106 _current_exe_machine=$(head
-c
19 /proc/self/exe
| tail
-c
1) 107 [ "$_current_exe_machine" = "$(printf '\076')" ] 115 # detect endianness without od/hexdump, like get_bitness() does. 116 local _current_exe_endianness
117 _current_exe_endianness="$(head
-c
6 /proc/self/exe
| tail
-c
1)" 118 if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then 119 echo "${cputype}${suffix_el}" 120 elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then 121 echo "${cputype}${suffix_eb}" 123 err
"unknown platform endianness" 128 local _ostype
_cputype
_bitness
_arch
_clibtype
129 _ostype="$(uname
-s
)" 130 _cputype="$(uname
-m
)" 133 if [ "$_ostype" = Linux
]; then 134 if [ "$(uname
-o
)" = Android
]; then 137 if ldd
--version
2>
&1 | grep
-q
'musl'; then 142 if [ "$_ostype" = Darwin
] && [ "$_cputype" = i386
]; then 143 # Darwin `uname -m` lies 144 if sysctl
hw.optional.x86_64
| grep
-q
': 1'; then 149 if [ "$_ostype" = SunOS
]; then 150 # Both Solaris and illumos presently announce as "SunOS" in "uname -s" 151 # so use "uname -o" to disambiguate. We use the full path to the 152 # system uname in case the user has coreutils uname first in PATH, 153 # which has historically sometimes printed the wrong value here. 154 if [ "$(/usr/bin/uname
-o
)" = illumos
]; then 158 # illumos systems have multi-arch userlands, and "uname -m" reports the 159 # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86 160 # systems. Check for the native (widest) instruction set on the 162 if [ "$_cputype" = i86pc
]; then 163 _cputype="$(isainfo
-n
)" 170 _ostype=linux-android
175 _ostype=unknown-linux-
$_clibtype 176 _bitness=$(get_bitness
) 180 _ostype=unknown-freebsd
184 _ostype=unknown-netbsd
188 _ostype=unknown-dragonfly
196 _ostype=unknown-illumos
199 MINGW*
| MSYS*
| CYGWIN*
| Windows_NT
) 200 _ostype=pc-windows-gnu
204 err
"unrecognized OS type: $_ostype" 211 i386
| i486
| i686
| i786
| x86
) 217 if [ "$_ostype" = "linux-android" ]; then 218 _ostype=linux-androideabi
224 if [ "$_ostype" = "linux-android" ]; then 225 _ostype=linux-androideabi
227 _ostype="${_ostype}eabihf" 233 if [ "$_ostype" = "linux-android" ]; then 234 _ostype=linux-androideabi
236 _ostype="${_ostype}eabihf" 244 x86_64
| x86-64
| x64
| amd64
) 249 _cputype=$(get_endianness
mips
'' el
) 253 if [ "$_bitness" -eq
64 ]; then 254 # only n64 ABI is supported for now 255 _ostype="${_ostype}abi64" 256 _cputype=$(get_endianness
mips64
'' el
) 282 err
"unknown CPU type: $_cputype" 286 # Detect 64-bit linux with 32-bit userland 287 if [ "${_ostype}" = unknown-linux-gnu
] && [ "${_bitness}" -eq
32 ]; then 290 if [ -n
"${CPUTYPE:-}" ]; then 293 # 32-bit executable for amd64 = x32 294 if is_host_amd64_elf
; then { 295 echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>
&2 296 echo "and there isn't a native toolchain -- you will have to install" 1>
&2 297 echo "multiarch compatibility with i686 and/or amd64, then select one" 1>
&2 298 echo "by re-running this script with the CPUTYPE environment variable" 1>
&2 299 echo "set to i686 or x86_64, respectively." 1>
&2 307 _cputype=$(get_endianness
mips
'' el
) 314 if [ "$_ostype" = "linux-android" ]; then 315 _ostype=linux-androideabi
317 _ostype="${_ostype}eabihf" 321 err
"riscv64 with 32-bit userland unsupported" 326 if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7
]; then 327 if ensure
grep
'^Features' /proc/cpuinfo
| grep
-q
-v
neon
; then 328 # At least one processor does not have NEON. 333 _arch="${_cputype}-${_ostype}" 340 _mem_total=$(awk
'/MemTotal/ {print $2}' /proc/meminfo
) 346 local _mem_total="$RETVAL" 347 local _mem_min=8388608 # 8Gb in kB 348 if [ "$_mem_total" -lt
"$_mem_min" ]; then 349 err
"not enough memory: $_mem_total < $_mem_min"; 355 _disk_free=$(df
-kh
.
| tail
-n1
| awk
'{print $4}') 356 RETVAL="${_disk_free%?}" 361 local _disk_free="$RETVAL" 362 local _disk_min=32 # in Gigabytes 363 if [ "$_disk_free" -lt
"$_disk_min" ]; then 364 err
"not enough disk space: $_disk_free < $_disk_min" 369 local _kernel_version
370 _kernel_version=$(uname
-r
) 371 RETVAL="$_kernel_version" 375 if !
lsmod
| grep
-wq
"$1"; then 376 err
"kernel module $1 isn't loaded" 382 _num_cpus=$(grep
-c
'^processor' /proc/cpuinfo
2>/dev/null
) 384 # sysctl -n hw.ncpu # nproc --all 389 local _num_cpus="$RETVAL" 391 if [ "$_num_cpus" -lt
"$_min_cpus" ]; then 392 err
"not enough cpu threads ($_num_cpus < $_min_cpus)"