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