18c339a94Sopenharmony_ci#
28c339a94Sopenharmony_ci# Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
38c339a94Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
48c339a94Sopenharmony_ci# you may not use this file except in compliance with the License.
58c339a94Sopenharmony_ci# You may obtain a copy of the License at
68c339a94Sopenharmony_ci#
78c339a94Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
88c339a94Sopenharmony_ci#
98c339a94Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
108c339a94Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
118c339a94Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128c339a94Sopenharmony_ci# See the License for the specific language governing permissions and
138c339a94Sopenharmony_ci# limitations under the License.
148c339a94Sopenharmony_ci#
158c339a94Sopenharmony_ci
168c339a94Sopenharmony_ci#!/bin/bash
178c339a94Sopenharmony_ci
188c339a94Sopenharmony_ci# ----------------------------------------------------------------------------
198c339a94Sopenharmony_ci#  Hvigor startup script, version 1.0.0
208c339a94Sopenharmony_ci#
218c339a94Sopenharmony_ci#  Required ENV vars:
228c339a94Sopenharmony_ci#  ------------------
238c339a94Sopenharmony_ci#    NODE_HOME - location of a Node home dir
248c339a94Sopenharmony_ci#    or
258c339a94Sopenharmony_ci#    Add /usr/local/nodejs/bin to the PATH environment variable
268c339a94Sopenharmony_ci# ----------------------------------------------------------------------------
278c339a94Sopenharmony_ci
288c339a94Sopenharmony_ciHVIGOR_APP_HOME="`pwd -P`"
298c339a94Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
308c339a94Sopenharmony_ciwarn() {
318c339a94Sopenharmony_ci	echo ""
328c339a94Sopenharmony_ci	echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
338c339a94Sopenharmony_ci}
348c339a94Sopenharmony_ci
358c339a94Sopenharmony_cierror() {
368c339a94Sopenharmony_ci	echo ""
378c339a94Sopenharmony_ci	echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
388c339a94Sopenharmony_ci}
398c339a94Sopenharmony_ci
408c339a94Sopenharmony_cifail() {
418c339a94Sopenharmony_ci	error "$@"
428c339a94Sopenharmony_ci	exit 1
438c339a94Sopenharmony_ci}
448c339a94Sopenharmony_ci
458c339a94Sopenharmony_ci# Determine node to start hvigor wrapper script
468c339a94Sopenharmony_ciif [ -n "${NODE_HOME}" ];then
478c339a94Sopenharmony_ci   EXECUTABLE_NODE="${NODE_HOME}/bin/node"
488c339a94Sopenharmony_ci   if [ ! -x "$EXECUTABLE_NODE" ];then
498c339a94Sopenharmony_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"
508c339a94Sopenharmony_ci   fi
518c339a94Sopenharmony_cielse
528c339a94Sopenharmony_ci   EXECUTABLE_NODE="node"
538c339a94Sopenharmony_ci   which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
548c339a94Sopenharmony_cifi
558c339a94Sopenharmony_ci
568c339a94Sopenharmony_ci# Check hvigor wrapper script
578c339a94Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
588c339a94Sopenharmony_ci	fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
598c339a94Sopenharmony_cifi
608c339a94Sopenharmony_ci
618c339a94Sopenharmony_ci# start hvigor-wrapper script
628c339a94Sopenharmony_ciexec "${EXECUTABLE_NODE}" \
638c339a94Sopenharmony_ci	"${HVIGOR_WRAPPER_SCRIPT}" "$@"
64