131c75014Sopenharmony_ci# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. 231c75014Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 331c75014Sopenharmony_ci# you may not use this file except in compliance with the License. 431c75014Sopenharmony_ci# You may obtain a copy of the License at 531c75014Sopenharmony_ci# 631c75014Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 731c75014Sopenharmony_ci# 831c75014Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 931c75014Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1031c75014Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1131c75014Sopenharmony_ci# See the License for the specific language governing permissions and 1231c75014Sopenharmony_ci# limitations under the License. 1331c75014Sopenharmony_ci 1431c75014Sopenharmony_ci#!/bin/bash 1531c75014Sopenharmony_ci 1631c75014Sopenharmony_ci# ---------------------------------------------------------------------------- 1731c75014Sopenharmony_ci# Hvigor startup script, version 1.0.0 1831c75014Sopenharmony_ci# 1931c75014Sopenharmony_ci# Required ENV vars: 2031c75014Sopenharmony_ci# ------------------ 2131c75014Sopenharmony_ci# NODE_HOME - location of a Node home dir 2231c75014Sopenharmony_ci# or 2331c75014Sopenharmony_ci# Add /usr/local/nodejs/bin to the PATH environment variable 2431c75014Sopenharmony_ci# ---------------------------------------------------------------------------- 2531c75014Sopenharmony_ci 2631c75014Sopenharmony_ciHVIGOR_APP_HOME=$(dirname $(readlink -f $0)) 2731c75014Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js 2831c75014Sopenharmony_ciwarn() { 2931c75014Sopenharmony_ci echo "" 3031c75014Sopenharmony_ci echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 3131c75014Sopenharmony_ci} 3231c75014Sopenharmony_ci 3331c75014Sopenharmony_cierror() { 3431c75014Sopenharmony_ci echo "" 3531c75014Sopenharmony_ci echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 3631c75014Sopenharmony_ci} 3731c75014Sopenharmony_ci 3831c75014Sopenharmony_cifail() { 3931c75014Sopenharmony_ci error "$@" 4031c75014Sopenharmony_ci exit 1 4131c75014Sopenharmony_ci} 4231c75014Sopenharmony_ci 4331c75014Sopenharmony_ci# Determine node to start hvigor wrapper script 4431c75014Sopenharmony_ciif [ -n "${NODE_HOME}" ];then 4531c75014Sopenharmony_ci EXECUTABLE_NODE="${NODE_HOME}/bin/node" 4631c75014Sopenharmony_ci if [ ! -x "$EXECUTABLE_NODE" ];then 4731c75014Sopenharmony_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" 4831c75014Sopenharmony_ci fi 4931c75014Sopenharmony_cielse 5031c75014Sopenharmony_ci EXECUTABLE_NODE="node" 5131c75014Sopenharmony_ci which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" 5231c75014Sopenharmony_cifi 5331c75014Sopenharmony_ci 5431c75014Sopenharmony_ci# Check hvigor wrapper script 5531c75014Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then 5631c75014Sopenharmony_ci fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" 5731c75014Sopenharmony_cifi 5831c75014Sopenharmony_ci 5931c75014Sopenharmony_ci# start hvigor-wrapper script 6031c75014Sopenharmony_ciexec "${EXECUTABLE_NODE}" \ 6131c75014Sopenharmony_ci "${HVIGOR_WRAPPER_SCRIPT}" "$@" 62