15ccb8f90Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
25ccb8f90Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
35ccb8f90Sopenharmony_ci# you may not use this file except in compliance with the License.
45ccb8f90Sopenharmony_ci# You may obtain a copy of the License at
55ccb8f90Sopenharmony_ci#
65ccb8f90Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
75ccb8f90Sopenharmony_ci#
85ccb8f90Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
95ccb8f90Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
105ccb8f90Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115ccb8f90Sopenharmony_ci# See the License for the specific language governing permissions and
125ccb8f90Sopenharmony_ci# limitations under the License.
135ccb8f90Sopenharmony_ci
145ccb8f90Sopenharmony_ci#!/bin/bash
155ccb8f90Sopenharmony_ci
165ccb8f90Sopenharmony_ci# ----------------------------------------------------------------------------
175ccb8f90Sopenharmony_ci#  Hvigor startup script, version 1.0.0
185ccb8f90Sopenharmony_ci#
195ccb8f90Sopenharmony_ci#  Required ENV vars:
205ccb8f90Sopenharmony_ci#  ------------------
215ccb8f90Sopenharmony_ci#    NODE_HOME - location of a Node home dir
225ccb8f90Sopenharmony_ci#    or
235ccb8f90Sopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
245ccb8f90Sopenharmony_ci# ----------------------------------------------------------------------------
255ccb8f90Sopenharmony_ci
265ccb8f90Sopenharmony_ciHVIGOR_APP_HOME="`pwd -P`"
275ccb8f90Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
285ccb8f90Sopenharmony_ciwarn() {
295ccb8f90Sopenharmony_ci	echo ""
305ccb8f90Sopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
315ccb8f90Sopenharmony_ci}
325ccb8f90Sopenharmony_ci
335ccb8f90Sopenharmony_cierror() {
345ccb8f90Sopenharmony_ci	echo ""
355ccb8f90Sopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
365ccb8f90Sopenharmony_ci}
375ccb8f90Sopenharmony_ci
385ccb8f90Sopenharmony_cifail() {
395ccb8f90Sopenharmony_ci	error "$@"
405ccb8f90Sopenharmony_ci	exit 1
415ccb8f90Sopenharmony_ci}
425ccb8f90Sopenharmony_ci
435ccb8f90Sopenharmony_ci# Determine node to start hvigor wrapper script
445ccb8f90Sopenharmony_ciif [ -n "${NODE_HOME}" ];then
455ccb8f90Sopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
465ccb8f90Sopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
475ccb8f90Sopenharmony_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"
485ccb8f90Sopenharmony_ci   fi
495ccb8f90Sopenharmony_cielse
505ccb8f90Sopenharmony_ci   EXECUTABLE_NODE="node"
515ccb8f90Sopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
525ccb8f90Sopenharmony_cifi
535ccb8f90Sopenharmony_ci
545ccb8f90Sopenharmony_ci# Check hvigor wrapper script
555ccb8f90Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
565ccb8f90Sopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
575ccb8f90Sopenharmony_cifi
585ccb8f90Sopenharmony_ci
595ccb8f90Sopenharmony_ci# start hvigor-wrapper script
605ccb8f90Sopenharmony_ciexec "${EXECUTABLE_NODE}" \
615ccb8f90Sopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
62