• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2021 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
15for i in "$@"; do
16  case "$i" in
17    -skip-ssl|--skip-ssl) # wget、npm跳过ssl检查,如使用此参数:
18    # 黑客等不法分子可以篡改或窃取客户端和服务器之间传输的信息和数据,从而影响用户的数据安全!
19    SKIP_SSL=YES
20    ;;
21  esac
22done
23if [ "X${SKIP_SSL}" == "XYES" ];then
24    wget_ssl_check='--no-check-certificate'
25else
26    wget_ssl_check=''
27fi
28
29if [ -z "$TOOL_REPO" ];then
30	tool_repo='https://repo.huaweicloud.com'
31else
32	tool_repo=$TOOL_REPO
33fi
34echo "tool_repo=$tool_repo"
35
36if [ -z "$NPM_REGISTRY" ];then
37	npm_registry='https://repo.huaweicloud.com/repository/npm/'
38else
39	npm_registry=$NPM_REGISTRY
40fi
41echo "npm_registry=$npm_registry"
42
43sha256_result=0
44check_sha256=''
45local_sha256=''
46function check_sha256(){
47    success_color='\033[1;42mSuccess\033[0m'
48    failed_color='\033[1;41mFailed\033[0m'
49    check_url=$1 #来源URL
50    local_file=$2  #本地文件绝对路径
51    check_sha256=$(curl -s -k ${check_url}.sha256)  # 当前使用华为云,URL固定,所以写死了,后续如果有变动,此处需要修改
52    local_sha256=$(sha256sum ${local_file} |awk '{print $1}')
53    if [ "X${check_sha256}" == "X${local_sha256}" ];then
54        echo -e "${success_color},${check_url} Sha256 check OK."
55        sha256_result=0
56    else
57        echo -e "${failed_color},${check_url} Sha256 check Failed.Retry!"
58        sha256_result=1
59        #exit 1  # 默认退出,必须保证sha256一致,如有特殊需要,请自行注释
60    fi
61}
62function hwcloud_download(){
63    # 代理不需要鉴权: wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://domain.com:port" ${huaweicloud_url}
64    # 代理需要鉴权(账号密码特殊字符均需要URL转义): wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://username:password@domain.com:port" ${huaweicloud_url}
65    # 不需要代理
66    download_local_file=$1
67    download_source_url=$2
68    for((i=1;i<=3;i++));
69    do
70        if [ -f "${download_local_file}" ];then
71            check_sha256 "${download_source_url}" "${download_local_file}"
72            if [ ${sha256_result} -gt 0 ];then
73                # 设置变量默认值,防止误删除
74                rm -rf "${download_local_file:-/tmp/20210721_not_exit_file}"
75            else
76                i=999
77                return 0
78            fi
79        fi
80        if [ ! -f "${download_local_file}" ];then
81            wget -t3 -T10 ${wget_ssl_check} -O  "${download_local_file}" "${download_source_url}"
82        fi
83    done
84    # 连续三次失败后报错退出
85    echo -e """Sha256 check failed!
86Download URL: ${download_source_url}
87Local file: ${download_local_file}
88Remote sha256: ${check_sha256}
89Local sha256: ${local_sha256}"""
90    exit 1
91}
92
93case $(uname -s) in
94    Linux)
95        host_platform=linux
96        ;;
97    Darwin)
98        host_platform=darwin
99        ;;
100    *)
101        echo "Unsupported host platform: $(uname -s)"
102        exit 1
103esac
104
105# 代码下载目录
106script_path=$(cd $(dirname $0);pwd)
107code_dir=$(dirname ${script_path})
108# 二进制所在目录,用于临时存放二进制,需要约7G空间
109# 下载的压缩包会自动解压到代码目录,压缩包会一直保留在该目录下
110bin_dir=${code_dir}/../OpenHarmony_2.0_canary_prebuilts
111
112# 二进制关系
113copy_config="""
114prebuilts/sdk/js-loader/build-tools,${tool_repo}/harmonyos/compiler/ace-loader/1.0/ace-loader-1.0.tar.gz
115prebuilts/build-tools/common,${tool_repo}/harmonyos/compiler/restool/2.007/restool-2.007.tar.gz
116prebuilts/cmake,${tool_repo}/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz
117prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/harmonyos/compiler/gn/1717/${host_platform}/gn-${host_platform}-x86-1717.tar.gz
118prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/harmonyos/compiler/ninja/1.10.1/${host_platform}/ninja-${host_platform}-x86-1.10.1.tar.gz
119prebuilts/,${tool_repo}/harmonyos/compiler/llvm_prebuilt_libs/ark_js_prebuilts_20220209.tar.gz
120"""
121
122if [[ "${host_platform}" == "linux" ]]; then
123    copy_config+="""
124        prebuilts/cmake,${tool_repo}/harmonyos/compiler/cmake/3.16.5/windows/cmake-windows-x86-3.16.5.tar.gz
125        prebuilts/mingw-w64/ohos/linux-x86_64,${tool_repo}/harmonyos/compiler/mingw-w64/7.0.0/clang-mingw.tar.gz
126        prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi,${tool_repo}/harmonyos/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz
127        prebuilts/gcc/linux-x86/aarch64,${tool_repo}/harmonyos/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
128        prebuilts/previewer/windows,${tool_repo}/harmonyos/develop_tools/previewer/3.1.11.2/previewer-3.1.11.2-3.1release-20221228.win.tar.gz
129        prebuilts/clang/ohos/windows-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/windows/clang-480513-windows-x86_64-20221021.tar.bz2
130        prebuilts/clang/ohos/windows-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/windows/libcxx-ndk-480513-windows-x86_64.tar.bz2
131        prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2
132        prebuilts/gcc/linux-x86/esp,${tool_repo}/harmonyos/compiler/gcc_esp/2019r2-8.2.0/linux/esp-2019r2-8.2.0.zip
133        prebuilts/gcc/linux-x86/csky,${tool_repo}/harmonyos/compiler/gcc_csky/v3.10.29/linux/csky-v3.10.29.tar.gz
134	prebuilts/python,${tool_repo}/harmonyos/compiler/python/3.9.2/${host_platform}/python-${host_platform}-x86-3.9.2_20200510.tar.gz
135	prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/clang-480513-${host_platform}-x86_64-20220815.tar.bz2
136        """
137elif [[ "${host_platform}" == "darwin" ]]; then
138    copy_config+="""
139        prebuilts/previewer/darwin,${tool_repo}/harmonyos/develop_tools/previewer/3.1.11.2/previewer-3.1.11.2-3.1release-20221228.mac.tar.gz
140        prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2
141	prebuilts/python,${tool_repo}/harmonyos/compiler/python/3.9.2/${host_platform}/python-${host_platform}-x86-3.9.2_202205071615.tar.gz
142        prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/clang-480513-${host_platform}-x86_64-20221021.tar.bz2
143	"""
144fi
145
146if [ ! -d "${bin_dir}" ];then
147    mkdir -p "${bin_dir}"
148fi
149
150for i in $(echo ${copy_config})
151do
152    unzip_dir=$(echo $i|awk -F ',' '{print $1}')
153    huaweicloud_url=$(echo $i|awk -F ',' '{print $2}')
154    md5_huaweicloud_url=$(echo ${huaweicloud_url}|md5sum|awk '{print $1}')
155    bin_file=$(basename ${huaweicloud_url})
156    bin_file_suffix=${bin_file#*.}
157    #huaweicloud_file_name=$(echo ${huaweicloud_url}|awk -F '/' '{print $NF}')
158
159    if [ ! -d "${code_dir}/${unzip_dir}" ];then
160        mkdir -p "${code_dir}/${unzip_dir}"
161    fi
162    hwcloud_download "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  "${huaweicloud_url}"
163    if [ "X${bin_file_suffix:0-3}" = "Xzip" ];then
164        unzip -o "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" -d "${code_dir}/${unzip_dir}/"
165    elif [ "X${bin_file_suffix:0-6}" = "Xtar.gz" ];then
166        tar -xvzf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  -C  "${code_dir}/${unzip_dir}"
167    else
168        tar -xvf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  -C  "${code_dir}/${unzip_dir}"
169    fi
170    # 由于部分压缩包包含了目录,用于专门处理多余目录
171    if [ -d "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" ];then
172        mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/"
173        rm -rf "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi"
174        mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/"
175    fi
176    if [ -d "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513-20221021" ];then
177        rm -rf "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm"
178        mv "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513-20221021" "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm"
179    ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm/lib/clang/current"
180    fi
181    if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513-20220815" ];then
182        rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm"
183        mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513-20220815" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm"
184	ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current"
185    fi
186    if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513-20221021" ];then
187        rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm"
188        mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513-20221021" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm"
189	ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm/lib/clang/current"
190    fi
191    if [ -d "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0/xtensa-esp32-elf" ];then
192        chmod 755 "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0" -R
193    fi
194done
195
196
197node_js_ver=v12.18.4
198node_js_name=node-${node_js_ver}-${host_platform}-x64
199node_js_pkg=${node_js_name}.tar.gz
200mkdir -p ${code_dir}/prebuilts/build-tools/common/nodejs
201cd ${code_dir}/prebuilts/build-tools/common/nodejs
202if [ ! -f "${node_js_pkg}" ]; then
203    wget -t3 -T10 ${wget_ssl_check} ${tool_repo}/nodejs/${node_js_ver}/${node_js_pkg}
204    tar zxf ${node_js_pkg}
205fi
206
207if [ ! -d "${code_dir}/third_party/jsframework" ]; then
208    echo "${code_dir}/third_party/jsframework not exist, it shouldn't happen, pls check..."
209else
210    cd ${code_dir}/third_party/jsframework/
211    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
212    npm config set registry ${npm_registry}
213    if [ "X${SKIP_SSL}" == "XYES" ];then
214        npm config set strict-ssl false
215    fi
216    npm cache clean -f
217    npm install
218
219    cd ${code_dir}
220    if [ -d "${code_dir}/prebuilts/build-tools/common/js-framework" ]; then
221        echo -e "\n"
222        echo "${code_dir}/prebuilts/build-tools/common/js-framework already exist, it will be replaced with node-${node_js_ver}"
223        /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/js-framework
224        echo -e "\n"
225    fi
226
227    mkdir -p ${code_dir}/prebuilts/build-tools/common/js-framework
228    /bin/cp -R ${code_dir}/third_party/jsframework/node_modules ${code_dir}/prebuilts/build-tools/common/js-framework/
229fi
230
231if [ ! -d "${code_dir}/developtools/ace-ets2bundle/compiler" ]; then
232    echo "${code_dir}/developtools/ace-ets2bundle/compiler not exist, it shouldn't happen, pls check..."
233else
234    cd ${code_dir}/developtools/ace-ets2bundle/compiler
235    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
236    npm config set registry ${npm_registry}
237    if [ "X${SKIP_SSL}" == "XYES" ];then
238        npm config set strict-ssl false
239    fi
240    npm cache clean -f
241    npm install
242fi
243
244
245if [ ! -d "${code_dir}/developtools/ace-js2bundle/ace-loader" ]; then
246    echo "${code_dir}/developtools/ace-js2bundle/ace-loader not exist, it shouldn't happen, pls check..."
247else
248    cd ${code_dir}/developtools/ace-js2bundle/ace-loader
249    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
250    npm config set registry ${npm_registry}
251    if [ "X${SKIP_SSL}" == "XYES" ];then
252        npm config set strict-ssl false
253    fi
254    npm cache clean -f
255    npm install
256fi
257
258if [ ! -d "${code_dir}/interface/sdk-js/build-tools" ]; then
259    echo "${code_dir}/interface/sdk-js/build-tools not exist, it shouldn't happen, pls check..."
260else
261    cd ${code_dir}/interface/sdk-js/build-tools
262    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
263    npm config set registry ${npm_registry}
264    if [ "X${SKIP_SSL}" == "XYES" ];then
265        npm config set strict-ssl false
266    fi
267    npm cache clean -f
268    npm install
269fi
270
271if [ -d "${code_dir}/ark/ts2abc/ts2panda" ]; then
272    cd ${code_dir}/ark/ts2abc/ts2panda
273    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
274    npm config set registry ${npm_registry}
275    if [ "X${SKIP_SSL}" == "XYES" ];then
276        npm config set strict-ssl false
277    fi
278    npm cache clean -f
279    npm install
280
281    cd ${code_dir}
282    if [ -d "${code_dir}/prebuilts/build-tools/common/ts2abc" ]; then
283        echo -e "\n"
284        echo "${code_dir}/prebuilts/build-tools/common/ts2abc already exist, it will be replaced with node-${node_js_ver}"
285        /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/ts2abc
286        echo -e "\n"
287    fi
288
289    mkdir -p ${code_dir}/prebuilts/build-tools/common/ts2abc
290    /bin/cp -rf ${code_dir}/ark/ts2abc/ts2panda/node_modules ${code_dir}/prebuilts/build-tools/common/ts2abc/
291fi
292
293
294cd ${code_dir}
295echo -e "\n"
296