pack-deploy-ci.sh 3.5 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
2
#!/bin/bash
usage() {
fuyanbin's avatar
fuyanbin committed
3
4
    echo "Usage: $0 --build-directory [build directory, default: /build]
                    --vendor <vendor>
fuyanbin's avatar
fuyanbin committed
5
                    --orgcode <organization code>
fuyanbin's avatar
fuyanbin committed
6
7
8
9
10
                    --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
12
13
14
                    --help"
    exit 1
}

fuyanbin's avatar
fuyanbin committed
15
BUILD_DIR="./image_build"
fuyanbin's avatar
fuyanbin committed
16
17
18
VENDOR=""
ORGCODE=""
CHANNELID=""
fuyanbin's avatar
fuyanbin committed
19
20
21
22
PACK_TYPE="owner"
PROJECT_ID=""
PIPELINE_ID=""
URL_TAG=""
fuyanbin's avatar
fuyanbin committed
23

fuyanbin's avatar
fuyanbin committed
24
25
CHROOT_TYPE="androidrom"
DEPLOY="elf"
fuyanbin's avatar
fuyanbin committed
26
27

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

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

generate_vendor_confg() {
    local yaml_file_src
    local yaml_file
54
    local config_json_file
fuyanbin's avatar
fuyanbin committed
55
56
57
58

    yaml_file="$build_dir"/vendor.yaml
    yaml_file_src="$build_dir"/vendor.yaml.src
    cp vendor.yaml.src "$yaml_file_src"
59
60
61
62
63
64
    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" \
        -e "s#__PACK_TYPE__#$PACK_TYPE#g" "$yaml_file_src"
fuyanbin's avatar
fuyanbin committed
65
    aio -m enc -i "$yaml_file_src" -o "$yaml_file"
66
67
68
69

    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
70
71
72
73
74
75
}

update_hugepall_zipfile() {
    local yaml_file
    local hugep_zip_file
    local hugep_zip_file_origin
76
    local config_json_file
fuyanbin's avatar
fuyanbin committed
77
78
79
80

    yaml_file="$build_dir"/vendor.yaml
    hugep_zip_file="$build_dir/hugep-all.zip"
    hugep_zip_file_origin="./services/hugep-all.zip"
81
    config_json_file="$build_dir"/config.json
fuyanbin's avatar
fuyanbin committed
82
83
84
85

    cp "$hugep_zip_file_origin" "$hugep_zip_file"

    zip -u -j "$hugep_zip_file" "$yaml_file"
86
    zip -u -j "$hugep_zip_file" "./services/hugep-start.sh"
87
    zip -u -j "$hugep_zip_file" "$config_json_file"
fuyanbin's avatar
fuyanbin committed
88
89
90
91
92
93
94
95
96
97
98
99
    outfile_path="$packge_dir/$VENDOR-$ORGCODE-$CHANNELID-hugep-all.zip"
    mv "$hugep_zip_file" "$outfile_path"
    rm -rf "$build_dir"
}

upload() {
    local outfile
    local uri
    local -A result

    outfile="$outfile_path"

100
    uri="product/terminal/chroot_integration/""$ORGCODE/${CHANNELID}/$(basename "$outfile")"
fuyanbin's avatar
fuyanbin committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    obsutil cp "$outfile" 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"
    rm -rf "$packge_dir"
}

export PATH="$PATH:$(pwd)"/tools/

generate_vendor_confg
update_hugepall_zipfile
upload