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