1#!/bin/bash 2# Copyright (c) 2022 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14set -e 15while [ $# -gt 0 ]; do 16 case "$1" in 17 -skip-ssl|--skip-ssl) # wget、npm skip ssl check, which will allow 18 # hacker to get and modify data stream between server and client! 19 SKIP_SSL=YES 20 ;; 21 -h|--help) 22 HELP=YES 23 ;; 24 --tool-repo) 25 TOOL_REPO="$2" 26 shift 27 ;; 28 --tool-repo=*) 29 TOOL_REPO="${1#--tool-repo=}" 30 ;; 31 --npm-registry) 32 NPM_REGISTRY="$2" 33 shift 34 ;; 35 --npm-registry=*) 36 NPM_REGISTRY="${1#--npm-registry=}" 37 ;; 38 --trusted-host) 39 TRUSTED_HOST="$2" 40 shift 41 ;; 42 --trusted-host=*) 43 TRUSTED_HOST="${1#--trusted-host=}" 44 ;; 45 --pypi-url) # python package index url 46 PYPI_URL="$2" 47 shift 48 ;; 49 --pypi-url=*) 50 PYPI_URL="${1#--pypi-url=}" 51 ;; 52 *) 53 echo "$0: Warning: unsupported parameter: $1" >&2 54 ;; 55 esac 56 shift 57done 58 59case $(uname -s) in 60 Linux) 61 62 host_platform=linux 63 ;; 64 Darwin) 65 host_platform=darwin 66 ;; 67 *) 68 echo "Unsupported host platform: $(uname -s)" 69 exit 1 70esac 71 72case $(uname -m) in 73 arm64) 74 75 host_cpu=arm64 76 ;; 77 *) 78 host_cpu=x86_64 79esac 80 81if [ "X${SKIP_SSL}" == "XYES" ];then 82 wget_ssl_check="--skip-ssl" 83else 84 wget_ssl_check='' 85fi 86 87if [ "X${HELP}" == "XYES" ];then 88 help="-h" 89else 90 help='' 91fi 92 93if [ ! -z "$TOOL_REPO" ];then 94 tool_repo="--tool-repo $TOOL_REPO" 95else 96 tool_repo='' 97fi 98 99if [ ! -z "$NPM_REGISTRY" ];then 100 npm_registry="--npm-registry $NPM_REGISTRY" 101else 102 npm_registry='' 103fi 104 105if [ ! -z "$TRUSTED_HOST" ];then 106 trusted_host=$TRUSTED_HOST 107elif [ ! -z "$PYPI_URL" ];then 108 trusted_host=${PYPI_URL/#*:\/\//} # remove prefix part such as http:// https:// etc. 109 trusted_host=${trusted_host/%[:\/]*/} # remove suffix part including the port number 110else 111 trusted_host='repo.huaweicloud.com' 112fi 113 114if [ ! -z "$PYPI_URL" ];then 115 pypi_url=$PYPI_URL 116else 117 pypi_url='http://repo.huaweicloud.com/repository/pypi/simple' 118fi 119 120if [ $UID -ne 0 ]; then 121 npm_para='' 122else 123 npm_para='--unsafe-perm' 124fi 125 126cpu="--host-cpu $host_cpu" 127platform="--host-platform $host_platform" 128 129script_path=$(cd $(dirname $0);pwd) 130code_dir=$(dirname ${script_path}) 131pip3 install --trusted-host $trusted_host -i $pypi_url rich 132echo "prebuilts_download start" 133python3 "${code_dir}/prebuilts_download/prebuilts_download.py" $wget_ssl_check $tool_repo $npm_registry $help $cpu $platform $npm_para 134echo "prebuilts_download end" 135 136echo -e "\n" 137