pack.sh 4.33 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
11
12
13
#!/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>
                    --help"
    exit 1
}
牛文敏's avatar
牛文敏 committed
14

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

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

27
28
29
30
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
31
do
32
33
34
35
36
37
38
39
40
41
42
    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;;
        --help) usage ;;
        --) shift; break;;
        *) usage ;;
    esac
fuyanbin's avatar
fuyanbin committed
43
done
fuyanbin's avatar
fuyanbin committed
44

45
46
47
48
49
50
51
52
53
54
55
build_dir=$(mktemp -d ./tmp.XXXXX)

build_image() {
    img="$1"
    systemfile="$build_dir/system.PARTITION"
    systemfile_ext4="$build_dir/system.PARTITION.ext4"

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

    mkdir "$build_dir/system"
fuyanbin's avatar
fuyanbin committed
62
    mount "$loopdev" "$build_dir/system"
63

fuyanbin's avatar
fuyanbin committed
64
    touch "$build_dir/system/.androidrom"
65

fuyanbin's avatar
fuyanbin committed
66
67
    rm -f "$build_dir/system/hugep-all.zip"
    cp -f "$build_dir/hugep-all.zip" "$build_dir/system/hugep-all.zip"
68

fuyanbin's avatar
fuyanbin committed
69
70
    find ./services/ -type f -name "*.rc" -exec install -t "$build_dir"/system/etc/init/ {} \;
    find ./services/ -type f ! -name  "*.rc" -exec install -m 0777 -t "$build_dir"/system/bin/ {} \;
71
72
    for file in $(find ./services/ -type f ! -name "*.rc")
    do
fuyanbin's avatar
fuyanbin committed
73
        chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")"
74
75
    done

fuyanbin's avatar
fuyanbin committed
76
77
    umount "$loopdev"
    losetup -d "$loopdev"
78
79
80
81
82
83
84
85
86
87
    rm -rf "$build_dir/system"
    sync

    if [[ -f "$systemfile_ext4" ]]
    then
        rm -f "$systemfile"
        img2simg "$systemfile_ext4" "$systemfile"
        rm -f "$systemfile_ext4"
    fi
    aml_image_v2_packer -r "./$build_dir/image.cfg" "$build_dir" "$(basename "$img")"
fuyanbin's avatar
fuyanbin committed
88
    rm -rf "./$build_dir/"
89
90
}

fuyanbin's avatar
fuyanbin committed
91
generate_vendor_confg() {
92
93
94
95
96
97
    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
98
99
100
101
    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"
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    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
116
    zip -u -j "$hugep_zip_file" "$yaml_file"
117
118
}

zhouzhenyu's avatar
zhouzhenyu committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
upload() {
    # get current time
    local date_i=$(date +%Y-%m-%d-%s)
    echo "$date_i"
    echo "line 34 end"

    echo "$IMAGE_FILE"
    outfile=$(basename "$IMAGE_FILE")
    echo "$outfile"
    MD5SUM=$(md5sum ${outfile} | awk '{print $1}' )
    if [[ "$NOUPLOAD" != "true" ]]
    then
        7z a -mm=LZMA2 $outfile.7z $outfile

        old_outfile=$outfile
        rm -f $old_outfile
        outfile=$outfile.7z

        # upload to dir
        upload.sh $args --file ${outfile} --directory product/terminal/chroot_androidrom/${ORGCODE}/${date_i}
        # construct URL
        IMG_URL="https://cdn.linkfog.cn/""product/terminal/chroot_androidrom/${ORGCODE}/${date_i}"
        # title
        TITLE="???Armbian ???,VENDOR:${VENDOR},ORGCODE:${ORGCODE} ${date}"
        mail.sh ${VENDOR} ${IMG_URL} ${MD5SUM} ${TITLE} 2>/dev/null

        echo "RESULT: ${VENDOR} ${IMG_URL} ${MD5SUM} ${TITLE}"

        # delete .img file
        rm -f ${outfile}
    fi
}

152
export PATH="$PATH":"$(pwd)"/tools/
fuyanbin's avatar
fuyanbin committed
153
154
155
156


generate_vendor_confg
update_hugepall_zipfile
157
build_image "$IMAGE_FILE"
zhouzhenyu's avatar
zhouzhenyu committed
158
upload