• 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 "$NPM_REGISTRY" ];then
30	npm_registry='https://repo.huaweicloud.com/repository/npm/'
31else
32	npm_registry=$NPM_REGISTRY
33fi
34echo "npm_registry=$npm_registry"
35
36sha256_result=0
37check_sha256=''
38local_sha256=''
39function check_sha256(){
40    success_color='\033[1;42mSuccess\033[0m'
41    failed_color='\033[1;41mFailed\033[0m'
42    check_url=$1 #来源URL
43    local_file=$2  #本地文件绝对路径
44    check_sha256=$(curl -s -k ${check_url}.sha256)  # 当前使用华为云,URL固定,所以写死了,后续如果有变动,此处需要修改
45    local_sha256=$(sha256sum ${local_file} |awk '{print $1}')
46    if [ "X${check_sha256}" == "X${local_sha256}" ];then
47        echo -e "${success_color},${check_url} Sha256 check OK."
48        sha256_result=0
49    else
50        echo -e "${failed_color},${check_url} Sha256 check Failed.Retry!"
51        sha256_result=1
52        #exit 1  # 默认退出,必须保证sha256一致,如有特殊需要,请自行注释
53    fi
54}
55function hwcloud_download(){
56    # 代理不需要鉴权: wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://domain.com:port" ${huaweicloud_url}
57    # 代理需要鉴权(账号密码特殊字符均需要URL转义): wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://username:password@domain.com:port" ${huaweicloud_url}
58    # 不需要代理
59    download_local_file=$1
60    download_source_url=$2
61    for((i=1;i<=3;i++));
62    do
63        if [ -f "${download_local_file}" ];then
64            check_sha256 "${download_source_url}" "${download_local_file}"
65            if [ ${sha256_result} -gt 0 ];then
66                # 设置变量默认值,防止误删除
67                rm -rf "${download_local_file:-/tmp/20210721_not_exit_file}"
68            else
69                i=999
70                return 0
71            fi
72        fi
73        if [ ! -f "${download_local_file}" ];then
74            wget -t3 -T10 ${wget_ssl_check} -O  "${download_local_file}" "${download_source_url}"
75        fi
76    done
77    # 连续三次失败后报错退出
78    echo -e """Sha256 check failed!
79Download URL: ${download_source_url}
80Local file: ${download_local_file}
81Remote sha256: ${check_sha256}
82Local sha256: ${local_sha256}"""
83    exit 1
84}
85
86case $(uname -s) in
87    Linux)
88        host_platform=linux
89        ;;
90    Darwin)
91        host_platform=darwin
92        ;;
93    *)
94        echo "Unsupported host platform: $(uname -s)"
95        exit 1
96esac
97
98# 代码下载目录
99script_path=$(cd $(dirname $0);pwd)
100code_dir=$(dirname ${script_path})
101# 二进制所在目录,用于临时存放二进制,需要约7G空间
102# 下载的压缩包会自动解压到代码目录,压缩包会一直保留在该目录下
103bin_dir=${code_dir}/../OpenHarmony_prebuilts_pkgs
104
105# 二进制关系
106copy_config="""
107prebuilts/sdk/js-loader/build-tools,https://repo.huaweicloud.com/harmonyos/compiler/ace-loader/1.0/ace-loader-1.0.tar.gz
108prebuilts/build-tools/common,https://repo.huaweicloud.com/harmonyos/compiler/restool/1.023-d/restool.tar.gz
109prebuilts/cmake,https://repo.huaweicloud.com/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz
110prebuilts/build-tools/${host_platform}-x86/bin,https://repo.huaweicloud.com/harmonyos/compiler/gn/1717/${host_platform}/gn-${host_platform}-x86-1717.tar.gz
111prebuilts/build-tools/${host_platform}-x86/bin,https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.10.1/${host_platform}/ninja-${host_platform}-x86-1.10.1.tar.gz
112prebuilts/python,https://repo.huaweicloud.com/harmonyos/compiler/python/3.8.5/${host_platform}/python-${host_platform}-x86-3.8.5.tar.gz
113prebuilts/clang/ohos/${host_platform}-x86_64,https://repo.huaweicloud.com/harmonyos/compiler/clang/10.0.1-73276/${host_platform}/clang-73276-release-${host_platform}-x86_64.tar.bz2
114"""
115
116if [[ "${host_platform}" == "linux" ]]; then
117    copy_config+="""
118        prebuilts/cmake,https://repo.huaweicloud.com/harmonyos/compiler/cmake/3.16.5/windows/cmake-windows-x86-3.16.5.tar.gz
119        prebuilts/mingw-w64/ohos/linux-x86_64,https://repo.huaweicloud.com/harmonyos/compiler/mingw-w64/7.0.0/clang-mingw.tar.gz
120        prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi,https://repo.huaweicloud.com/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
121        prebuilts/gcc/linux-x86/aarch64,https://repo.huaweicloud.com/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
122        prebuilts/previewer/windows,https://repo.huaweicloud.com/harmonyos/develop_tools/previewer/3.0.0.0/windows/previewer.tar.gz
123        """
124elif [[ "${host_platform}" == "darwin" ]]; then
125    copy_config+="""
126        prebuilts/previewer/darwin,https://repo.huaweicloud.com/harmonyos/develop_tools/previewer/3.0.0.0/darwin/previewer.tar.gz
127        """
128fi
129
130if [ ! -d "${bin_dir}" ];then
131    mkdir -p "${bin_dir}"
132fi
133
134for i in $(echo ${copy_config})
135do
136    unzip_dir=$(echo $i|awk -F ',' '{print $1}')
137    huaweicloud_url=$(echo $i|awk -F ',' '{print $2}')
138    md5_huaweicloud_url=$(echo ${huaweicloud_url}|md5sum|awk '{print $1}')
139    bin_file=$(basename ${huaweicloud_url})
140    bin_file_suffix=${bin_file#*.}
141    #huaweicloud_file_name=$(echo ${huaweicloud_url}|awk -F '/' '{print $NF}')
142
143    if [ ! -d "${code_dir}/${unzip_dir}" ];then
144        mkdir -p "${code_dir}/${unzip_dir}"
145    fi
146    hwcloud_download "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  "${huaweicloud_url}"
147    if [ "X${bin_file_suffix:0-3}" = "Xzip" ];then
148        unzip "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" -d "${code_dir}/${unzip_dir}/"
149    elif [ "X${bin_file_suffix:0-6}" = "Xtar.gz" ];then
150        tar -xvzf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  -C  "${code_dir}/${unzip_dir}"
151    else
152        tar -xvf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}"  -C  "${code_dir}/${unzip_dir}"
153    fi
154    # 由于部分压缩包包含了目录,用于专门处理多余目录
155    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
156        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/"
157        rm -rf "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi"
158        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/"
159    fi
160    if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-73276-release" ];then
161        rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm"
162        mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-73276-release" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm"
163	ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current"
164    fi
165    if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-73276-release" ];then
166        rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm"
167        mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-73276-release" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm"
168	ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm/lib/clang/current"
169    fi
170done
171
172
173node_js_ver=v12.18.4
174node_js_name=node-${node_js_ver}-${host_platform}-x64
175node_js_pkg=${node_js_name}.tar.gz
176mkdir -p ${code_dir}/prebuilts/build-tools/common/nodejs
177cd ${code_dir}/prebuilts/build-tools/common/nodejs
178if [ ! -f "${node_js_pkg}" ]; then
179    wget -t3 -T10 ${wget_ssl_check} https://repo.huaweicloud.com/nodejs/${node_js_ver}/${node_js_pkg}
180    tar zxf ${node_js_pkg}
181fi
182
183if [ ! -d "${code_dir}/third_party/jsframework" ]; then
184    echo "${code_dir}/third_party/jsframework not exist, it shouldn't happen, pls check..."
185else
186    cd ${code_dir}/third_party/jsframework/
187    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
188    npm config set registry ${npm_registry}
189    if [ "X${SKIP_SSL}" == "XYES" ];then
190        npm config set strict-ssl false
191    fi
192    npm cache clean -f
193    npm install
194
195    cd ${code_dir}
196    if [ -d "${code_dir}/prebuilts/build-tools/common/js-framework" ]; then
197        echo -e "\n"
198        echo "${code_dir}/prebuilts/build-tools/common/js-framework already exist, it will be replaced with node-${node_js_ver}"
199        /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/js-framework
200        echo -e "\n"
201    fi
202
203    mkdir -p ${code_dir}/prebuilts/build-tools/common/js-framework
204    /bin/cp -rf ${code_dir}/third_party/jsframework/node_modules ${code_dir}/prebuilts/build-tools/common/js-framework/
205fi
206
207if [ ! -d "${code_dir}/developtools/ace-ets2bundle/compiler" ]; then
208    echo "${code_dir}/developtools/ace-ets2bundle/compiler not exist, it shouldn't happen, pls check..."
209else
210    cd ${code_dir}/developtools/ace-ets2bundle/compiler
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
218fi
219
220if [ ! -d "${code_dir}/developtools/ace-js2bundle/ace-loader" ]; then
221    echo "${code_dir}/developtools/ace-js2bundle/ace-loader not exist, it shouldn't happen, pls check..."
222else
223    cd ${code_dir}/developtools/ace-js2bundle/ace-loader
224    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
225    npm config set registry ${npm_registry}
226    if [ "X${SKIP_SSL}" == "XYES" ];then
227        npm config set strict-ssl false
228    fi
229    npm cache clean -f
230    npm install
231fi
232
233if [ -d "${code_dir}/ark/ts2abc/ts2panda" ]; then
234    cd ${code_dir}/ark/ts2abc/ts2panda
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
242
243    cd ${code_dir}
244    if [ -d "${code_dir}/prebuilts/build-tools/common/ts2abc" ]; then
245        echo -e "\n"
246        echo "${code_dir}/prebuilts/build-tools/common/ts2abc already exist, it will be replaced with node-${node_js_ver}"
247        /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/ts2abc
248        echo -e "\n"
249    fi
250
251    mkdir -p ${code_dir}/prebuilts/build-tools/common/ts2abc
252    /bin/cp -rf ${code_dir}/ark/ts2abc/ts2panda/node_modules ${code_dir}/prebuilts/build-tools/common/ts2abc/
253fi
254
255#安装鸿蒙sdk中js组件的相关依赖
256if [ -d "${code_dir}/prebuilts/sdk/js-loader/build-tools/ace-loader" ]; then
257    cd ${code_dir}/prebuilts/sdk/js-loader/build-tools/ace-loader
258    export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH
259    npm config set registry ${npm_registry}
260    npm config set @ohos:registry=https://repo.harmonyos.com/npm/
261    if [ "X${SKIP_SSL}" == "XYES" ];then
262        npm config set strict-ssl false
263    fi
264    npm cache clean -f
265    npm install
266fi
267
268cd ${code_dir}
269echo -e "\n"
270