pack.sh 6.53 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
#!/bin/bash
2
3
4
5
6
7
8
usage() {
    echo "Usage: $0 -V | --vendor  <vendor id>
                    -t | --type <pipe type>
                    -i | --image <image file>
                    --chroot-type <pack type>
                    --orgcode <organization code>
                    --channelid <channel id>
fuyanbin's avatar
fuyanbin committed
9
                    --packtype <pack type>
10
11
12
                    --help"
    exit 1
}
牛文敏's avatar
牛文敏 committed
13

14
15
16
17
18
19
VENDOR=""
PIPE_TYPE="small"
CHROOT_TYPE="androidrom"
DEPLOY="elf"
ORGCODE=""
CHANNELID=""
fuyanbin's avatar
typo    
fuyanbin committed
20
IMAGE_FILE=""
fuyanbin's avatar
fuyanbin committed
21
PACK_TYPE="other"
fuyanbin's avatar
fuyanbin committed
22

zhouzhenyu's avatar
zhouzhenyu committed
23
24
25
26
# new append
NOUPLOAD="false"
LOCAL="false"

27
export PATH=${PATH}:$(pwd)/tools/
fuyanbin's avatar
fuyanbin committed
28
PARSED_ARUGMENTS=$(getopt -a -n "$0" -o V:t:i: --long help,vendor:,type:,image:,chroot-type:,orgcode:,channelid:,packtype: -- "$@")
29
30
eval set -- "${PARSED_ARUGMENTS}"
while :
fuyanbin's avatar
fuyanbin committed
31
do
32
33
34
35
36
37
38
    case "$1" in
        -V | --vendor) VENDOR="$2"; shift 2 ;;
        -t | --type) PIPE_TYPE="$2"; shift 2 ;;
        -i | --image) IMAGE_FILE="$2"; shift 2 ;;
        --chroot-type) CHROOT_TYPE="$2"; shift 2 ;;
        --orgcode) ORGCODE="$2"; shift 2;;
        --channelid) CHANNELID="$2"; shift 2;;
fuyanbin's avatar
fuyanbin committed
39
        --packtype) PACK_TYPE="$2"; shift 2;;
40
41
42
43
        --help) usage ;;
        --) shift; break;;
        *) usage ;;
    esac
fuyanbin's avatar
fuyanbin committed
44
done
fuyanbin's avatar
fuyanbin committed
45

fuyanbin's avatar
cleanup    
fuyanbin committed
46
47
build_dir=$(mktemp -d /build/tmp.XXXXX)
packge_dir=$(mktemp -d /build/tmp.XXXXX)
fuyanbin's avatar
fuyanbin committed
48
boot_dir=$(mktemp -d /build/tmp.XXXXX)
49
50

build_image() {
fuyanbin's avatar
cleanup    
fuyanbin committed
51
    local img="$1"
fuyanbin's avatar
fuyanbin committed
52
    local android_sdk
fuyanbin's avatar
cleanup    
fuyanbin committed
53

54
55
56
    systemfile="$build_dir/system.PARTITION"
    systemfile_ext4="$build_dir/system.PARTITION.ext4"

fuyanbin's avatar
fuyanbin committed
57
    aml_image_v2_packer -d "$img" "$build_dir"
58
59
60
    if file "$systemfile" | grep "Android sparse image"
    then
        simg2img "$systemfile" "$systemfile_ext4"
fuyanbin's avatar
fuyanbin committed
61
        loopdev=$(losetup -P -f --show "$systemfile_ext4")
62
    else
fuyanbin's avatar
fuyanbin committed
63
        loopdev=$(losetup -P -f --show "$systemfile")
64
65
66
    fi

    mkdir "$build_dir/system"
fuyanbin's avatar
fuyanbin committed
67
    mount "$loopdev" "$build_dir/system"
68

fuyanbin's avatar
fuyanbin committed
69
    touch "$build_dir/system/.androidrom"
70

fuyanbin's avatar
fuyanbin committed
71
    rm -f "$build_dir/system/hugep-all.zip"
fuyanbin's avatar
fuyanbin committed
72
73
    rm -f "$build_dir/system/bin/hugep-all.zip"

fuyanbin's avatar
fuyanbin committed
74
    android_sdk="$(grep "build\.version\.sdk" "$build_dir"/system/build.prop | awk -F'=' '{print $2}')"
75
76
    android_sdk="${android_sdk//$'\r'}"
    android_sdk="${android_sdk//$'\n'}"
fuyanbin's avatar
fuyanbin committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    if [[ "$android_sdk" -ge 28 ]]
    then
        find ./services/ -type f -name "*.rc" -exec install -t "$build_dir"/system/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"
fuyanbin's avatar
fuyanbin committed
92
        if ! find_autostart -script_name preinstall.sh -initrc "$packge_dir"/init.rc -root_path "$build_dir" > "$packge_dir"/find_autostart.log 2>/dev/null
fuyanbin's avatar
fuyanbin committed
93
        then
fuyanbin's avatar
fuyanbin committed
94
            find_autostart -script_name recovery.sh -initrc "$packge_dir"/init.rc -root_path "$build_dir" > "$packge_dir"/find_autostart.log 2>/dev/null
fuyanbin's avatar
fuyanbin committed
95
96
97
        fi
        local auto_start_script
        auto_start_script="$(cat "$packge_dir"/find_autostart.log)"
fuyanbin's avatar
typo    
fuyanbin committed
98
        if [[ -z "$auto_start_script" ]] && [[ -f "$build_dir"/system/bin/startsoftdetector.sh ]]
99
        then
100
            # TODO: startsoftdetector.sh 会阻塞在某一步,要把 starthugep.sh 加在中间部分
101
102
            auto_start_script="/system/bin/startsoftdetector.sh"
        fi
103
        # NOTE: 返回的脚本路径里一定以 /system/ 开头, 所以下边拼路径时没有加上 /system
fuyanbin's avatar
fuyanbin committed
104
105
        if [[ -n "$auto_start_script" ]]
        then
106
            if ! grep -q "#!/system/bin/sh" "$build_dir"/"$auto_start_script"
fuyanbin's avatar
fuyanbin committed
107
            then
108
                echo "#!/system/bin/sh" >> "$build_dir"/"$auto_start_script"
fuyanbin's avatar
fuyanbin committed
109
            fi
fuyanbin's avatar
fuyanbin committed
110
            echo " " >> "$build_dir"/"$auto_start_script"
111
112
113
            echo "/system/bin/starthugep.sh > /dev/null 2>&1 &" >> "$build_dir"/"$auto_start_script"
            chmod 0755 "$build_dir"/"$auto_start_script"
            chcon u:object_r:drmserver_exec:s0 "$build_dir"/"$auto_start_script"
fuyanbin's avatar
fuyanbin committed
114
115
        fi
    fi
116

fuyanbin's avatar
fuyanbin committed
117
    cp -f "$build_dir/hugep-all.zip" "$build_dir"/system/bin/hugep-all.zip
fuyanbin's avatar
fuyanbin committed
118

fuyanbin's avatar
fuyanbin committed
119
    find ./services/ -type f ! -name  "*.rc" ! -name "*.zip" -exec install -m 0777 -t "$build_dir"/system/bin/ {} \;
fuyanbin's avatar
fuyanbin committed
120
121
122
    cp -f services/manager_bin_file.zip "$build_dir"/system/bin/manager_bin_file.zip

    for file in $(find ./services/ -type f ! -name "*.rc" ! -name "*.zip")
123
    do
fuyanbin's avatar
fuyanbin committed
124
        chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")"
125
126
    done

fuyanbin's avatar
fuyanbin committed
127
128
    umount "$loopdev"
    losetup -d "$loopdev"
129
130
131
132
133
134
135
136
137
    rm -rf "$build_dir/system"
    sync

    if [[ -f "$systemfile_ext4" ]]
    then
        rm -f "$systemfile"
        img2simg "$systemfile_ext4" "$systemfile"
        rm -f "$systemfile_ext4"
    fi
fuyanbin's avatar
fuyanbin committed
138
    aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "${packge_dir}/$(basename "$img")"
fuyanbin's avatar
fuyanbin committed
139
    rm -rf "$build_dir"
140
141
}

fuyanbin's avatar
fuyanbin committed
142
generate_vendor_confg() {
143
144
145
146
147
148
    local yaml_file_src
    local yaml_file

    yaml_file="$build_dir"/vendor.yaml
    yaml_file_src="$build_dir"/vendor.yaml.src
    cp vendor.yaml.src "$yaml_file_src"
fuyanbin's avatar
fuyanbin committed
149
150
151
152
    sed -i'' "s#__VENDOR__#$VENDOR#g"  "$yaml_file_src"
    sed -i'' "s#__ORGCODE__#$ORGCODE#g"  "$yaml_file_src"
    sed -i'' "s#__CHROOT_TYPE__#$CHROOT_TYPE#g"  "$yaml_file_src"
    sed -i'' "s#__DEPLOY__#$DEPLOY#g"  "$yaml_file_src"
fuyanbin's avatar
fuyanbin committed
153
154
    sed -i'' "s#__CHANNEL_ID__#$CHANNELID#g"  "$yaml_file_src"
    sed -i'' "s#__PACK_TYPE__#$PACK_TYPE#g"  "$yaml_file_src"
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    aio -m enc -i "$yaml_file_src" -o "$yaml_file"
}

update_hugepall_zipfile() {
    local yaml_file
    local hugep_zip_file
    local hugep_zip_file_origin

    yaml_file="$build_dir"/vendor.yaml
    hugep_zip_file="$build_dir/hugep-all.zip"
    hugep_zip_file_origin="./services/hugep-all.zip"

    cp "$hugep_zip_file_origin" "$hugep_zip_file"

fuyanbin's avatar
fuyanbin committed
169
    zip -u -j "$hugep_zip_file" "$yaml_file"
170
171
}

zhouzhenyu's avatar
zhouzhenyu committed
172
upload() {
fuyanbin's avatar
cleanup    
fuyanbin committed
173
174
    local date_i
    local outfile
fuyanbin's avatar
fuyanbin committed
175
    local outfile_gz
fuyanbin's avatar
cleanup    
fuyanbin committed
176
    local MD5SUM
177
    local uri
zhouzhenyu's avatar
zhouzhenyu committed
178

fuyanbin's avatar
cleanup    
fuyanbin committed
179
    outfile="${packge_dir}/$(basename "$IMAGE_FILE")"
fuyanbin's avatar
fuyanbin committed
180
    outfile_gz="${outfile}.gz"
fuyanbin's avatar
cleanup    
fuyanbin committed
181
182
    date_i="$(date +%Y-%m-%d-%s)"
    MD5SUM=$(md5sum "$outfile" | awk '{print $1}' )
zhouzhenyu's avatar
zhouzhenyu committed
183

fuyanbin's avatar
cleanup    
fuyanbin committed
184
185
    if [[ "$NOUPLOAD" != "true" ]]
    then
fuyanbin's avatar
fuyanbin committed
186
        zstd --ultra --format=gzip "$outfile" -o "$outfile_gz"
fuyanbin's avatar
fuyanbin committed
187
        uri="product/terminal/chroot_androidrom/""$ORGCODE/$date_i/$(basename "$outfile_gz")"
188
189
        obsutil cp "$outfile_gz" obs://fae-cdn.linkfog.cn/"$uri"
        IMG_URL="https://fae-cdn.linkfog.cn/""$uri"
zhouzhenyu's avatar
zhouzhenyu committed
190
191
        echo "RESULT: ${VENDOR} ${IMG_URL} ${MD5SUM} ${TITLE}"

fuyanbin's avatar
fuyanbin committed
192
        rm -f "$outfile" "$outfile_gz"
fuyanbin's avatar
fuyanbin committed
193
        rm -rf "$packge_dir"
zhouzhenyu's avatar
zhouzhenyu committed
194
195
196
    fi
}

fuyanbin's avatar
cleanup    
fuyanbin committed
197
export PATH="$PATH:$(pwd)"/tools/
fuyanbin's avatar
fuyanbin committed
198
199
200

generate_vendor_confg
update_hugepall_zipfile
201
build_image "$IMAGE_FILE"
zhouzhenyu's avatar
zhouzhenyu committed
202
upload