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 14
/
Copy patherofs.sh
executable file
·120 lines (111 loc) · 6.83 KB
/
erofs.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
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
117
118
119
120
#!/bin/bash
IMAGE=$(realpath $1)
PARTITION=$2
SIZE=$3
rm -rf log.txt >> /dev/null
touch log.txt
NEWIMAGE="$PARTITION-ext4.img"
LOCALDIR=`cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd`
RUNDIR=$(dirname $1)
MOUNTDIR="$LOCALDIR/$PARTITION"
toolsdir="$LOCALDIR/tools"
tmpdir="$LOCALDIR/tmp"
fileconts="$tmpdir/plat_file_contexts"
usage() {
echo "sudo ./$0 <image path> <partition name>"
}
if [[ $2 == "" ]]; then
usage
fi
mount() {
sudo rm -rf $tmpdir $MOUNTDIR
mkdir $MOUNTDIR
echo "[INFO] Mounting $PARTITION..."
sudo mount -t auto -o loop $IMAGE $MOUNTDIR
}
contextfix() {
echo "/opconfig(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/opcust(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/3rdmodem(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/3rdmodemnvm(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/3rdmodemnvmbkp(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/cust(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/eng(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/hw_product(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/log(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/modem_log(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/patch_hw(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/preas(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/prets(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/pretvs(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/resetFactory.cfg(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/sec_storage(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/splash2(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_bigball(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_carrier(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_custom(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_company(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_engineering(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_heytap(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_manifest(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_preload(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_product(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_region(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_stock(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/my_version(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/special_preload(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/preavs(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/preload(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/version(/.*)? u:object_r:rootfs:s0" >> "$fileconts"
echo "/(oppo_custom|my_custom)/theme_bak(/.*)? u:object_r:oppo_theme_data_file:s0
/(my_(engineering|version|product|company|preload|bigball|carrier|region|stock|heytap|manifest|custom)|special_preload)(/.*)? u:object_r:system_file:s0
/(my_(engineering|version|product|company|preload|bigball|carrier|region|stock|heytap|custom)|special_preload)/overlay(/.*)? u:object_r:vendor_overlay_file:s0
/(my_(engineering|version|product|company|preload|bigball|carrier|region|stock|heytap|custom)|special_preload)/non_overlay/overlay(/.*)? u:object_r:vendor_overlay_file:s0
/(my_(engineering|version|product|company|preload|bigball|carrier|region|stock|heytap|custom)|special_preload)/vendor_overlay/[0-9]+/.* u:object_r:vendor_file:s0
/(my_(engineering|version|product|company|preload|bigball|carrier|region|stock|heytap|custom)|special_preload)/vendor/etc(/.*)? u:object_r:vendor_configs_file:s0
/(my_version|odm)/build.prop u:object_r:vendor_file:s0
/(my_version|odm)/vendor_overlay/[0-9]+/lib(64)?(/.*)? u:object_r:same_process_hal_file:s0
/(my_version|odm)/vendor_overlay/[0-9]+/etc/camera(/.*)? u:object_r:same_process_hal_file:s0
/(my_version|odm)/vendor_overlay/[0-9]+/camera(/.*)? u:object_r:vendor_file:s0
/(my_version|odm)/lib64/camera(/.*)? u:object_r:vendor_file:s0
/(my_version|odm)/vendor_overlay/lib?(/.*)? u:object_r:same_process_hal_file:s0
/(my_version|odm)/vendor_overlay/lib(64)?(/.*)? u:object_r:same_process_hal_file:s0
/my_manifest/build.prop u:object_r:vendor_file:s0
/my_company/theme_bak(/.*)? u:object_r:oem_theme_data_file:s0
/my_product/etc/project_info.txt u:object_r:vendor_file:s0
/my_product/product_overlay/framework(/.*)? u:object_r:system_file:s0
/my_product/product_overlay/etc/permissions(/.*)? u:object_r:system_file:s0
/(vendor|my_engineering|system/vendor)/bin/factory u:object_r:factory_exec:s0
/(vendor|my_engineering|system/vendor)/bin/pcba_diag u:object_r:pcba_diag_exec:s0
/my_product/lib(64)?/libcolorx-loader\.so u:object_r:same_process_hal_file:s0
/my_product/vendor/firmware(/.*) u:object_r:vendor_file:s0
/my_version/vendor/firmware(/.*)? u:object_r:vendor_file:s0" >> "$fileconts"
if [[ $PARTITION != "system" ]]; then
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
fi
}
rebuild() {
mkdir $tmpdir
echo "[INFO] Rebuilding $PARTITION as ext4 image..."
cp -fpr $(sudo find $MOUNTDIR | grep file_contexts) $tmpdir/ >/dev/null 2>&1
contextfix
SIZE=`du -sk $MOUNTDIR | awk '{$1*=1024;$1=int($1*2);printf $1}'`
if (( $SIZE < 1474560 )); then
SIZE=`du -sk $MOUNTDIR | awk '{$1*=1024;$1=int($1*7);printf $1}'`
fi
if [[ $PARTITION == "system" ]]; then
sudo $toolsdir/mkuserimg_mke2fs.py "$MOUNTDIR/" "$NEWIMAGE" ext4 "/" $SIZE $fileconts -j "0" -T "1230768000" -L "/" -I "256" -M "/" -m "0" >> log.txt
else
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
fi
sudo umount -f -l $MOUNTDIR
rm -rf $MOUNTDIR
sudo rm -rf $tmpdir
echo "[INFO] Done"
}
mount
rebuild