-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcustomize.sh
468 lines (380 loc) · 11.6 KB
/
customize.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!/system/bin/sh
# Magisk Module: Systemless Debloater v1.5.4a
# Copyright (c) zgfg @ xda, 2020-
# Config file improvements provided by ipdev @ xda
# XDA thread: https://forum.xda-developers.com/t/magisk-module-systemless-debloater.4180083
# GitHub source: https://github.com/zgfg/SystemlessDebloater
if [ -z $BOOTMODE ] || [ "$BOOTMODE" != "true" ]
then
abort "ERROR: Install from Magisk app, not from TWRP!"
fi
# Module's version
MyVersion=v1.5.4a
# Module's folder (upon the installation and reboot)
ModFolder=$(echo "$MODPATH" | sed "s!/modules_update/!/modules/!")
# Download folder
LogFolder=/sdcard/Download
# Alternative path to Internal memory
#LogFolder=/storage/emulated/0/Download
# Log file
LogFile=$LogFolder/SystemlessDebloater.log
echo "Magisk Module: Systemless Debloater $MyVersion log file." > $LogFile
echo 'Copyright (c) zgfg @ xda, 2020-' >> $LogFile
echo 'Config file improvements provided by ipdev @ xda' >> $LogFile
echo "Installation start time: $(date +%c)" >> $LogFile
echo '' >> $LogFile
# Log system info
Prop=$(getprop ro.product.cpu.abilist)
if [ ! -z "$Prop" ] && [ "$Prop" ]
then
echo "$Prop" | tee -a $LogFile
fi
Prop=$(getprop ro.build.version.release)
PrintLine='Android '$Prop
Prop=$(getprop ro.build.system_root_image)
if [ ! -z "$Prop" ] && [ "$Prop" ]
then
PrintLine=$PrintLine' SAR'
fi
Prop=$(getprop ro.build.ab_update)
if [ ! -z "$Prop" ] && [ "$Prop" ]
then
PrintLine=$PrintLine' A/B'
fi
Prop=$(getprop ro.boot.slot_suffix)
if [ ! -z "$Prop" ] && [ "$Prop" ]
then
PrintLine=$PrintLine" ($Prop)"
fi
echo "$PrintLine" | tee -a $LogFile
echo $(magisk -c) | tee -a $LogFile
echo '' >> $LogFile
# Verbose logging
VerboseLog="true"
# Default SAR mount-points (SAR partitions to search for debloating)
#SarMountPointList="/system product /vendor /system_ext /india /my_bigball"
SarMountPointList=""
# Invalid paths for (systemless) debloating
#InvalidMountPointList="/data /apex /framework"
InvalidMountPointList="/data /framework"
# Default/empty list of app names for debloating and debloated app names
DebloatList=""
DebloatedList=""
# Simple example for DebloatList var for the input file SystemlessDebloaterList.sh:
#DebloatList="EasterEgg CatchLog Traceur wps_lite"
# Searching for possible several instances of Stock apps for debloating
MultiDebloat="true"
# For Magisk v26, there is no more .replace file in REPLACEd folders on the /system side
# Potential problems when reinstalling/updating the module, to find the previously REPLACEd stock apps
# To avoid, force all debloating by mounting through service.sh
ForceMountList="true"
# Input and config files
InputFile=$LogFolder/SystemlessDebloaterList.sh
ConfigFile=$LogFolder/SystemlessDebloater.cfg
ExampleConfigFile=$MODPATH/SystemlessDebloater.cfg
# Check for the old input file
if [ -f "$InputFile" ]
then
# Source the old input file
echo 'Input source file: '$InputFile | tee -a $LogFile
. $InputFile
if [ ! -f "$ConfigFile" ]
then
echo 'Please delete your old '$InputFile | tee -a $LogFile
fi
echo '' >> $LogFile
fi
# Check for the config file
if [ -f "$ConfigFile" ]
then
echo 'Input config file: '$ConfigFile | tee -a $LogFile
echo '' >> $LogFile
# Clean the config file format and save to a temporary file
TmpConfigFile=$MODPATH/TmpSystemlessDebloater.cfg
sed -e '/^#/d' -e 's/#.*//g' -e 's/\"//g' -e 's/[ \t ]//g' -e '/^$/d' $ConfigFile > $TmpConfigFile
# Append new line to the temporary config if not present
if [ -n "$(tail -c1 $TmpConfigFile)" ]
then
echo >> $TmpConfigFile
fi
# Read DebloatList
DebloatList=$'\n'
while read AppName
do
DebloatList="$DebloatList$AppName"$'\n'
done < $TmpConfigFile
# Delete the temprary file
rm -f $TmpConfigFile
else
# Create the config file
cp $ExampleConfigFile $ConfigFile
if [ ! -z "$DebloatList" ]
then
echo '## My list of stock apps for debloating:' >> $ConfigFile
# Transfer DebloatList to the new config file
for AppName in $DebloatList
do
echo $AppName >> $ConfigFile
done
fi
echo 'New config file created: '$ConfigFile | tee -a $LogFile
echo '' >> $LogFile
fi
rm -f $ExampleConfigFile
echo "Verbose logging: $VerboseLog" >> $LogFile
echo "Multiple search/debloat: $MultiDebloat" >> $LogFile
echo "Force mounting by service.sh: $ForceMountList" >> $LogFile
echo '' >> $LogFile
# List Stock packages
Packages=$(pm list packages -f | sed 's!^package:!!g')
# Log input SarMountPointList
if [ ! -z "$VerboseLog" ] && [ "$VerboseLog" = "true" ]
then
echo 'Input SarMountPointList="'"$SarMountPointList"'"' >> $LogFile
echo '' >> $LogFile
fi
# Log InvalidMountPointList
echo 'InvalidMountPointList="'"$InvalidMountPointList"'"' >> $LogFile
echo '' >> $LogFile
# Add /system to SarMountPointList
NewList=$SarMountPointList
SarMountPointList="/system"$'\n'
for Path in $NewList
do
# Append to SarMountPointList
SarMountPointList="$SarMountPointList$Path"$'\n'
done
# Search through packages to add potential mount points
for PackageInfo in $Packages
do
# Extract potential mount point path from PackageInfo
Path=$(echo "$PackageInfo" | cut -d '/' -f 2)
# Append to SarMountPointList
SarMountPointList="$SarMountPointList/$Path"$'\n'
done
# Sort SarMountPointList to remove duplicates
NewList=$(echo "$SarMountPointList" | sort -bu )
# Exclude not valid paths from SarMountPointList
SarMountPointList=""
for Path in $NewList
do
# Skip not valid paths
for InvalidPath in $InvalidMountPointList
do
if [ "$Path" = "$InvalidPath" ]
then
Path=""
break
fi
done
# Append to SarMountPointList
if [ ! -z "$Path" ]
then
SarMountPointList="$SarMountPointList"$'\n'"$Path"
fi
done
# Log final SarMountPointList
echo 'Final SarMountPointList="'"$SarMountPointList"'"' >> $LogFile
echo '' >> $LogFile
# Log input DebloatList
echo 'Input DebloatList="'"$DebloatList"'"' >> $LogFile
echo '' >> $LogFile
# Sort DebloatList
NewList=$DebloatList
DebloatList=""
for AppName in $NewList
do
# Append to DebloatList
DebloatList="$DebloatList$AppName"$'\n'
done
DebloatList=$(echo "$DebloatList" | sort -bu )
# Log final DebloatList
if [ ! -z "$VerboseLog" ] && [ "$VerboseLog" = "true" ]
then
echo 'Final DebloatList="'"$DebloatList"'"' >> $LogFile
echo '' >> $LogFile
fi
# List Stock packages
PackageInfoList=""
for PackageInfo in $Packages
do
# Include only applications from SAR mount points
for SarMountPoint in $SarMountPointList
do
if [ -z $(echo "$PackageInfo" | grep '^$SarMountPoint/') ]
then
PrepPackageInfo=$PackageInfo
# Append to the PackageInfoList
PackageInfoList="$PackageInfoList$PrepPackageInfo"$'\n'
break
fi
done
done
# Sort PackageInfoList
PackageInfoList=$(echo "$PackageInfoList" | sort -bu )
#Search for Stock apps
StockAppList=""
for SarMountPoint in $SarMountPointList
do
NewList=$(find "$SarMountPoint/" -type f -name "*.apk" 2> /dev/null)
if [ ! -z "$NewList" ]
then
StockAppList="$StockAppList$NewList"$'\n'
fi
done
# Search for previously REPLACEd Stock apps
DotReplace='.replace'
ReplacedAppList=""
for SarMountPoint in $SarMountPointList
do
NewList=$(find "$SarMountPoint/" -type f -name "$DotReplace" 2> /dev/null)
if [ ! -z "$NewList" ]
then
ReplacedAppList="$ReplacedAppList"$'\n'"$NewList"
fi
done
# For Magisk v26, there is no more .replace file in REPLACEd folders on the /system side
# When reinstalling the module, search for previously REPLACEd stock apps also in the module's folder
NewList=$(find "$ModFolder/system/" -type f -name "$DotReplace" 2> /dev/null)
if [ ! -z "$NewList" ]
then
for FilePath in $NewList
do
# Extract the corresponding /system path
FilePath=$(echo "$FilePath" | sed "s!^$ModFolder!!")
FolderPath=$(echo "$FilePath" | sed "s!$DotReplace$!!")
# Check if the corresponding /system folder exists
if [ -d $FolderPath ]
then
ReplacedAppList="$ReplacedAppList"$'\n'"$FilePath"
fi
done
fi
# Sort ReplacedAppList
ReplacedAppList=$(echo "$ReplacedAppList" | sort -bu )
# Log ReplacedAppList
if [ ! -z "$VerboseLog" ] && [ "$VerboseLog" = "true" ]
then
echo "Previously REPLACEd Stock apps:$ReplacedAppList"$'\n' >> $LogFile
fi
# List of apps to debloat by REPLACE and by mounting
REPLACE=""
MountList=""
# Iterate through apps for debloating
echo 'Debloating:' >> $LogFile
for AppName in $DebloatList
do
AppFound=""
# Search through previously REPLACEd Stock apps
SearchName="/$AppName/$DotReplace"
SearchList=$(echo "$ReplacedAppList" | grep "$SearchName$")
for FilePath in $SearchList
do
# Break if app already found
if [ "$AppFound" = "true" ] && [ "$MultiDebloat" != "true" ]
then
break
fi
# Remove /filename from the end of the path
FileName=${FilePath##*/}
FolderPath=$(echo "$FilePath" | sed "s,/$FileName$,,")
if [ ! -z "$FolderPath" ]
then
AppFound="true"
# Log the full path
echo "found: $FilePath" >> $LogFile
if [ "$ForceMountList" = "true" ] || [ -z $(echo "$FolderPath" | grep '^/system/') ]
then
# Append to MountList with appended AppName
MountList="$MountList$FolderPath/$AppName.apk"$'\n'
else
# Append to REPLACE list
REPLACE="$REPLACE$FolderPath"$'\n'
fi
# Append to DebloatedList
DebloatedList="$DebloatedList$AppName"$'\n'
fi
done
#Search through Stock apps
SearchName=/"$AppName".apk
SearchList=$(echo "$StockAppList" | grep "$SearchName$")
for FilePath in $SearchList
do
# Break if app already found
if [ "$AppFound" = "true" ] && [ "$MultiDebloat" != "true" ]
then
break
fi
# Find the corresponding package
PackageInfo=$(echo "$PackageInfoList" | grep "$FilePath")
PackageName=""
# Extract package name
if [ ! -z "$PackageInfo" ]
then
PackageName=$(echo "$PackageInfo" | sed "s!^$FilePath=!!")
PackageName="($PackageName) "
fi
# Remove /filename from the end of the path
FileName=${FilePath##*/}
FolderPath=$(echo "$FilePath" | sed "s,/$FileName$,,")
if [ ! -z "$FolderPath" ]
then
AppFound="true"
# Log the full path and package name
echo "found: $FilePath $PackageName" >> $LogFile
if [ "$ForceMountList" = "true" ] || [ -z $(echo "$FolderPath" | grep '^/system/') ]
then
# Append to MountList
MountList="$MountList$FilePath"$'\n'
else
# Append to REPLACE list
REPLACE="$REPLACE$FolderPath"$'\n'
fi
# Append to DebloatedList
DebloatedList="$DebloatedList$AppName"$'\n'
fi
done
if [ -z "$AppFound" ]
then
# Log app name if not found
echo "$AppName --- app not found!" | tee -a $LogFile
fi
done
echo '' >> $LogFile
if [ -z "$REPLACE" ] && [ -z "$MountList"]
then
echo 'No app for debloating found!' | tee -a $LogFile
echo 'Make sure to uninstall updates and clear data for apps you want to debloat!' | tee -a $LogFile
echo '' >> $LogFile
fi
# Sort and log DebloatedList
DebloatedList=$(echo "$DebloatedList" | sort -bu )
echo 'DebloatedList="'"$DebloatedList"$'\n"' >> $LogFile
echo '' >> $LogFile
# Sort and log REPLACE list
REPLACE=$(echo "$REPLACE" | sort -bu )
if [ "$ForceMountList" != "true" ]
then
echo 'REPLACE="'"$REPLACE"$'\n"' >> $LogFile
echo '' >> $LogFile
fi
# Sort and log MountList
MountList=$(echo "$MountList" | sort -bu )
echo 'MountList="'"$MountList"$'\n"' >> $LogFile
echo '' >> $LogFile
# Prepare for debloating/mounting through servise.sh and mountList.sh
MountListFile='mountList.sh'
echo 'MountList="'"$MountList"$'\n"' >> $MODPATH/$MountListFile
# Log the MountListFile path
echo "MountListFile:"$'\n'"$ModFolder/$MountListFile" >> $LogFile
echo '' >> $LogFile
# Log Stock apps and packages
if [ ! -z "$VerboseLog" ] && [ "$VerboseLog" = "true" ]
then
echo "Stock apps:"$'\n'"$StockAppList" >> $LogFile
echo "Stock packages: $PackageInfoList" >> $LogFile
echo '' >> $LogFile
fi
# Log installation end time and note for the log file
echo "Installation end time: $(date +%c)" >> $LogFile
echo "Systemless Debloater log: $LogFile"