1697b4da4Sopenharmony_ci/** 2697b4da4Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3697b4da4Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4697b4da4Sopenharmony_ci * you may not use this file except in compliance with the License. 5697b4da4Sopenharmony_ci * You may obtain a copy of the License at 6697b4da4Sopenharmony_ci * 7697b4da4Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8697b4da4Sopenharmony_ci * 9697b4da4Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10697b4da4Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11697b4da4Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12697b4da4Sopenharmony_ci * See the License for the specific language governing permissions and 13697b4da4Sopenharmony_ci * limitations under the License. 14697b4da4Sopenharmony_ci */ 15697b4da4Sopenharmony_ci 16697b4da4Sopenharmony_ci#!/bin/bash 17697b4da4Sopenharmony_ci 18697b4da4Sopenharmony_ci# ---------------------------------------------------------------------------- 19697b4da4Sopenharmony_ci# Hvigor startup script, version 1.0.0 20697b4da4Sopenharmony_ci# 21697b4da4Sopenharmony_ci# Required ENV vars: 22697b4da4Sopenharmony_ci# ------------------ 23697b4da4Sopenharmony_ci# NODE_HOME - location of a Node home dir 24697b4da4Sopenharmony_ci# or 25697b4da4Sopenharmony_ci# Add /usr/local/nodejs/bin to the PATH environment variable 26697b4da4Sopenharmony_ci# ---------------------------------------------------------------------------- 27697b4da4Sopenharmony_ci 28697b4da4Sopenharmony_ciHVIGOR_APP_HOME=$(dirname $(readlink -f $0)) 29697b4da4Sopenharmony_ciHVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js 30697b4da4Sopenharmony_ciwarn() { 31697b4da4Sopenharmony_ci echo "" 32697b4da4Sopenharmony_ci echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 33697b4da4Sopenharmony_ci} 34697b4da4Sopenharmony_ci 35697b4da4Sopenharmony_cierror() { 36697b4da4Sopenharmony_ci echo "" 37697b4da4Sopenharmony_ci echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" 38697b4da4Sopenharmony_ci} 39697b4da4Sopenharmony_ci 40697b4da4Sopenharmony_cifail() { 41697b4da4Sopenharmony_ci error "$@" 42697b4da4Sopenharmony_ci exit 1 43697b4da4Sopenharmony_ci} 44697b4da4Sopenharmony_ci 45697b4da4Sopenharmony_ci# Determine node to start hvigor wrapper script 46697b4da4Sopenharmony_ciif [ -n "${NODE_HOME}" ];then 47697b4da4Sopenharmony_ci EXECUTABLE_NODE="${NODE_HOME}/bin/node" 48697b4da4Sopenharmony_ci if [ ! -x "$EXECUTABLE_NODE" ];then 49697b4da4Sopenharmony_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" 50697b4da4Sopenharmony_ci fi 51697b4da4Sopenharmony_cielse 52697b4da4Sopenharmony_ci EXECUTABLE_NODE="node" 53697b4da4Sopenharmony_ci which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" 54697b4da4Sopenharmony_cifi 55697b4da4Sopenharmony_ci 56697b4da4Sopenharmony_ci# Check hvigor wrapper script 57697b4da4Sopenharmony_ciif [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then 58697b4da4Sopenharmony_ci fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" 59697b4da4Sopenharmony_cifi 60697b4da4Sopenharmony_ci 61697b4da4Sopenharmony_ci# start hvigor-wrapper script 62697b4da4Sopenharmony_ciexec "${EXECUTABLE_NODE}" \ 63697b4da4Sopenharmony_ci "${HVIGOR_WRAPPER_SCRIPT}" "$@" 64