diff --git a/bin/nave b/bin/nave index a5c114a..11854e4 100755 --- a/bin/nave +++ b/bin/nave @@ -46,14 +46,16 @@ shopt -s extglob # Try to figure out the os and arch for binary fetching uname="$(uname -a)" os= -arch=x86 +arch= case "$uname" in Linux\ *) os=linux ;; Darwin\ *) os=darwin ;; SunOS\ *) os=sunos ;; esac case "$uname" in + *i386*) arch=x86 ;; *x86_64*) arch=x64 ;; + *raspberrypi*) arch=arm-pi ;; esac tar=${TAR-tar} @@ -213,12 +215,13 @@ nave_fetch () { local url local urls=( + "https://iojs.org/dist/v$version/iojs-v$version.tar.gz" "http://nodejs.org/dist/v$version/node-v$version.tar.gz" "http://nodejs.org/dist/node-v$version.tar.gz" "http://nodejs.org/dist/node-$version.tar.gz" ) for url in "${urls[@]}"; do - curl -#Lf "$url" > "$src".tgz + get -#Lf "$url" > "$src".tgz if [ $? -eq 0 ]; then $tar xzf "$src".tgz -C "$src" --strip-components=1 if [ $? -eq 0 ]; then @@ -234,6 +237,11 @@ nave_fetch () { return 1 } +get () { + curl -H "user-agent:nave/$(curl --version | head -n1)" "$@" + return $? +} + build () { local version="$1" @@ -248,25 +256,27 @@ build () { esac if [ $binavail -eq 1 ]; then local t="$version-$os-$arch" - local url="http://nodejs.org/dist/v$version/node-v${t}.tar.gz" local tgz="$NAVE_SRC/$t.tgz" - curl -#Lf "$url" > "$tgz" - if [ $? -ne 0 ]; then - # binary download failed. oh well. cleanup, and proceed. - rm "$tgz" - echo "Binary download failed, trying source." >&2 - else - # unpack straight into the build target. - $tar xzf "$tgz" -C "$2" --strip-components 1 + for url in "https://iojs.org/dist/v$version/iojs-v${t}.tar.gz" \ + "http://nodejs.org/dist/v$version/node-v${t}.tar.gz"; do + get -#Lf "$url" > "$tgz" if [ $? -ne 0 ]; then + # binary download failed. oh well. cleanup, and proceed. rm "$tgz" - nave_uninstall "$version" - echo "Binary unpack failed, trying source." >&2 + else + # unpack straight into the build target. + $tar xzf "$tgz" -C "$2" --strip-components 1 + if [ $? -ne 0 ]; then + rm "$tgz" + nave_uninstall "$version" + echo "Binary unpack failed, trying source." >&2 + fi + # it worked! + echo "installed from binary" >&2 + return 0 fi - # it worked! - echo "installed from binary" >&2 - return 0 - fi + done + echo "Binary download failed, trying source." >&2 fi fi @@ -321,6 +331,9 @@ nave_usemain () { nave_install () { local version=$(ver "$1") + if [ -z "$version" ]; then + fail "Must supply a version ('stable', 'latest' or numeric)" + fi if nave_installed "$version"; then echo "Already installed: $version" >&2 return 0 @@ -358,7 +371,7 @@ nave_ls () { } nave_ls_remote () { - curl -s http://nodejs.org/dist/ \ + get -s http://nodejs.org/dist/ \ | version_list "remote" \ || return 1 } @@ -394,21 +407,22 @@ ver () { nave_version_family () { local family="$1" family="${family/v/}" - curl -s http://nodejs.org/dist/ \ + { get -s http://nodejs.org/dist/; + get -s https://iojs.org/dist/; } \ | egrep -o $family'\.[0-9]+' \ | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ | tail -n1 } nave_latest () { - curl -s http://nodejs.org/dist/ \ + get -s https://iojs.org/dist/ \ | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ | tail -n1 } nave_stable () { - curl -s http://nodejs.org/dist/ \ + get -s http://nodejs.org/dist/ \ | egrep -o '[0-9]+\.[0-9]*[02468]\.[0-9]+' \ | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ | tail -n1 @@ -636,6 +650,7 @@ add_named_env () { ensure_dir "$NAVE_ROOT/$name/share/man" ln -sf -- "$NAVE_ROOT/$version/bin/node" "$NAVE_ROOT/$name/bin/node" + ln -sf -- "$NAVE_ROOT/$version/bin/npm" "$NAVE_ROOT/$name/bin/npm" ln -sf -- "$NAVE_ROOT/$version/bin/node-waf" "$NAVE_ROOT/$name/bin/node-waf" }