#!/usr/bin/env sh

URL=https://github.com/NodeOS/nodejs/releases/download/v{version}/{platform}-{arch}.tar.gz


NODE_ARCH=$npm_config_arch


while getopts ":-:" opt; do
  case $opt in
    -)
      case "${OPTARG}" in
        arch=*)
          NODE_ARCH=${OPTARG#*=}
        ;;
      esac
    ::
  esac
done


case $NODE_ARCH in
  "")
  ;;

  arm)
    CPU=cortex-a7
  ;;

  arm64)
    CPU=cortex-a53
  ;;

  ia32)
    BITS=32
    MACHINE=pc
  ;;

  x64)
    BITS=64
    MACHINE=pc
  ;;

  *)
    echo "Unknown architecture $NODE_ARCH"
    exit 1
  ;;
esac


prebuild-install -d $URL || BITS=$BITS CPU=$CPU MACHINE=$MACHINE npm run build
