1315b9658Sopenharmony_ci#!/bin/bash
2315b9658Sopenharmony_ci
3315b9658Sopenharmony_ci# ----------------------------------------------------------------------------
4315b9658Sopenharmony_ci#  Hvigor startup script, version 1.0.0
5315b9658Sopenharmony_ci# 
6315b9658Sopenharmony_ci#  Required ENV vars:
7315b9658Sopenharmony_ci#  ------------------
8315b9658Sopenharmony_ci#    NODE_HOME - location of a Node home dir
9315b9658Sopenharmony_ci#    or 
10315b9658Sopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
11315b9658Sopenharmony_ci# ----------------------------------------------------------------------------
12315b9658Sopenharmony_ci
13315b9658Sopenharmony_ciHVIGOR_APP_HOME=$(dirname $(readlink -f $0))
14315b9658Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
15315b9658Sopenharmony_ciwarn() {
16315b9658Sopenharmony_ci	echo ""
17315b9658Sopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
18315b9658Sopenharmony_ci}
19315b9658Sopenharmony_ci
20315b9658Sopenharmony_cierror() {
21315b9658Sopenharmony_ci	echo ""
22315b9658Sopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
23315b9658Sopenharmony_ci}
24315b9658Sopenharmony_ci
25315b9658Sopenharmony_cifail() {
26315b9658Sopenharmony_ci	error "$@"
27315b9658Sopenharmony_ci	exit 1
28315b9658Sopenharmony_ci}
29315b9658Sopenharmony_ci
30315b9658Sopenharmony_ci# Determine node to start hvigor wrapper script
31315b9658Sopenharmony_ciif [ -n "${NODE_HOME}" ];then
32315b9658Sopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
33315b9658Sopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
34315b9658Sopenharmony_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"
35315b9658Sopenharmony_ci   fi
36315b9658Sopenharmony_cielse
37315b9658Sopenharmony_ci   EXECUTABLE_NODE="node"
38315b9658Sopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
39315b9658Sopenharmony_cifi
40315b9658Sopenharmony_ci
41315b9658Sopenharmony_ci# Check hvigor wrapper script
42315b9658Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
43315b9658Sopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
44315b9658Sopenharmony_cifi
45315b9658Sopenharmony_ci
46315b9658Sopenharmony_ci# start hvigor-wrapper script
47315b9658Sopenharmony_ciexec "${EXECUTABLE_NODE}" \
48315b9658Sopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
49