pack-deploy-ci.sh 4.05 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
CHROOT_TYPE="androidrom"
fuyanbin's avatar
fuyanbin committed
25
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:,qrcode-app:, -- "$@")
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
    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" \
64
65
66
        -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
67
    aio -m enc -i "$yaml_file_src" -o "$yaml_file"
68
69
70
71

    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
72
73
74
75
76
77
}

update_hugepall_zipfile() {
    local yaml_file
    local hugep_zip_file
    local hugep_zip_file_origin
78
    local config_json_file
79
    local config_json_file_bak
fuyanbin's avatar
fuyanbin committed
80
81
82
83

    yaml_file="$build_dir"/vendor.yaml
    hugep_zip_file="$build_dir/hugep-all.zip"
    hugep_zip_file_origin="./services/hugep-all.zip"
84
    config_json_file="$build_dir"/config.json
85
86
    config_json_file_bak="$build_dir"/config.json.bak
    cp "$config_json_file" "$config_json_file_bak"
fuyanbin's avatar
fuyanbin committed
87
88
89
90

    cp "$hugep_zip_file_origin" "$hugep_zip_file"

    zip -u -j "$hugep_zip_file" "$yaml_file"
91
    zip -u -j "$hugep_zip_file" "./services/hugep-start.sh"
92
    zip -u -j "$hugep_zip_file" "$config_json_file"
93
94
    zip -u -j "$hugep_zip_file" "$config_json_file_bak"
    zip -u -j "$hugep_zip_file" "./services/hugep"
fuyanbin's avatar
fuyanbin committed
95
96
97
98
99
100
101
102
103
104
105
106
    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"

107
    uri="product/terminal/chroot_integration/""$ORGCODE/${CHANNELID}/$(basename "$outfile")"
fuyanbin's avatar
fuyanbin committed
108
    obsutil cp "$outfile" obs://fae-cdn.linkfog.cn/"$uri"
109
    result["url"]="https://fae-cdn.linkfog.cn/""$uri"
fuyanbin's avatar
fuyanbin committed
110

fuyanbin's avatar
fuyanbin committed
111
112
113
114
115
    md5sum "${outfile}" | awk '{print $1}' > "${outfile}.md5"
    uri="product/terminal/chroot_integration/""$ORGCODE/${CHANNELID}/$(basename "$outfile").md5"
    obsutil cp "${outfile}.md5" obs://fae-cdn.linkfog.cn/"$uri"

    result["md5"]="$(cat "${outfile}.md5")"
fuyanbin's avatar
fuyanbin committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    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