Skip to content

Commit

Permalink
Check installed node version
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Weigel committed Feb 6, 2019
1 parent 4f29367 commit 72082ad
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions hapi-server
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

versionmin="v6.0.0"
# Note that code can only test major version.
# Also note that assuming posix shell.
versionmin="6"

# From https://unix.stackexchange.com/a/76518
path=$(exec 2>/dev/null;cd -- $(dirname "$0"); unset PWD; /usr/bin/pwd || /bin/pwd || pwd)
Expand All @@ -15,23 +17,33 @@ fi

# Use node in path if version > versionmin
if command -v node > /dev/null 2>&1; then
version=$(node -v)
if test $version > $versionmin; then
node $com
exit 0
version=$(node -v)
version=${version//v/}
version="${version%%.*}"
if test $version -gt $(($versionmin-1)); then
echo "Using system node binary with version = $version."
node $com
exit 0
else
echo "System node binary version = $version. Version $versionmin+ required."
fi
elif command -v nodejs > /dev/null 2>&1; then
version=$(nodejs -v)
if test $version > $versionmin; then
nodejs $com
exit 0
version=$(node -v)
version=${version//v/}
version="${version%%.*}"
if test $version -gt $(($versionmin-1)); then
echo "Using system nodejs binary with version = $version."
nodejs $com
exit 0
else
echo "System nodejs binary version = $version. Version $versionmin+ required."
fi
fi

# Use node in hapi-server package
if command -v $path"/bin/node" > /dev/null 2>&1; then
$path"/bin/node" $com
else
echo "Did not find "$(dirname "$SCRIPT")"/bin/node, node, or nodejs"
echo "Did not find $path/bin/node, node, or nodejs."
exit 1
fi

0 comments on commit 72082ad

Please sign in to comment.