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