16e7c69efSopenharmony_ci#!/bin/bash
26e7c69efSopenharmony_ci
36e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
46e7c69efSopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd.
56e7c69efSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
66e7c69efSopenharmony_ci# you may not use this file except in compliance with the License.
76e7c69efSopenharmony_ci# You may obtain a copy of the License at
86e7c69efSopenharmony_ci#
96e7c69efSopenharmony_ci#  http://www.apache.org/licenses/LICENSE-2.0
106e7c69efSopenharmony_ci#
116e7c69efSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
126e7c69efSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
136e7c69efSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146e7c69efSopenharmony_ci# See the License for the specific language governing permissions and
156e7c69efSopenharmony_ci# limitations under the License.
166e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
176e7c69efSopenharmony_ci
186e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
196e7c69efSopenharmony_ci#  Hvigor startup script, version 1.0.0
206e7c69efSopenharmony_ci# 
216e7c69efSopenharmony_ci#  Required ENV vars:
226e7c69efSopenharmony_ci#  ------------------
236e7c69efSopenharmony_ci#    NODE_HOME - location of a Node home dir
246e7c69efSopenharmony_ci#    or 
256e7c69efSopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
266e7c69efSopenharmony_ci# ----------------------------------------------------------------------------
276e7c69efSopenharmony_ci
286e7c69efSopenharmony_ciHVIGOR_APP_HOME=$(dirname $(readlink -f $0))
296e7c69efSopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
306e7c69efSopenharmony_ciwarn() {
316e7c69efSopenharmony_ci	echo ""
326e7c69efSopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
336e7c69efSopenharmony_ci}
346e7c69efSopenharmony_ci
356e7c69efSopenharmony_cierror() {
366e7c69efSopenharmony_ci	echo ""
376e7c69efSopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
386e7c69efSopenharmony_ci}
396e7c69efSopenharmony_ci
406e7c69efSopenharmony_cifail() {
416e7c69efSopenharmony_ci	error "$@"
426e7c69efSopenharmony_ci	exit 1
436e7c69efSopenharmony_ci}
446e7c69efSopenharmony_ci
456e7c69efSopenharmony_ci# Determine node to start hvigor wrapper script
466e7c69efSopenharmony_ciif [ -n "${NODE_HOME}" ];then
476e7c69efSopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
486e7c69efSopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
496e7c69efSopenharmony_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"
506e7c69efSopenharmony_ci   fi
516e7c69efSopenharmony_cielse
526e7c69efSopenharmony_ci   EXECUTABLE_NODE="node"
536e7c69efSopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
546e7c69efSopenharmony_cifi
556e7c69efSopenharmony_ci
566e7c69efSopenharmony_ci# Check hvigor wrapper script
576e7c69efSopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
586e7c69efSopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
596e7c69efSopenharmony_cifi
606e7c69efSopenharmony_ci
616e7c69efSopenharmony_ci# start hvigor-wrapper script
626e7c69efSopenharmony_ciexec "${EXECUTABLE_NODE}" \
636e7c69efSopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
64