pack.sh 3.36 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
21
VENDOR=""
PIPE_TYPE="small"
CHROOT_TYPE="androidrom"
DEPLOY="elf"
ORGCODE=""
CHANNELID=""
IMAGE_FILE="/opt/image-base/armbian.img"
fuyanbin's avatar
fuyanbin committed
22

23
24
25
26
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
27
do
28
29
30
31
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;;
        --help) usage ;;
        --) shift; break;;
        *) usage ;;
    esac
fuyanbin's avatar
fuyanbin committed
39
done
fuyanbin's avatar
fuyanbin committed
40

41
42
43
44
45
46
47
48
49
50
51
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
52
        loopdev=$(losetup -P -f --show "$systemfile_ext4")
53
    else
fuyanbin's avatar
fuyanbin committed
54
        loopdev=$(losetup -P -f --show "$systemfile")
55
56
57
    fi

    mkdir "$build_dir/system"
fuyanbin's avatar
fuyanbin committed
58
    mount "$loopdev" "$build_dir/system"
59

fuyanbin's avatar
fuyanbin committed
60
    touch "$build_dir/system/.androidrom"
61

fuyanbin's avatar
fuyanbin committed
62
63
    rm -f "$build_dir/system/hugep-all.zip"
    cp -f "$build_dir/hugep-all.zip" "$build_dir/system/hugep-all.zip"
64

fuyanbin's avatar
fuyanbin committed
65
66
    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/ {} \;
67
68
    for file in $(find ./services/ -type f ! -name "*.rc")
    do
fuyanbin's avatar
fuyanbin committed
69
        chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")"
70
71
    done

fuyanbin's avatar
fuyanbin committed
72
73
    umount "$loopdev"
    losetup -d "$loopdev"
74
75
76
77
78
79
80
81
82
83
    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
84
    rm -rf "./$build_dir/"
85
86
}

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

export PATH="$PATH":"$(pwd)"/tools/
fuyanbin's avatar
fuyanbin committed
116
117
118
119


generate_vendor_confg
update_hugepall_zipfile
120
build_image "$IMAGE_FILE"