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