1#!/bin/bash
2
3# ----------------------------------------------------------------------------
4#  Hvigor startup script, version 1.0.0
5#
6#  Required ENV vars:
7#  ------------------
8#    NODE_HOME - location of a Node home dir
9#    or
10#    Add /usr/local/nodejs/bin to the PATH environment variable
11# ----------------------------------------------------------------------------
12# ----------------------------------------------------------------------------
13# Copyright (c) 2023 Huawei Device Co., Ltd.
14# Licensed under the Apache License, Version 2.0 (the "License");
15# you may not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18#  http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS,
22# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25# ----------------------------------------------------------------------------
26HVIGOR_APP_HOME="`pwd -P`"
27HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
28warn() {
29	echo ""
30	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
31}
32
33error() {
34	echo ""
35	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
36}
37
38fail() {
39	error "$@"
40	exit 1
41}
42
43# Determine node to start hvigor wrapper script
44if [ -n "${NODE_HOME}" ];then
45   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
46   if [ ! -x "$EXECUTABLE_NODE" ];then
47       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"
48   fi
49else
50   EXECUTABLE_NODE="node"
51   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
52fi
53
54# Check hvigor wrapper script
55if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
56	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
57fi
58
59# start hvigor-wrapper script
60exec "${EXECUTABLE_NODE}" \
61	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
62