• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2024 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
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#!/bin/bash
27
28# ----------------------------------------------------------------------------
29#  Hvigor startup script, version 1.0.0
30#
31#  Required ENV vars:
32#  ------------------
33#    NODE_HOME - location of a Node home dir
34#    or
35#    Add /usr/local/nodejs/bin to the PATH environment variable
36# ----------------------------------------------------------------------------
37
38HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
39HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
40warn() {
41	echo ""
42	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
43}
44
45error() {
46	echo ""
47	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
48}
49
50fail() {
51	error "$@"
52	exit 1
53}
54
55# Determine node to start hvigor wrapper script
56if [ -n "${NODE_HOME}" ];then
57   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
58   if [ ! -x "$EXECUTABLE_NODE" ];then
59       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"
60   fi
61else
62   EXECUTABLE_NODE="node"
63   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
64fi
65
66# Check hvigor wrapper script
67if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
68	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
69fi
70
71# start hvigor-wrapper script
72exec "${EXECUTABLE_NODE}" \
73	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
74