10fbfc30aSopenharmony_ci#!/bin/bash
20fbfc30aSopenharmony_ci
30fbfc30aSopenharmony_ci# ----------------------------------------------------------------------------
40fbfc30aSopenharmony_ci#  Hvigor startup script, version 1.0.0
50fbfc30aSopenharmony_ci#
60fbfc30aSopenharmony_ci#  Required ENV vars:
70fbfc30aSopenharmony_ci#  ------------------
80fbfc30aSopenharmony_ci#    NODE_HOME - location of a Node home dir
90fbfc30aSopenharmony_ci#    or
100fbfc30aSopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
110fbfc30aSopenharmony_ci# ----------------------------------------------------------------------------
120fbfc30aSopenharmony_ci
130fbfc30aSopenharmony_ciHVIGOR_APP_HOME="`pwd -P`"
140fbfc30aSopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
150fbfc30aSopenharmony_ciwarn() {
160fbfc30aSopenharmony_ci	echo ""
170fbfc30aSopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
180fbfc30aSopenharmony_ci}
190fbfc30aSopenharmony_ci
200fbfc30aSopenharmony_cierror() {
210fbfc30aSopenharmony_ci	echo ""
220fbfc30aSopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
230fbfc30aSopenharmony_ci}
240fbfc30aSopenharmony_ci
250fbfc30aSopenharmony_cifail() {
260fbfc30aSopenharmony_ci	error "$@"
270fbfc30aSopenharmony_ci	exit 1
280fbfc30aSopenharmony_ci}
290fbfc30aSopenharmony_ci
300fbfc30aSopenharmony_ci# Determine node to start hvigor wrapper script
310fbfc30aSopenharmony_ciif [ -n "${NODE_HOME}" ];then
320fbfc30aSopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
330fbfc30aSopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
340fbfc30aSopenharmony_ci       fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
350fbfc30aSopenharmony_ci   fi
360fbfc30aSopenharmony_cielse
370fbfc30aSopenharmony_ci   EXECUTABLE_NODE="node"
380fbfc30aSopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
390fbfc30aSopenharmony_cifi
400fbfc30aSopenharmony_ci
410fbfc30aSopenharmony_ci# Check hvigor wrapper script
420fbfc30aSopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
430fbfc30aSopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
440fbfc30aSopenharmony_cifi
450fbfc30aSopenharmony_ci
460fbfc30aSopenharmony_ci# start hvigor-wrapper script
470fbfc30aSopenharmony_ciexec "${EXECUTABLE_NODE}" \
480fbfc30aSopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
49