10704ebd2Sopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd.
20704ebd2Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
30704ebd2Sopenharmony_ci# you may not use this file except in compliance with the License.
40704ebd2Sopenharmony_ci# You may obtain a copy of the License at
50704ebd2Sopenharmony_ci#
60704ebd2Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
70704ebd2Sopenharmony_ci#
80704ebd2Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
90704ebd2Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
100704ebd2Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
110704ebd2Sopenharmony_ci# See the License for the specific language governing permissions and
120704ebd2Sopenharmony_ci# limitations under the License.
130704ebd2Sopenharmony_ci#!/bin/bash
140704ebd2Sopenharmony_ci
150704ebd2Sopenharmony_ci# ----------------------------------------------------------------------------
160704ebd2Sopenharmony_ci#  Hvigor startup script, version 1.0.0
170704ebd2Sopenharmony_ci# 
180704ebd2Sopenharmony_ci#  Required ENV vars:
190704ebd2Sopenharmony_ci#  ------------------
200704ebd2Sopenharmony_ci#    NODE_HOME - location of a Node home dir
210704ebd2Sopenharmony_ci#    or 
220704ebd2Sopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
230704ebd2Sopenharmony_ci# ----------------------------------------------------------------------------
240704ebd2Sopenharmony_ci
250704ebd2Sopenharmony_ciHVIGOR_APP_HOME=$(dirname $(readlink -f $0))
260704ebd2Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
270704ebd2Sopenharmony_ciwarn() {
280704ebd2Sopenharmony_ci	echo ""
290704ebd2Sopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
300704ebd2Sopenharmony_ci}
310704ebd2Sopenharmony_ci
320704ebd2Sopenharmony_cierror() {
330704ebd2Sopenharmony_ci	echo ""
340704ebd2Sopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
350704ebd2Sopenharmony_ci}
360704ebd2Sopenharmony_ci
370704ebd2Sopenharmony_cifail() {
380704ebd2Sopenharmony_ci	error "$@"
390704ebd2Sopenharmony_ci	exit 1
400704ebd2Sopenharmony_ci}
410704ebd2Sopenharmony_ci
420704ebd2Sopenharmony_ci# Determine node to start hvigor wrapper script
430704ebd2Sopenharmony_ciif [ -n "${NODE_HOME}" ];then
440704ebd2Sopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
450704ebd2Sopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
460704ebd2Sopenharmony_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"
470704ebd2Sopenharmony_ci   fi
480704ebd2Sopenharmony_cielse
490704ebd2Sopenharmony_ci   EXECUTABLE_NODE="node"
500704ebd2Sopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
510704ebd2Sopenharmony_cifi
520704ebd2Sopenharmony_ci
530704ebd2Sopenharmony_ci# Check hvigor wrapper script
540704ebd2Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
550704ebd2Sopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
560704ebd2Sopenharmony_cifi
570704ebd2Sopenharmony_ci
580704ebd2Sopenharmony_ci# start hvigor-wrapper script
590704ebd2Sopenharmony_ciexec "${EXECUTABLE_NODE}" \
600704ebd2Sopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
61