pack.sh 2.36 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
#!/bin/bash
牛文敏's avatar
牛文敏 committed
2
set -e
fuyanbin's avatar
fuyanbin committed
3
img="$1"
牛文敏's avatar
牛文敏 committed
4
5
6
zippath="$2"
zipname=$(basename "$zippath")

fuyanbin's avatar
fuyanbin committed
7
8
9
10
11
12
13
build_dir=$(mktemp -d ./tmp.XXXXX)
systemfile="$build_dir/system.PARTITION"
systemfile_ext4="$build_dir/system.PARTITION.ext4"
smallprcfile="$(pwd)/services/smallp.rc"
starthugepfile="$(pwd)/services/starthugep.sh"
uninstallpkgrc="$(pwd)/services/uninstallpkg.rc"
uninstallpkgfile="$(pwd)/services/uninstallpkg.sh"
14
setmacrc="$(pwd)/services/setmac.rc"
fuyanbin's avatar
fuyanbin committed
15
setmacfile="$(pwd)/services/set-mac.sh"
fuyanbin's avatar
fuyanbin committed
16
17
18
19
startthirdpartyrc="$(pwd)/services/startthirdparty.rc"
startthirdpartyfile="$(pwd)/services/startthirdparty.sh"
hugepstartfile="$(pwd)/services/hugepstart.sh"

fuyanbin's avatar
fuyanbin committed
20
21
22
23
24
25
26
27
28

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
fuyanbin's avatar
fuyanbin committed
29

fuyanbin's avatar
fuyanbin committed
30
31
32
mkdir "$build_dir/system"
sudo mount "$loopdev" "$build_dir/system"

fuyanbin's avatar
fuyanbin committed
33
sudo touch "$build_dir/system/.androidrom"
fuyanbin's avatar
fuyanbin committed
34

35
sudo wget -P "$build_dir/system/" -O "$build_dir/system/bin/hugep-all.zip"
牛文敏's avatar
牛文敏 committed
36

37
sudo chmod 777 "$starthugepfile"
fuyanbin's avatar
fuyanbin committed
38
39
40
41
42
43
44
45
sudo cp -f "$smallprcfile" "$build_dir/system/etc/init/"
sudo cp -f "$starthugepfile" "$build_dir/system/bin/"
sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$starthugepfile")"

sudo cp -f "$uninstallpkgrc" "$build_dir/system/etc/init"
sudo cp -f "$uninstallpkgfile" "$build_dir/system/bin"
sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$uninstallpkgfile")"

46
47
48
49
sudo cp -f "$setmacrc" "$build_dir/system/etc/init"
sudo cp -f "$setmacfile" "$build_dir/system/bin"
sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$setmacfile")"

fuyanbin's avatar
fuyanbin committed
50
51
52
53
54
55
56
sudo cp -f "$startthirdpartyrc" "$build_dir/system/etc/init"
sudo cp -f "$startthirdpartyfile" "$build_dir/system/bin"
sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$startthirdpartyfile")"

sudo cp -f "$hugepstartfile" "$build_dir/system/bin"
sudo chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$hugepstartfile")"

fuyanbin's avatar
fuyanbin committed
57
58
sudo umount "$loopdev"
sudo losetup -d "$loopdev"
59
rm -rf "$build_dir/system"
fuyanbin's avatar
fuyanbin committed
60
61
62
63
64
65
66
67
68
69
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")"
rm -rf "./$build_dir/"