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