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