#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
# nodejs-maven-plugin incorrectly detects the architecture on 
# Linux x64 running 32 bit Java leading to the installation of
# invalid nodejs binary - 32 bit on 64 bit OS. This is a
# wrapper which makes a check for the architecture again and
# forces the usage of the 64 bit binary. The 64 bit nodejs
# is installed in advance in case we need it.
#
# target/nodejs64/node - the forcibly installed 64 bit binary
# target/nodejs/node - the binary installed by nodejs-maven-plugin
#                      could be 32 bit or 64 bit.
#

MACHINE_TYPE=`uname -m`
if [ $MACHINE_TYPE = 'x86_64' ]; then
  NODE_PATH=$( dirname "$0" )/../../target/nodejs64/node
  chmod +x $NODE_PATH
  echo Forcing 64 bit nodejs at $NODE_PATH
else
  NODE_PATH=$( dirname "$0" )/../../target/nodejs/node
fi

$NODE_PATH "$@"
