1794c9f46Sopenharmony_ci#!/bin/bash 2794c9f46Sopenharmony_ci 3794c9f46Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd. 4794c9f46Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 5794c9f46Sopenharmony_ci# you may not use this file except in compliance with the License. 6794c9f46Sopenharmony_ci# You may obtain a copy of the License at 7794c9f46Sopenharmony_ci# 8794c9f46Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 9794c9f46Sopenharmony_ci# 10794c9f46Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 11794c9f46Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 12794c9f46Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13794c9f46Sopenharmony_ci# See the License for the specific language governing permissions and 14794c9f46Sopenharmony_ci# limitations under the License. 15794c9f46Sopenharmony_ci 16794c9f46Sopenharmony_ci# ---------------------------------------------------------------------------- 17794c9f46Sopenharmony_ci# Hvigor startup script, version 1.0.0 18794c9f46Sopenharmony_ci# 19794c9f46Sopenharmony_ci# Required ENV vars: 20794c9f46Sopenharmony_ci# ------------------ 21794c9f46Sopenharmony_ci# NODE_HOME - location of a Node home dir 22794c9f46Sopenharmony_ci# or 23794c9f46Sopenharmony_ci# Add /usr/local/nodejs/bin to the PATH environment variable 24794c9f46Sopenharmony_ci# ---------------------------------------------------------------------------- 25794c9f46Sopenharmony_ci 26794c9f46Sopenharmony_ciHVIGOR_APP_HOME="`pwd -P`" 27794c9f46Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js 28794c9f46Sopenharmony_ciwarn() { 29794c9f46Sopenharmony_ci echo "" 30794c9f46Sopenharmony_ci echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 31794c9f46Sopenharmony_ci} 32794c9f46Sopenharmony_ci 33794c9f46Sopenharmony_cierror() { 34794c9f46Sopenharmony_ci echo "" 35794c9f46Sopenharmony_ci echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 36794c9f46Sopenharmony_ci} 37794c9f46Sopenharmony_ci 38794c9f46Sopenharmony_cifail() { 39794c9f46Sopenharmony_ci error "$@" 40794c9f46Sopenharmony_ci exit 1 41794c9f46Sopenharmony_ci} 42794c9f46Sopenharmony_ci 43794c9f46Sopenharmony_ci# Determine node to start hvigor wrapper script 44794c9f46Sopenharmony_ciif [ -n "${NODE_HOME}" ];then 45794c9f46Sopenharmony_ci EXECUTABLE_NODE="${NODE_HOME}/bin/node" 46794c9f46Sopenharmony_ci if [ ! -x "$EXECUTABLE_NODE" ];then 47794c9f46Sopenharmony_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" 48794c9f46Sopenharmony_ci fi 49794c9f46Sopenharmony_cielse 50794c9f46Sopenharmony_ci EXECUTABLE_NODE="node" 51794c9f46Sopenharmony_ci which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" 52794c9f46Sopenharmony_cifi 53794c9f46Sopenharmony_ci 54794c9f46Sopenharmony_ci# Check hvigor wrapper script 55794c9f46Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then 56794c9f46Sopenharmony_ci fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" 57794c9f46Sopenharmony_cifi 58794c9f46Sopenharmony_ci 59794c9f46Sopenharmony_ci# start hvigor-wrapper script 60794c9f46Sopenharmony_ciexec "${EXECUTABLE_NODE}" \ 61794c9f46Sopenharmony_ci "${HVIGOR_WRAPPER_SCRIPT}" "$@" 62