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