[Fix] avoid OpenBSD `nvm install` error when /sbin/init doesn't exist

`nvm install` fails with "Binary download failed, trying source" when
- running on Bash;
- errtrace (`set -E`) is enabled;
- an ERR trap uses `exit` to return a non-zero status; and
- /sbin/init doesn't exist.

Resolved by moving `ls -dl /sbin/init` to the following `if` statement.
In this context, returning non-zero isn't an error and the ERR trap
isn't executed.
Luke Arms 2021-12-26 15:31:53 +11:00 committed by Jordan Harband
parent 81f0f3ec19
commit 1875fe8b40
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 5 additions and 3 deletions

8
nvm.sh
View File

@ -1870,10 +1870,12 @@ nvm_get_arch() {
*) NVM_ARCH="${HOST_ARCH}" ;;
esac
# If running a 64bit ARM kernel but a 32bit ARM userland, change ARCH to 32bit ARM (armv7l)
# If running a 64bit ARM kernel but a 32bit ARM userland,
# change ARCH to 32bit ARM (armv7l) if /sbin/init is 32bit executable
local L
L=$(ls -dl /sbin/init 2>/dev/null) # if /sbin/init is 32bit executable
if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] && [ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then
if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] &&
L="$(ls -dl /sbin/init 2>/dev/null)" &&
[ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then
NVM_ARCH=armv7l
HOST_ARCH=armv7l
fi