1 # Copyright (c) 2024-2024 Huawei Device Co., Ltd. 2 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # you may not use this file except in compliance with the License. 4 # You may obtain a copy of the License at 5 # 6 # http://www.apache.org/licenses/LICENSE-2.0 7 # 8 # Unless required by applicable law or agreed to in writing, software 9 # distributed under the License is distributed on an "AS IS" BASIS, 10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 # See the License for the specific language governing permissions and 12 # limitations under the License. 13 14 15 16 17#!/bin/bash 18 19# ---------------------------------------------------------------------------- 20# Hvigor startup script, version 1.0.0 21# 22# Required ENV vars: 23# ------------------ 24# NODE_HOME - location of a Node home dir 25# or 26# Add /usr/local/nodejs/bin to the PATH environment variable 27# ---------------------------------------------------------------------------- 28 29HVIGOR_APP_HOME="`pwd -P`" 30HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js 31warn() { 32 echo "" 33 echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 34} 35 36error() { 37 echo "" 38 echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 39} 40 41fail() { 42 error "$@" 43 exit 1 44} 45 46# Determine node to start hvigor wrapper script 47if [ -n "${NODE_HOME}" ];then 48 EXECUTABLE_NODE="${NODE_HOME}/bin/node" 49 if [ ! -x "$EXECUTABLE_NODE" ];then 50 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" 51 fi 52else 53 EXECUTABLE_NODE="node" 54 which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" 55fi 56 57# Check hvigor wrapper script 58if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then 59 fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" 60fi 61 62# start hvigor-wrapper script 63exec "${EXECUTABLE_NODE}" \ 64 "${HVIGOR_WRAPPER_SCRIPT}" "$@" 65