pack.sh 5.6 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
#!/bin/bash
牛文敏's avatar
牛文敏 committed
2
set -e
3
4
5
6
7
8
9
10
#!/bin/bash
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
11
                    --packtype <pack type>
12
13
14
                    --help"
    exit 1
}
牛文敏's avatar
牛文敏 committed
15

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

zhouzhenyu's avatar
zhouzhenyu committed
25
26
27
28
# new append
NOUPLOAD="false"
LOCAL="false"

29
30
31
32
export PATH=${PATH}:$(pwd)/tools/
PARSED_ARUGMENTS=$(getopt -a -n "$0" -o V:t:i: --long help,vendor:,type:,image:,chroot-type:,orgcode:,channelid:, -- "$@")
eval set -- "${PARSED_ARUGMENTS}"
while :
fuyanbin's avatar
fuyanbin committed
33
do
34
35
36
37
38
39
40
    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
41
        --packtype) PACK_TYPE="$2"; shift 2;;
42
43
44
45
        --help) usage ;;
        --) shift; break;;
        *) usage ;;
    esac
fuyanbin's avatar
fuyanbin committed
46
done
fuyanbin's avatar
fuyanbin committed
47

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

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

56
57
58
    systemfile="$build_dir/system.PARTITION"
    systemfile_ext4="$build_dir/system.PARTITION.ext4"

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

    mkdir "$build_dir/system"
fuyanbin's avatar
fuyanbin committed
69
    mount "$loopdev" "$build_dir/system"
70

fuyanbin's avatar
fuyanbin committed
71
    touch "$build_dir/system/.androidrom"
72

fuyanbin's avatar
fuyanbin committed
73
    rm -f "$build_dir/system/hugep-all.zip"
fuyanbin's avatar
fuyanbin committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    rm -f "$build_dir/system/bin/hugep-all.zip"

    android_sdk="$(grep "sdk\.version" "$build_dir"/system/build.prop | awk -F'=' '{print $2}')"
    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"
        if ! find_autostart -script_name preinstall.sh -initrc "$packge_dir"/init.rc > "$packge_dir"/find_autostart.log
        then
            find_autostart -script_name recovery.sh -initrc "$packge_dir"/init.rc > "$packge_dir"/find_autostart.log
        fi
        local auto_start_script
        auto_start_script="$(cat "$packge_dir"/find_autostart.log)"
        if [[ -n "$auto_start_script" ]]
        then
            if ! grep -q "#!/system/bin/sh" "$build_dir"/system/"$auto_start_script"
            then
                echo "#!/system/bin/sh" >> "$build_dir"/system/"$auto_start_script"
            fi
            echo "starthugep.sh > /dev/null 2>&1 &" >> "$build_dir"/system/"$auto_start_script"
        fi
    fi
107

fuyanbin's avatar
fuyanbin committed
108
    find ./services/ -type f ! -name  "*.rc" -exec install -m 0777 -t "$build_dir"/system/bin/ {} \;
109
110
    for file in $(find ./services/ -type f ! -name "*.rc")
    do
fuyanbin's avatar
fuyanbin committed
111
        chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")"
112
113
    done

fuyanbin's avatar
fuyanbin committed
114
115
    umount "$loopdev"
    losetup -d "$loopdev"
116
117
118
119
120
121
122
123
124
    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
125
    aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "${packge_dir}/$(basename "$img")"
fuyanbin's avatar
fuyanbin committed
126
    rm -rf "$build_dir"
127
128
}

fuyanbin's avatar
fuyanbin committed
129
generate_vendor_confg() {
130
131
132
133
134
135
    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
136
137
138
139
    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
140
141
    sed -i'' "s#__CHANNEL_ID__#$CHANNELID#g"  "$yaml_file_src"
    sed -i'' "s#__PACK_TYPE__#$PACK_TYPE#g"  "$yaml_file_src"
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    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
156
    zip -u -j "$hugep_zip_file" "$yaml_file"
157
158
}

zhouzhenyu's avatar
zhouzhenyu committed
159
upload() {
fuyanbin's avatar
cleanup    
fuyanbin committed
160
161
162
163
    local date_i
    local outfile
    local outfile_7z
    local MD5SUM
zhouzhenyu's avatar
zhouzhenyu committed
164

fuyanbin's avatar
cleanup    
fuyanbin committed
165
166
167
168
    outfile="${packge_dir}/$(basename "$IMAGE_FILE")"
    outfile_7z="${outfile}.7z"
    date_i="$(date +%Y-%m-%d-%s)"
    MD5SUM=$(md5sum "$outfile" | awk '{print $1}' )
zhouzhenyu's avatar
zhouzhenyu committed
169

fuyanbin's avatar
cleanup    
fuyanbin committed
170
171
172
173
    if [[ "$NOUPLOAD" != "true" ]]
    then
        7z a -mm=LZMA2 "$outfile_7z" "$outfile"
        upload.sh --file "$outfile_7z" --directory product/terminal/chroot_androidrom/"$ORGCODE/$date_i"
fuyanbin's avatar
fuyanbin committed
174
        IMG_URL="https://cdn.linkfog.cn/""product/terminal/chroot_androidrom/$ORGCODE/$date_i/$(basename "$outfile_7z")"
zhouzhenyu's avatar
zhouzhenyu committed
175
176
        echo "RESULT: ${VENDOR} ${IMG_URL} ${MD5SUM} ${TITLE}"

fuyanbin's avatar
cleanup    
fuyanbin committed
177
        rm -f "$outfile" "$outfile_7z"
fuyanbin's avatar
fuyanbin committed
178
        rm -rf "$packge_dir"
zhouzhenyu's avatar
zhouzhenyu committed
179
180
181
    fi
}

fuyanbin's avatar
cleanup    
fuyanbin committed
182
export PATH="$PATH:$(pwd)"/tools/
fuyanbin's avatar
fuyanbin committed
183
184
185

generate_vendor_confg
update_hugepall_zipfile
186
build_image "$IMAGE_FILE"
zhouzhenyu's avatar
zhouzhenyu committed
187
upload