changeset 218: |
f88e8a46080b |
parent: |
98abb7f50885
|
child: |
b1a96e0e3add |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 30 Apr 2024 22:35:33 -0400 |
permissions: |
-rwxr-xr-x |
description: |
check mem |
19 host_config_file=host.sxp
20 rm
-f
$host_config_file 22 local _mem_total="$RETVAL" 25 get_architecture
|| return 1 27 assert_nz
"$_arch" "arch" 28 _write
";; -*- mode:skel -*-" 29 _write
":arch \"$_arch\"" 31 local _kernel_version="$RETVAL" 32 _write
":kernel \"$_kernel_version\"" 34 local _num_cpus="$RETVAL" 35 _write
":cpus $_num_cpus" 36 _write
":mem $_mem_total" 51 say
"$1" >>
$host_config_file 60 if [ -z
"$1" ]; then err
"assert_nz $2"; fi 64 command -v
"$1" >
/dev/null
2>
&1 68 if !
check_cmd
"$1"; then 69 err
"need '$1' (command not found)" 74 if !
"$@"; then err
"command failed: $*"; fi 78 # Check for /proc by looking for the /proc/self/exe link 79 # This is only run on Linux 80 if !
test -L
/proc/self/exe
; then 81 err
"fatal: Unable to find /proc/self/exe. Is /proc mounted? Installation cannot proceed without /proc." 86 # Architecture detection without dependencies beyond coreutils. 87 # ELF files start out "\x7fELF", and the following byte is 90 # The printf builtin on some shells like dash only supports octal 91 # escape sequences, so we use those. 92 local _current_exe_head
93 _current_exe_head=$(head
-c
5 /proc/self/exe
) 94 if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then 96 elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then 99 err
"unknown platform bitness" 103 is_host_amd64_elf
() { 104 # ELF e_machine detection without dependencies beyond coreutils. 105 # Two-byte field at offset 0x12 indicates the CPU, 106 # but we're interested in it being 0x3E to indicate amd64, or not that. 107 local _current_exe_machine
108 _current_exe_machine=$(head
-c
19 /proc/self/exe
| tail
-c
1) 109 [ "$_current_exe_machine" = "$(printf '\076')" ] 117 # detect endianness without od/hexdump, like get_bitness() does. 118 local _current_exe_endianness
119 _current_exe_endianness="$(head
-c
6 /proc/self/exe
| tail
-c
1)" 120 if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then 121 echo "${cputype}${suffix_el}" 122 elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then 123 echo "${cputype}${suffix_eb}" 125 err
"unknown platform endianness" 130 local _ostype
_cputype
_bitness
_arch
_clibtype
131 _ostype="$(uname
-s
)" 132 _cputype="$(uname
-m
)" 135 if [ "$_ostype" = Linux
]; then 136 if [ "$(uname
-o
)" = Android
]; then 139 if ldd
--version
2>
&1 | grep
-q
'musl'; then 144 if [ "$_ostype" = Darwin
] && [ "$_cputype" = i386
]; then 145 # Darwin `uname -m` lies 146 if sysctl
hw.optional.x86_64
| grep
-q
': 1'; then 151 if [ "$_ostype" = SunOS
]; then 152 # Both Solaris and illumos presently announce as "SunOS" in "uname -s" 153 # so use "uname -o" to disambiguate. We use the full path to the 154 # system uname in case the user has coreutils uname first in PATH, 155 # which has historically sometimes printed the wrong value here. 156 if [ "$(/usr/bin/uname
-o
)" = illumos
]; then 160 # illumos systems have multi-arch userlands, and "uname -m" reports the 161 # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86 162 # systems. Check for the native (widest) instruction set on the 164 if [ "$_cputype" = i86pc
]; then 165 _cputype="$(isainfo
-n
)" 172 _ostype=linux-android
177 _ostype=unknown-linux-
$_clibtype 178 _bitness=$(get_bitness
) 182 _ostype=unknown-freebsd
186 _ostype=unknown-netbsd
190 _ostype=unknown-dragonfly
198 _ostype=unknown-illumos
201 MINGW*
| MSYS*
| CYGWIN*
| Windows_NT
) 202 _ostype=pc-windows-gnu
206 err
"unrecognized OS type: $_ostype" 213 i386
| i486
| i686
| i786
| x86
) 219 if [ "$_ostype" = "linux-android" ]; then 220 _ostype=linux-androideabi
226 if [ "$_ostype" = "linux-android" ]; then 227 _ostype=linux-androideabi
229 _ostype="${_ostype}eabihf" 235 if [ "$_ostype" = "linux-android" ]; then 236 _ostype=linux-androideabi
238 _ostype="${_ostype}eabihf" 246 x86_64
| x86-64
| x64
| amd64
) 251 _cputype=$(get_endianness
mips
'' el
) 255 if [ "$_bitness" -eq
64 ]; then 256 # only n64 ABI is supported for now 257 _ostype="${_ostype}abi64" 258 _cputype=$(get_endianness
mips64
'' el
) 284 err
"unknown CPU type: $_cputype" 288 # Detect 64-bit linux with 32-bit userland 289 if [ "${_ostype}" = unknown-linux-gnu
] && [ "${_bitness}" -eq
32 ]; then 292 if [ -n
"${CPUTYPE:-}" ]; then 295 # 32-bit executable for amd64 = x32 296 if is_host_amd64_elf
; then { 297 echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>
&2 298 echo "and there isn't a native toolchain -- you will have to install" 1>
&2 299 echo "multiarch compatibility with i686 and/or amd64, then select one" 1>
&2 300 echo "by re-running this script with the CPUTYPE environment variable" 1>
&2 301 echo "set to i686 or x86_64, respectively." 1>
&2 309 _cputype=$(get_endianness
mips
'' el
) 316 if [ "$_ostype" = "linux-android" ]; then 317 _ostype=linux-androideabi
319 _ostype="${_ostype}eabihf" 323 err
"riscv64 with 32-bit userland unsupported" 328 if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7
]; then 329 if ensure
grep
'^Features' /proc/cpuinfo
| grep
-q
-v
neon
; then 330 # At least one processor does not have NEON. 335 _arch="${_cputype}-${_ostype}" 342 _mem_total=$(awk
'/MemTotal/ {print $2}' /proc/meminfo
) 348 local _mem_total="$RETVAL" 349 local _mem_min=8388608 # 8Gb in kB 350 if [ "$_mem_total" -lt
"$_mem_min" ]; then 351 err
"not enough memory: $_mem_total < $_mem_min"; 357 _disk_free=$(df
.
| tail
-n1
| awk
'{print $4}') 358 RETVAL="${_disk_free}" 363 local _disk_free="$RETVAL" 364 local _disk_min=33554432 # in bytes 365 if [ "$_disk_free" -lt
"$_disk_min" ]; then 366 err
"not enough disk space: $_disk_free < $_disk_min" 371 local _kernel_version
372 _kernel_version=$(uname
-r
) 373 RETVAL="$_kernel_version" 377 if !
lsmod
| grep
-wq
"$1"; then 378 err
"kernel module $1 isn't loaded" 384 _num_cpus=$(grep
-c
'^processor' /proc/cpuinfo
2>/dev/null
) 386 # sysctl -n hw.ncpu # nproc --all 391 local _num_cpus="$RETVAL" 393 if [ "$_num_cpus" -lt
"$_min_cpus" ]; then 394 err
"not enough cpu threads ($_num_cpus < $_min_cpus)"