pack-ci.sh 16.8 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
usage() {
    echo "Usage: $0 --build-directory [build directory, default: /build]
                    --vendor <vendor>
                    --orgcode <organization code>
                    --channel-id <channel id>
                    --package-type [packtype: owner or other; default: owner]
                    --project-id <project id>
                    --pipeline-id <pipeline id>
                    --url-tag <url tag>
fuyanbin's avatar
fuyanbin committed
11
                    --qrcode-app
fuyanbin's avatar
fuyanbin committed
12
13
14
15
16
17
18
19
20
21
22
23
                    --help"
    exit 1
}

BUILD_DIR="./image_build"
VENDOR=""
ORGCODE=""
CHANNELID=""
PACK_TYPE="owner"
PROJECT_ID=""
PIPELINE_ID=""
URL_TAG=""
fuyanbin's avatar
fuyanbin committed
24
INSTALL_QRCODE_APP="false"
fuyanbin's avatar
fuyanbin committed
25
26
27
28

CHROOT_TYPE="androidrom"
DEPLOY="elf"

fuyanbin's avatar
fuyanbin committed
29
export PATH=$(pwd)/tools/android-tools:$(pwd)/tools/:$(pwd)/tools/amlogic_tool:$(pwd)/tools/rockchip_tool:$(pwd)/tools/rockchip_tool/obsutil:$(pwd)/tools/allwinner:$PATH
fuyanbin's avatar
fuyanbin committed
30
PARSED_ARUGMENTS=$(getopt -a -n "$0" -o 'x' --long help,build-directory:,vendor:,orgcode:,channel-id:,package-type:,project-id:,pipeline-id:,url-tag:,qrcode-app:, -- "$@")
fuyanbin's avatar
fuyanbin committed
31
32
33
34
35
36
37
38
39
40
41
42
eval set -- "${PARSED_ARUGMENTS}"
while :
do
    case "$1" in
        --build-directory) BUILD_DIR="$2"; shift 2;;
        --vendor) VENDOR="$2"; shift 2;;
        --orgcode) ORGCODE="$2"; shift 2;;
        --channel-id) CHANNELID="$2"; shift 2;;
        --package-type) PACK_TYPE="$2"; shift 2;;
        --project-id) PROJECT_ID="$2"; shift 2;;
        --pipeline-id) PIPELINE_ID="$2"; shift 2;;
        --url-tag) URL_TAG="$2"; shift 2;;
fuyanbin's avatar
fuyanbin committed
43
        --qrcode-app) INSTALL_QRCODE_APP="$2"; shift 2;;
fuyanbin's avatar
fuyanbin committed
44
45
46
47
48
49
50
51
52
53
        --help) usage ;;
        --) shift; break;;
        *) usage ;;
    esac
done

build_dir=$(mktemp -d "$BUILD_DIR"/tmp.XXXXX)
packge_dir=$(mktemp -d "$BUILD_DIR"/tmp.XXXXX)
boot_dir=$(mktemp -d "$BUILD_DIR"/tmp.XXXXX)

fuyanbin's avatar
fuyanbin committed
54
55
56
57
system_mount_point=""
system_path=""
systemfile=""
systemfile_ext4=""
fuyanbin's avatar
fuyanbin committed
58
59
60
61
super_file=""
super_file_ext4=""
update_img_tmp_dir="$build_dir/img_dir"
super_img_tmp_dir="$build_dir/img_dir/super"
fuyanbin's avatar
fuyanbin committed
62

fuyanbin's avatar
fuyanbin committed
63
ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME="system_a"
fuyanbin's avatar
fuyanbin committed
64
ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME="system"
fuyanbin's avatar
fuyanbin committed
65

fuyanbin's avatar
fuyanbin committed
66
67
is_amlogic=0
is_allwinner=0
fuyanbin's avatar
fuyanbin committed
68
is_rockchip=0
fuyanbin's avatar
fuyanbin committed
69

fuyanbin's avatar
fuyanbin committed
70
outfile_path=""
fuyanbin's avatar
fuyanbin committed
71

fuyanbin's avatar
fuyanbin committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
validate_partition_size_change() {
    local group_name
    local size
    local total_size
    local group_maxinum_size
    local c_super_file="$1"
    local parttion_name="$2"
    local partition_info_dump
    local group_info_dump

    group_name=$(get_group_name "$c_super_file" "$parttion_name")

    partition_info_dump=$(lpdump -j "$c_super_file" |  jq -c -r '.partitions[]')
    for item in $partition_info_dump
    do
        if [[ "$(echo "$item" | jq -r '.group_name')" == "$group_name" ]]
        then
            size=$(echo "$item" | jq -r '.size')
            total_size=$((total_size+size))
        fi
    done
fuyanbin's avatar
fuyanbin committed
93
    total_size=$((total_size+251658240))
fuyanbin's avatar
fuyanbin committed
94
95
96
97
98
99

    group_info_dump=$(lpdump -j "$c_super_file" |  jq -c -r '.groups[]')
    for item in $group_info_dump
    do
        if [[ "$(echo "$item" | jq -r '.name')" == "$group_name" ]]
        then
fuyanbin's avatar
typo    
fuyanbin committed
100
            group_maxinum_size=$(echo "$item" | jq -r '.maximum_size')
fuyanbin's avatar
fuyanbin committed
101
102
103
104
105
106
107
108
109
110
111
            break
        fi
    done

    if [[ -n "$group_maxinum_size" ]] && [[ "$group_maxinum_size" -lt "$total_size" ]]
    then
        return 1
    fi
    return 0
}

fuyanbin's avatar
fuyanbin committed
112
113
114
115
get_group_name() {
    local group_name
    local partition_info_dump
    local c_super_file="$1"
fuyanbin's avatar
fuyanbin committed
116
    local parttion_name="$2"
fuyanbin's avatar
fuyanbin committed
117
118
119
120

    partition_info_dump=$(lpdump -j "$c_super_file" |  jq -c -r '.partitions[]')
    for item in $partition_info_dump
    do
fuyanbin's avatar
fuyanbin committed
121
        if [[ "$(echo "$item" | jq -r '.name')" == "$parttion_name" ]]
fuyanbin's avatar
fuyanbin committed
122
123
124
125
126
127
128
129
130
131
132
133
134
        then
            group_name=$(echo "$item" | jq -r '.group_name')
        fi
    done
    printf "%s" "$group_name"
}

resize_system_image() {
    local c_system_file="$1"
    local image_size
    local loopdev

    image_size="$(stat -c "%s" "$c_system_file")"
fuyanbin's avatar
fuyanbin committed
135
    image_size=$((image_size+251658240)) # +240M
fuyanbin's avatar
fuyanbin committed
136
137
138
139

    qemu-img resize -f raw "$c_system_file" "$image_size"
    loopdev=$(losetup -P -f --show "$c_system_file")

fuyanbin's avatar
fuyanbin committed
140
    e2fsck -f -y "$loopdev"
fuyanbin's avatar
fuyanbin committed
141
142
143
144
    resize2fs "$loopdev"
    losetup -d "$loopdev"
}

fuyanbin's avatar
fuyanbin committed
145
146
147
__unpack_super_img() {
    local system_partition_name="$1"

148
    if __is_sparse_super
fuyanbin's avatar
fuyanbin committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    then
        simg2img "$super_file" "$super_file_ext4"
        lpunpack "$super_file_ext4" "$super_img_tmp_dir"
    else
        lpunpack "$super_file" "$super_img_tmp_dir"
    fi
    systemfile="$super_img_tmp_dir/${system_partition_name}.img"
    systemfile_ext4="$super_img_tmp_dir/${system_partition_name}.img.ext4"
    if file "$systemfile" | grep "Android sparse image"
    then
        resize_system_image "$systemfile_ext4"
    else
        resize_system_image "$systemfile"
    fi
}

fuyanbin's avatar
fuyanbin committed
165
unpack_and_mount_image() {
fuyanbin's avatar
fuyanbin committed
166
    local img="$1"
fuyanbin's avatar
fuyanbin committed
167
168
    local loopdev

fuyanbin's avatar
fuyanbin committed
169
170
171
    mkdir -p "$update_img_tmp_dir"
    mkdir -p "$super_img_tmp_dir"

fuyanbin's avatar
fuyanbin committed
172
173
    if aml_image_v2_packer -c "$img"
    then
fuyanbin's avatar
fuyanbin committed
174
        echo "Amlogic Image Format Detected.."
fuyanbin's avatar
fuyanbin committed
175
176
177
        is_amlogic=1
        systemfile="$build_dir/system.PARTITION"
        systemfile_ext4="$build_dir/system.PARTITION.ext4"
fuyanbin's avatar
fuyanbin committed
178

fuyanbin's avatar
fuyanbin committed
179
        aml_image_v2_packer -d "$img" "$build_dir"
fuyanbin's avatar
fuyanbin committed
180
181
182
183
184
    elif sunxi-fw info "$img" | grep -i -q "PhoenixSuite image file"
    then
        echo "Allwinner PhoenixSute Image Format Detected.."
        is_allwinner=1
        cp "$img" "$update_img_tmp_dir/update.img"
185
186
187
188
        local SCRIPT
        local WORKDIR
        SCRIPT=$(readlink -f "\$0")
        WORKDIR=$(dirname "$SCRIPT")
189
        pushd "$update_img_tmp_dir"
190
        /usr/lib/wine/wine "$WORKDIR"/tools/allwinner/win32/imgRePacker.exe unpack ./update.img
191
        popd
fuyanbin's avatar
fuyanbin committed
192
193
        rm -f "$update_img_tmp_dir/update.img"

194
195
        super_file="$update_img_tmp_dir/update.img.dump/super.fex"
        super_file_ext4="$update_img_tmp_dir/update.img.dump/super.fex.ext4"
fuyanbin's avatar
fuyanbin committed
196
        __unpack_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
fuyanbin's avatar
fuyanbin committed
197
    else
fuyanbin's avatar
fuyanbin committed
198
199
200
201
202
        echo "Rockchip Format Detected.."
        is_rockchip=1
        cp "$img" "$update_img_tmp_dir/update.img"
        mkdir -p "$update_img_tmp_dir/update.img.dump"
        rkImageMaker -unpack "$update_img_tmp_dir/update.img" "$update_img_tmp_dir/update.img.dump"
203
204
205
206
        # workround: afptool 工具好像有路径读取问题
        pushd "$update_img_tmp_dir"
        afptool -unpack "./update.img.dump/firmware.img" "./update.img.dump"
        popd
fuyanbin's avatar
fuyanbin committed
207
208
209
210
        rm -f "$update_img_tmp_dir/update.img"
        rm -f "$update_img_tmp_dir/update.img.dump/firmware.img"
        rm -f "$update_img_tmp_dir/update.img.dump/boot.bin"

211
212
        super_file="$update_img_tmp_dir/update.img.dump/Image/super.img"
        super_file_ext4="$update_img_tmp_dir/update.img.dump/Image/super.img.ext4"
fuyanbin's avatar
fuyanbin committed
213
        __unpack_super_img "$ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME"
fuyanbin's avatar
fuyanbin committed
214
    fi
fuyanbin's avatar
fuyanbin committed
215

216
    if __is_sparse_system
fuyanbin's avatar
fuyanbin committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    then
        simg2img "$systemfile" "$systemfile_ext4"
        loopdev=$(losetup -P -f --show "$systemfile_ext4")
    else
        loopdev=$(losetup -P -f --show "$systemfile")
    fi

    system_mount_point="$build_dir/system"
    mkdir "$system_mount_point"
    mount "$loopdev" "$system_mount_point"

    if [[ -d "$system_mount_point/system" ]]
    then
        system_path="$system_mount_point/system"
    else
        system_path="$system_mount_point"
    fi
fuyanbin's avatar
fuyanbin committed
234
235
    losetup -d "$loopdev"
}
fuyanbin's avatar
fuyanbin committed
236

fuyanbin's avatar
fuyanbin committed
237
install_dianxin() {
fuyanbin's avatar
fuyanbin committed
238
239
240
241
    local img="$1"
    local android_sdk

    unpack_and_mount_image "$img"
fuyanbin's avatar
fuyanbin committed
242
243
244
245
246
247
248
249
    touch "$system_path/.androidrom"

    rm -f "$system_path/hugep-all.zip"
    rm -f "$system_path/bin/hugep-all.zip"

    android_sdk="$(grep "build\.version\.sdk" "$system_path"/build.prop | awk -F'=' '{print $2}')"
    android_sdk="${android_sdk//$'\r'}"
    android_sdk="${android_sdk//$'\n'}"
fuyanbin's avatar
fuyanbin committed
250
    if [[ "$android_sdk" -ge 25 ]]
fuyanbin's avatar
fuyanbin committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    then
        find ./services/ -type f -name "*.rc" -exec install -t "$system_path"/etc/init/ {} \;
    else
        pushd "$boot_dir"
        abootimg -x "$build_dir/boot.PARTITION" ramdisk
        mkdir initrd_dir
        pushd initrd_dir
        gunzip -c ../initrd.img | cpio -i
        popd
        cp initrd_dir/init.rc .
        rm -rf initrd_dir
        popd
        cp "$boot_dir"/init.rc "$packge_dir"/init.rc
        rm -rf "$boot_dir"
        if ! find_autostart -script_name preinstall.sh -initrc "$packge_dir"/init.rc -root_path "$build_dir" > "$packge_dir"/find_autostart.log 2>/dev/null
        then
            find_autostart -script_name recovery.sh -initrc "$packge_dir"/init.rc -root_path "$build_dir" > "$packge_dir"/find_autostart.log 2>/dev/null
        fi
        local auto_start_script
        auto_start_script="$(cat "$packge_dir"/find_autostart.log)"
        if [[ -z "$auto_start_script" ]] && [[ -f "$system_path"/bin/startsoftdetector.sh ]]
        then
            # TODO: startsoftdetector.sh 会阻塞在某一步,要把 starthugep.sh 加在中间部分
            auto_start_script="/system/bin/startsoftdetector.sh"
        fi
        # NOTE: 返回的脚本路径里一定以 /system/ 开头, 所以下边拼路径时没有加上 /system
        if [[ -n "$auto_start_script" ]]
        then
            local _script_path
280
            _script_path="$system_path/$(echo "$auto_start_script" | sed 's|^/system||')"
281
282
            local tmp_script_path="/tmp/tmp_auto_start.sh"
            local start_n
fuyanbin's avatar
fuyanbin committed
283
284
            if ! grep -q "#!/system/bin/sh" "$_script_path"
            then
285
286
287
                start_n=1
            else
                start_n=2
fuyanbin's avatar
fuyanbin committed
288
            fi
289
290
291
292
293
294
295
296

            {
                echo "#!/system/bin/sh"
                echo " "
                echo "/system/bin/starthugep.sh > /dev/null 2>&1 &"
                tail -n +"${start_n}" "$_script_path"
            } > "$tmp_script_path"

297
            cat "$tmp_script_path" | tee "$_script_path"
fuyanbin's avatar
fuyanbin committed
298
299
300
301
302
303
304
            chmod 0755 "$_script_path"
            chcon u:object_r:drmserver_exec:s0 "$_script_path"
        fi
    fi

    cp -f "$build_dir/hugep-all.zip" "$system_path"/bin/hugep-all.zip

305
    find ./services/ -type f ! -name  "*.rc" ! -name "*.zip" ! -name "*.apk" ! -name "hugep" ! -name "hugep-start.sh" -exec install -m 0777 -t "$system_path"/bin/ {} \;
fuyanbin's avatar
fuyanbin committed
306

307
    for file in $(find ./services/ -type f ! -name "*.rc" ! -name "*.zip" ! -name "*.apk" ! -name "hugep" ! -name "hugep-start.sh")
fuyanbin's avatar
fuyanbin committed
308
309
310
311
    do
        chcon u:object_r:drmserver_exec:s0 "$system_path/bin/$(basename "$file")"
    done

312
313
314
315
316
    for file in $(find ./services/ -type f -name "*.zip")
    do
        chcon u:object_r:system_file:s0 "$system_path/bin/$(basename "$file")"
    done

fuyanbin's avatar
fuyanbin committed
317
    for file in $(find ./services/ -type f -name "*.rc" ! -name "*.zip")
318
319
320
321
    do
        chcon u:object_r:drmserver_exec:s0 "$system_path/etc/init/$(basename "$file")"
    done

fuyanbin's avatar
fuyanbin committed
322
    if [[ "$android_sdk" -ge 31 ]] && [[ "$INSTALL_QRCODE_APP" == "true" ]]
323
324
325
326
    then
        find ./services/ -type f -name  "*.apk" -exec install -m 0644 -t "$system_path"/preinstall/ {} \;
    fi

fuyanbin's avatar
fuyanbin committed
327
328
329
    pack_image "$img"
}

330
331
332
333
334
335
336
337
338
__is_sparse_super() {
    if file "$super_file" | grep "Android sparse image"
    then
        return 0
    else
        return 1
    fi
}

fuyanbin's avatar
fuyanbin committed
339
340
341
__pack_super_img() {
    local system_partition_name="$1"
    local c_super_file
342
    if __is_sparse_super
fuyanbin's avatar
fuyanbin committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
    then
        c_super_file="$super_file_ext4"
    else
        c_super_file="$super_file"
    fi
    local c_group_name
    c_group_name="$(get_group_name "$c_super_file" "$system_partition_name")"
    if validate_partition_size_change "$c_super_file" "$system_partition_name"
    then
        lpadd --readonly \
            --replace \
            "$c_super_file" \
            "$system_partition_name" \
            "$c_group_name" \
            "$systemfile"

359
        if __is_sparse_super
fuyanbin's avatar
fuyanbin committed
360
361
362
363
364
365
        then
            img2simg "$super_file_ext4" "$super_file"
            rm -rf "$super_file_ext4"
        fi
    else
        repack.sh "$c_super_file" "$c_group_name" "$systemfile" "$system_partition_name"
366
367
368
369
370
371
372
        if __is_sparse_super
        then
            mv "$(dirname "$c_super_file")/super.new.img" "$super_file"
        else
            simg2img "$(dirname "$c_super_file")/super.new.img" "$super_file"
            rm -f "$(dirname "$c_super_file")/super.new.img"
        fi
fuyanbin's avatar
fuyanbin committed
373
374
375
376
377
    fi
}

__get_chip_from_parameter() {
    local chip
378
379
    chip=$(rkChipInfo -f "$IMAGE_FILE" -o 123 | awk '{print $1}')
    [[ -z "$chip" ]] && chip=$(rkChipInfo -f "$IMAGE_FILE" -o 21 | awk '{print $1}')
380
    printf "RK%s" "$chip"
fuyanbin's avatar
fuyanbin committed
381
382
}

383
384
385
386
387
388
389
390
391
__is_sparse_system() {
    if file "$systemfile" | grep "Android sparse image"
    then
        return 0
    else
        return 1
    fi
}

fuyanbin's avatar
fuyanbin committed
392
393
pack_image() {
    local img
fuyanbin's avatar
typo    
fuyanbin committed
394
    img="$1"
fuyanbin's avatar
fuyanbin committed
395

396
    sync
fuyanbin's avatar
typo    
fuyanbin committed
397
    umount "$system_mount_point"
fuyanbin's avatar
fuyanbin committed
398
399
400
    rm -rf "$system_mount_point"
    sync

401
    if __is_sparse_system
fuyanbin's avatar
fuyanbin committed
402
403
404
405
406
    then
        rm -f "$systemfile"
        img2simg "$systemfile_ext4" "$systemfile"
        rm -f "$systemfile_ext4"
    fi
fuyanbin's avatar
fuyanbin committed
407

fuyanbin's avatar
fuyanbin committed
408
    outfile_path="${packge_dir}/${CHANNELID}-$(basename "$img")"
fuyanbin's avatar
fuyanbin committed
409
410
    if [[ "$is_amlogic" == "1" ]] 
    then
fuyanbin's avatar
fuyanbin committed
411
        echo "Amlogic Image Format Detected.."
fuyanbin's avatar
fuyanbin committed
412
        aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "$outfile_path"
fuyanbin's avatar
fuyanbin committed
413
414
415
    elif [[ "$is_allwinner" == "1" ]]
    then
        echo "Allwinner PhoenixSute Image Format Detected.."
fuyanbin's avatar
fuyanbin committed
416
        __pack_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
417
        sleep 5
418
419
420
421
        local SCRIPT
        local WORKDIR
        SCRIPT=$(readlink -f "\$0")
        WORKDIR=$(dirname "$SCRIPT")
422
        pushd "$update_img_tmp_dir"
423
        /usr/lib/wine/wine "$WORKDIR"/tools/allwinner/win32/imgRePacker.exe pack ./update.img.dump
424
        popd
fuyanbin's avatar
fuyanbin committed
425
        mv "$update_img_tmp_dir/update.img" "$outfile_path"
fuyanbin's avatar
fuyanbin committed
426
427
428
429
430
431
    elif [[ "$is_rockchip" == "1" ]]
    then
        echo "Rockchip Image Format Detected.."
        __pack_super_img "$ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME"
        cp -f "$update_img_tmp_dir/update.img.dump/MiniLoaderAll.bin" "$update_img_tmp_dir/update.img.dump/Image/MiniLoaderAll.bin"
        cp -f "$update_img_tmp_dir/update.img.dump/parameter.txt" "$update_img_tmp_dir/update.img.dump/Image/parameter.txt"
fuyanbin's avatar
fuyanbin committed
432
        afptool -pack "$update_img_tmp_dir/update.img.dump" "$update_img_tmp_dir/update.img"
fuyanbin's avatar
fuyanbin committed
433
        local chip_parameter
fuyanbin's avatar
fuyanbin committed
434
        chip_parameter="$(__get_chip_from_parameter "${update_img_tmp_dir}/update.img.dump/parameter.txt")"
fuyanbin's avatar
fuyanbin committed
435
        # e.g. rkImageMaker -RK322H output/MiniLoaderAll.bin output/Image/update.img update.img -os_type:androidos
fuyanbin's avatar
fuyanbin committed
436
437
438
        rkImageMaker "-${chip_parameter}" \
            "$update_img_tmp_dir/update.img.dump/MiniLoaderAll.bin" "$update_img_tmp_dir/update.img" "$outfile_path" \
            -os_type:androidos
fuyanbin's avatar
fuyanbin committed
439
    fi
fuyanbin's avatar
fuyanbin committed
440
441
442
443
444
445
    rm -rf "$build_dir"
}

generate_vendor_confg() {
    local yaml_file_src
    local yaml_file
446
    local config_json_file
fuyanbin's avatar
fuyanbin committed
447
448
449
450

    yaml_file="$build_dir"/vendor.yaml
    yaml_file_src="$build_dir"/vendor.yaml.src
    cp vendor.yaml.src "$yaml_file_src"
451
452
453
454
455
    sed -i'' -e "s#__VENDOR__#$VENDOR#g" \
        -e "s#__ORGCODE__#$ORGCODE#g" \
        -e "s#__CHROOT_TYPE__#$CHROOT_TYPE#g" \
        -e "s#__DEPLOY__#$DEPLOY#g" \
        -e "s#__CHANNEL_ID__#$CHANNELID#g" \
456
457
458
        -e "s#__PACK_TYPE__#$PACK_TYPE#g" \
        -e "s#__CI_PROJECT_ID__#$PROJECT_ID#g" \
        -e "s#__CI_PIPELINE_ID__#$PIPELINE_ID#g" "$yaml_file_src"
fuyanbin's avatar
fuyanbin committed
459
    aio -m enc -i "$yaml_file_src" -o "$yaml_file"
460
461
462
463

    config_json_file="$build_dir"/config.json
    cp config.json.src "$config_json_file"
    sed -i'' "s#__CHANNEL_ID__#$CHANNELID#g" "$config_json_file"
fuyanbin's avatar
fuyanbin committed
464
465
466
467
468
469
}

update_hugepall_zipfile() {
    local yaml_file
    local hugep_zip_file
    local hugep_zip_file_origin
470
    local config_json_file
471
    local config_json_file_bak
fuyanbin's avatar
fuyanbin committed
472
473
474
475

    yaml_file="$build_dir"/vendor.yaml
    hugep_zip_file="$build_dir/hugep-all.zip"
    hugep_zip_file_origin="./services/hugep-all.zip"
476
    config_json_file="$build_dir"/config.json
477
478
    config_json_file_bak="$build_dir"/config.json.bak
    cp "$config_json_file" "$config_json_file_bak"
fuyanbin's avatar
fuyanbin committed
479
480
481
482

    cp "$hugep_zip_file_origin" "$hugep_zip_file"

    zip -u -j "$hugep_zip_file" "$yaml_file"
483
    zip -u -j "$hugep_zip_file" "./services/hugep-start.sh"
484
    zip -u -j "$hugep_zip_file" "$config_json_file"
485
486
    zip -u -j "$hugep_zip_file" "$config_json_file_bak"
    zip -u -j "$hugep_zip_file" "./services/hugep"
fuyanbin's avatar
fuyanbin committed
487
488
489
490
491
492
493
494
495
496
}

upload() {
    local date_i
    local outfile
    local outfile_gz
    local uri
    local random_num
    local -A result

fuyanbin's avatar
fuyanbin committed
497
    outfile="$outfile_path"
fuyanbin's avatar
fuyanbin committed
498
    outfile_gz="${outfile}.gz"
fuyanbin's avatar
fuyanbin committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
    date_i="$(date +%Y-%m-%d-%s)"

    zstd --ultra --format=gzip "$outfile" -o "$outfile_gz"
    random_num=$(< /dev/urandom tr -dC 0-9a-z | head -c 8)
    [[ -z "$URL_TAG" ]] && URL_TAG="${date_i}-${random_num}"
    uri="product/terminal/chroot_androidrom/""$ORGCODE/${date_i}-${URL_TAG}/$(basename "$outfile_gz")"
    obsutil cp "$outfile_gz" obs://fae-cdn.linkfog.cn/"$uri"

    result["url"]="https://fae-cdn.linkfog.cn/""$uri"
    result["md5"]="$(md5sum "${outfile}" | awk '{print $1}')"
    mkdir -p .result
    jq -n --arg url "${result[url]}" --arg md5 "${result[md5]}" '{$url, $md5}' > ".result/${PROJECT_ID}-${PIPELINE_ID}.json"
    echo ".result/${PROJECT_ID}-${PIPELINE_ID}.json"
    cat ".result/${PROJECT_ID}-${PIPELINE_ID}.json"

    rm -f "$outfile" "$outfile_gz"
    rm -rf "$packge_dir"
}

IMAGE_FILE="/baseimages/$VENDOR-$ORGCODE.img"
519
[[ ! -f "$IMAGE_FILE" ]] && IMAGE_FILE="CH-A03.img"
fuyanbin's avatar
fuyanbin committed
520
521
generate_vendor_confg
update_hugepall_zipfile
fuyanbin's avatar
fuyanbin committed
522
install_dianxin "$IMAGE_FILE"
fuyanbin's avatar
fuyanbin committed
523
upload