pack.sh 3.38 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
107
108
109
110
111
112
113
114
115
116
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"
        loopdev=$(sudo losetup -P -f --show "$systemfile_ext4")
    else
        loopdev=$(sudo losetup -P -f --show "$systemfile")
    fi

    mkdir "$build_dir/system"
    sudo mount "$loopdev" "$build_dir/system"

    sudo touch "$build_dir/system/.androidrom"

    sudo rm -f "$build_dir/system/hugep-all.zip"
    sudo cp -f "$build_dir/hugep-all.zip" "$build_dir/system/hugep-all.zip"

    sudo find ./services/ -type f -name "*.rc" -exec install -t "$build_dir"/system/etc/init/ {} \;
    sudo find ./services/ -type f ! -name  "*.rc" -exec install -m 0777 -t "$build_dir"/system/bin/ {} \;
    for file in $(find ./services/ -type f ! -name "*.rc")
    do
        sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")"
    done

    sudo umount "$loopdev"
    sudo losetup -d "$loopdev"
    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")"
    sudo rm -rf "./$build_dir/"
}

genarae_vendor_confg() {
    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"
    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"
    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"

    zip -u -j "$yaml_file" "$hugep_zip_file"
}

export PATH="$PATH":"$(pwd)"/tools/
build_image "$IMAGE_FILE"