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