-
Notifications
You must be signed in to change notification settings - Fork 235
/
makeimg.sh
executable file
·201 lines (174 loc) · 8.39 KB
/
makeimg.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
# Copyright (C) 2020 Xiaoxindada <[email protected]>
LOCALDIR=`cd "$( dirname ${BASH_SOURCE[0]} )" && pwd`
cd $LOCALDIR
source ./bin.sh
source ./language_helper.sh
Usage() {
cat <<EOT
Usage:
$0 <os_repackage_type>
os_repackage_type: System.img repack type: [--AB|--ab or -A|--a-only]
[--AB_CONFIG|--ab_config]: Use fs_config to repack ab system.img
[--A-ONLY_CONFIG|--a-only_config]: Use fs_config to repack a-only system.img
EOT
}
os_repackage_type="$1"
case $os_repackage_type in
"-A"|"-a"|"--a-only"|"--A-ONLY_CONFIG"|"--a-only_config")
systemdir="$TARGETDIR/system/system"
;;
"--AB"|"--ab"|"--AB_CONFIG"|"--ab_config")
systemdir="$TARGETDIR/system"
;;
"-h"|"--help")
Usage
exit
;;
*)
Usage
exit
;;
esac
if [ "$1" = "" ];then
Usage
exit
fi
configdir="$TARGETDIR/config"
target_contexts="system_test_contexts"
case $os_repackage_type in
"--AB"|"--ab"|"--AB_CONFIG"|"--ab_config")
system="$systemdir/system"
;;
"-A"|"--a-only"|"--A-ONLY_CONFIG"|"--a-only_config")
system="$systemdir"
;;
esac
case $os_repackage_type in
"--A-ONLY_CONFIG"|"--a-only_config")
echo "/ u:object_r:system_file:s0" > $configdir/system_A_contexts
echo "/system u:object_r:system_file:s0" >> $configdir/system_A_contexts
echo "/system(/.*)? u:object_r:system_file:s0" >> $configdir/system_A_contexts
echo "/system/lost+found u:object_r:system_file:s0" >> $configdir/system_A_contexts
echo "/ 0 0 0755" > $configdir/system_A_fs
echo "system 0 0 0755" >> $configdir/system_A_fs
echo "system/lost+found 0 0 0700" >> $configdir/system_A_fs
cat $configdir/system_file_contexts | grep "system_ext" >> $configdir/system_ext_contexts
cat $configdir/system_fs_config | grep "system_ext" >> $configdir/system_ext_fs
cat $configdir/system_file_contexts | grep "/system/system/" >> $configdir/system_A_contexts
cat $configdir/system_fs_config | grep "system/system/" >> $configdir/system_A_fs
sed -i 's#/system/system/system_ext#/system/system_ext#' $configdir/system_ext_contexts
sed -i 's#system/system/system_ext#system/system_ext#' $configdir/system_ext_fs
sed -i 's#/system/system#/system#' $configdir/system_A_contexts
sed -i 's#system/system#system#' $configdir/system_A_fs
cat $configdir/system_ext_contexts >> $configdir/system_A_contexts
cat $configdir/system_ext_fs >> $configdir/system_A_fs
;;
esac
# Generate debloated file_contexts
file_contexts() {
rm -rf $configdir/$target_contexts
mkdir -p $configdir
cat $system/etc/selinux/plat_file_contexts >> $configdir/$target_contexts
partition_name="system_ext product vendor"
for partition in $partition_name ;do
if [ -d $systemdir/$partition/etc/selinux ];then
file_contexts=$(ls $system/$partition/etc/selinux | grep file_contexts*)
#echo $system/$partition/etc/selinux/$file_contexts
[ -z $(cat $system/$partition/etc/selinux/$file_contexts) ] && continue
cat $system/$partition/etc/selinux/$file_contexts >> $configdir/$target_contexts
fi
done
}
file_contexts
case $os_repackage_type in
"-A"|"--a-only"|"--AB"|"--ab"|"--AB_CONFIG"|"--ab_config")
if [[ -f $configdir/$target_contexts ]]; then
echo "/firmware(/.*)? u:object_r:firmware_file:s0" >> $configdir/$target_contexts
echo "/bt_firmware(/.*)? u:object_r:bt_firmware_file:s0" >> $configdir/$target_contexts
echo "/persist(/.*)? u:object_r:mnt_vendor_file:s0" >> $configdir/$target_contexts
echo "/dsp u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/oem u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/op1 u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/op2 u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/charger_log u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/audit_filter_table u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/keydata u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/keyrefuge u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/omr u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/publiccert.pem u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/sepolicy_version u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/cust u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/donuts_key u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/v_key u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/carrier u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/dqmdbg u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/ADF u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/APD u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/asdf u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/batinfo u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/voucher u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/xrom u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/custom u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/cpefs u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/modem u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/module_hashes u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/pds u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/tombstones u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/factory u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/oneplus(/.*)? u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/addon.d u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/op_odm u:object_r:rootfs:s0" >> $configdir/$target_contexts
echo "/avb u:object_r:rootfs:s0" >> $configdir/$target_contexts
fi
;;
esac
if [ ! -d $systemdir ];then
echo "$SYSTEMDIR_NF"
exit
fi
echo "
$CURR_IMG_SIZE:
_________________
`du -sh $systemdir | awk '{print $1}' | bc -q | sed 's/$/&G/'`
`du -sm $systemdir | awk '{print $1}' | bc -q | sed 's/$/&M/'`
`du -sk $systemdir | awk '{print $1}' | bc -q | sed 's/$/&B/'`
_________________
"
size=`du -sk $systemdir | awk '{$1*=1024;$1=int($1*1.05);printf $1}'`
echo "$CURR_IMG_REPACK_SIZE: ${size} B"
echo ""
#mke2fs+e2fsdroid 打包
#$bin/mke2fs -L / -t ext4 -b 4096 $TARGETDIR/system.img $size
#$bin/e2fsdroid -e -T 0 -S $configdir/system_file_contexts -C $configdir/system_fs_config -a /system -f ./out/system $TARGETDIR/system.img
case $os_repackage_type in
"-A"|"-a"|"--a-only")
$bin/mkuserimg_mke2fs.sh "$systemdir" "$TARGETDIR/system.img" "ext4" "/system" $size -j "0" -T "1230768000" -L "system" -I "256" -M "/system" -m "0" $configdir/$target_contexts
;;
"--AB"|"--ab")
$bin/mkuserimg_mke2fs.sh "$systemdir" "$TARGETDIR/system.img" "ext4" "/" $size -j "0" -T "1230768000" -L "/" -I "256" -M "/" -m "0" $configdir/$target_contexts
;;
"--A-ONLY_CONFIG"|"--a-only_config")
$bin/mkuserimg_mke2fs.sh "$systemdir" "$TARGETDIR/system.img" "ext4" "/system" $size -j "0" -T "1230768000" -C "$configdir/system_A_fs" -L "system" -I "256" -M "/system" -m "0" "$configdir/system_A_contexts"
;;
"--AB_CONFIG"|"--ab_config")
$bin/mkuserimg_mke2fs.sh "$systemdir" "$TARGETDIR/system.img" "ext4" "/system" $size -j "0" -T "1230768000" -C "$configdir/system_fs_config" -L "system" -I "256" -M "/system" -m "0" "$configdir/system_file_contexts"
;;
esac
if [ -s $TARGETDIR/system.img ];then
echo "$PACK_STR$SUCCESS_STR"
echo "$OUTPUTTO_STR: $LOCALDIR/SGSI"
else
echo ""
exit
fi
if [ -s $TARGETDIR/system.img ];then
rm -rf $LOCALDIR/SGSI
mkdir -p $LOCALDIR/SGSI
mv -f $TARGETDIR/system.img ./SGSI/
cp -frp $system/build.prop $TARGETDIR/
./get_build_info.sh "$TARGETDIR" "$LOCALDIR/SGSI/system.img" > $LOCALDIR/SGSI/build_info.txt
rm -rf $TARGETDIR/build.prop
./copy.sh
chmod -R 777 $LOCALDIR/SGSI
fi