This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
product-merge.sh
executable file
·91 lines (78 loc) · 2.21 KB
/
product-merge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
#!/bin/bash
PARTITION=product
# SIZE=$1
rm -rf log.txt >> /dev/null
touch log.txt
NEWIMAGE="$PARTITION-ext4.img"
LOCALDIR=`cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd`
RUNDIR=$(realpath .)
MOUNTDIR="$LOCALDIR/$PARTITION"
toolsdir="$LOCALDIR/tools"
tmpdir="$LOCALDIR/tmp"
fileconts="$tmpdir/plat_file_contexts"
PRODUCTDIR=$LOCALDIR/product
SIZECACHE="$tmpdir/size"
echo "[INFO] Cleaning up existing build residue"
rm -rf $PRODUCTDIR
# if [[ $1 == "" ]]; then
# SIZE=4294967296
# else
# SIZE=$1
# fi
usage() {
echo "sudo ./$0"
}
PARTITIONS="my_product my_engineering my_company my_carrier my_region my_heytap my_stock my_preload my_bigball my_manifest"
mkdir $PRODUCTDIR
mkdir -p $tmpdir
touch $fileconts
merge() {
mkdir $partition
mount -o loop -t auto $partition.img $partition
cp -fpr $partition/* $PRODUCTDIR/
umount -f -l $partition
rm -rf $partition
}
clean() {
echo "[INFO] Cleaning product image"
cd $PRODUCTDIR
rm -rf apkcerts.txt
rm -rf applist
rm -rf build.prop
rm -rf custom_info.txt
rm -rf decouping_wallpaper
rm -rf del*
rm -rf etc
rm -rf framework
rm -rf lost+found
rm -rf media
rm -rf non_overlay
rm -rf plugin
rm -rf product_overlay
rm -rf res
rm -rf vendor
cd $RUNDIR
}
fconts() {
echo "[INFO] Grabbing file contexts"
mkdir $LOCALDIR/system
sudo mount -t auto $RUNDIR/system.img $LOCALDIR/system
sudo cat $LOCALDIR/system/system/etc/selinux/plat_file_contexts >> $fileconts
sudo umount -f -l $LOCALDIR/system
rm -rf $LOCALDIR/system
}
getsize() {
echo "[INFO] Setting image size"
SIZE=`du -sk $PRODUCTDIR | awk '{$1*=1024;$1=int($1*1.05);printf $1}'`
}
for partition in $PARTITIONS; do
echo "[INFO] Merging $partition into product.img"
merge >> log.txt
done
clean
fconts
getsize
echo "[INFO] Rebuilding Product image"
sudo $toolsdir/mkuserimg_mke2fs.py "$MOUNTDIR/" "$NEWIMAGE" ext4 "/$PARTITION" $SIZE $fileconts -j "0" -T "1230768000" -L "$PARTITION" -I "256" -M "/$PARTITION" -m "0" >> log.txt
echo "[INFO] Done! Cleaning up"
rm -rf $PRODUCTDIR $tmpdir