From 6824eec3084a1a77e0d702c292f6453400df669a Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 11 Feb 2022 17:41:36 +0300 Subject: [PATCH] Pull request: scripts: imp mips compat Updates #4269. Squashed commit of the following: commit f633e875f4f0ab767a0537d9bfe95734823f8a51 Author: Ainar Garipov Date: Fri Feb 11 17:33:53 2022 +0300 scripts: imp mips compat --- scripts/install.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 7cf35adc..8cad4609 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -39,8 +39,25 @@ is_command() { } # Function is_little_endian checks if the CPU is little-endian. +# +# See https://serverfault.com/a/163493/267530. is_little_endian() { - [ "$( head -c 6 /bin/sh | tail -c 1 )" = "$( printf '\001' )" ] + # The ASCII character "I" has the octal code of 111. In the two-byte octal + # display mode (-o), hexdump will print it either as "000111" on a little + # endian system or as a "111000" on a big endian one. Return the sixth + # character to compare it against the number '1'. + # + # Do not use echo -n, because its behavior in the presence of the -n flag is + # explicitly implementation-defined in POSIX. Use hexdump instead of od, + # because OpenWrt and its derivatives have the former but not the latter. + is_little_endian_result="$( + printf 'I'\ + | hexdump -o\ + | awk '{ print substr($2, 6, 1); exit; }' + )" + readonly is_little_endian_result + + [ "$is_little_endian_result" -eq '1' ] } # Function check_required checks if the required software is available on the