changeset 232: |
8b62bc1ae25c |
parent: |
b1a96e0e3add
|
child: |
7c6e3bbfe8cd |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sun, 26 May 2024 21:11:52 +0000 |
permissions: |
-rwxr-xr-x |
description: |
more porting over to skelfile |
19 host_config_file=$(cat
/proc/sys/kernel/hostname
).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" 52 say
"$1=$(eval echo "\$$1" 2>
/dev/null
)" 56 say
"$1" >>
$host_config_file 65 if [ -z
"$1" ]; then err
"assert_nz $2"; fi 69 command -v
"$1" >
/dev/null
2>
&1 73 if !
check_cmd
"$1"; then 74 err
"need '$1' (command not found)" 79 if !
"$@"; then err
"command failed: $*"; fi 83 # Check for /proc by looking for the /proc/self/exe link 84 # This is only run on Linux 85 if !
test -L
/proc/self/exe
; then 86 err
"fatal: Unable to find /proc/self/exe. Is /proc mounted? Installation cannot proceed without /proc." 91 # Architecture detection without dependencies beyond coreutils. 92 # ELF files start out "\x7fELF", and the following byte is 95 # The printf builtin on some shells like dash only supports octal 96 # escape sequences, so we use those. 97 local _current_exe_head
98 _current_exe_head=$(head
-c
5 /proc/self/exe
) 99 if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then 101 elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then 104 err
"unknown platform bitness" 108 is_host_amd64_elf
() { 109 # ELF e_machine detection without dependencies beyond coreutils. 110 # Two-byte field at offset 0x12 indicates the CPU, 111 # but we're interested in it being 0x3E to indicate amd64, or not that. 112 local _current_exe_machine
113 _current_exe_machine=$(head
-c
19 /proc/self/exe
| tail
-c
1) 114 [ "$_current_exe_machine" = "$(printf '\076')" ] 122 # detect endianness without od/hexdump, like get_bitness() does. 123 local _current_exe_endianness
124 _current_exe_endianness="$(head
-c
6 /proc/self/exe
| tail
-c
1)" 125 if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then 126 echo "${cputype}${suffix_el}" 127 elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then 128 echo "${cputype}${suffix_eb}" 130 err
"unknown platform endianness" 135 local _ostype
_cputype
_bitness
_arch
_clibtype
136 _ostype="$(uname
-s
)" 137 _cputype="$(uname
-m
)" 140 if [ "$_ostype" = Linux
]; then 141 if [ "$(uname
-o
)" = Android
]; then 144 if ldd
--version
2>
&1 | grep
-q
'musl'; then 149 if [ "$_ostype" = Darwin
] && [ "$_cputype" = i386
]; then 150 # Darwin `uname -m` lies 151 if sysctl
hw.optional.x86_64
| grep
-q
': 1'; then 156 if [ "$_ostype" = SunOS
]; then 157 # Both Solaris and illumos presently announce as "SunOS" in "uname -s" 158 # so use "uname -o" to disambiguate. We use the full path to the 159 # system uname in case the user has coreutils uname first in PATH, 160 # which has historically sometimes printed the wrong value here. 161 if [ "$(/usr/bin/uname
-o
)" = illumos
]; then 165 # illumos systems have multi-arch userlands, and "uname -m" reports the 166 # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86 167 # systems. Check for the native (widest) instruction set on the 169 if [ "$_cputype" = i86pc
]; then 170 _cputype="$(isainfo
-n
)" 177 _ostype=linux-android
182 _ostype=unknown-linux-
$_clibtype 183 _bitness=$(get_bitness
) 187 _ostype=unknown-freebsd
191 _ostype=unknown-netbsd
195 _ostype=unknown-dragonfly
203 _ostype=unknown-illumos
206 MINGW*
| MSYS*
| CYGWIN*
| Windows_NT
) 207 _ostype=pc-windows-gnu
211 err
"unrecognized OS type: $_ostype" 218 i386
| i486
| i686
| i786
| x86
) 224 if [ "$_ostype" = "linux-android" ]; then 225 _ostype=linux-androideabi
231 if [ "$_ostype" = "linux-android" ]; then 232 _ostype=linux-androideabi
234 _ostype="${_ostype}eabihf" 240 if [ "$_ostype" = "linux-android" ]; then 241 _ostype=linux-androideabi
243 _ostype="${_ostype}eabihf" 251 x86_64
| x86-64
| x64
| amd64
) 256 _cputype=$(get_endianness
mips
'' el
) 260 if [ "$_bitness" -eq
64 ]; then 261 # only n64 ABI is supported for now 262 _ostype="${_ostype}abi64" 263 _cputype=$(get_endianness
mips64
'' el
) 289 err
"unknown CPU type: $_cputype" 293 # Detect 64-bit linux with 32-bit userland 294 if [ "${_ostype}" = unknown-linux-gnu
] && [ "${_bitness}" -eq
32 ]; then 297 if [ -n
"${CPUTYPE:-}" ]; then 300 # 32-bit executable for amd64 = x32 301 if is_host_amd64_elf
; then { 302 echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>
&2 303 echo "and there isn't a native toolchain -- you will have to install" 1>
&2 304 echo "multiarch compatibility with i686 and/or amd64, then select one" 1>
&2 305 echo "by re-running this script with the CPUTYPE environment variable" 1>
&2 306 echo "set to i686 or x86_64, respectively." 1>
&2 314 _cputype=$(get_endianness
mips
'' el
) 321 if [ "$_ostype" = "linux-android" ]; then 322 _ostype=linux-androideabi
324 _ostype="${_ostype}eabihf" 328 err
"riscv64 with 32-bit userland unsupported" 333 if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7
]; then 334 if ensure
grep
'^Features' /proc/cpuinfo
| grep
-q
-v
neon
; then 335 # At least one processor does not have NEON. 340 _arch="${_cputype}-${_ostype}" 347 _mem_total=$(awk
'/MemTotal/ {print $2}' /proc/meminfo
) 353 local _mem_total="$RETVAL" 354 local _mem_min=8388608 # 8Gb in kB 355 if [ "$_mem_total" -lt
"$_mem_min" ]; then 356 err
"not enough memory: $_mem_total < $_mem_min"; 362 _disk_free=$(df
.
| tail
-n1
| awk
'{print $4}') 363 RETVAL="${_disk_free}" 368 local _disk_free="$RETVAL" 369 local _disk_min=33554432 # in bytes 370 if [ "$_disk_free" -lt
"$_disk_min" ]; then 371 err
"not enough disk space: $_disk_free < $_disk_min" 376 local _kernel_version
377 _kernel_version=$(uname
-r
) 378 RETVAL="$_kernel_version" 382 if !
lsmod
| grep
-wq
"$1"; then 383 err
"kernel module $1 isn't loaded" 389 _num_cpus=$(grep
-c
'^processor' /proc/cpuinfo
2>/dev/null
) 391 # sysctl -n hw.ncpu # nproc --all 396 local _num_cpus="$RETVAL" 398 if [ "$_num_cpus" -lt
"$_min_cpus" ]; then 399 err
"not enough cpu threads ($_num_cpus < $_min_cpus)" 409 say_var
INSTALL_PREFIX