-
Notifications
You must be signed in to change notification settings - Fork 0
/
njasd_linux.sh
684 lines (668 loc) · 24.8 KB
/
njasd_linux.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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
#!/usr/bin/env bash
#
# NJASD (Not Just A System Debloater) v1.2.
# By mdp43140
#
### Config ###
BASE_DIR_HOST="."
BASE_DIR_PHONE="/sdcard/njasd"
BLOATWARES_LIST_UNINSTALL_SYSTEM="$BASE_DIR_HOST/Bloatware_List.txt"
INSTALL_APPS_DIR="$BASE_DIR_HOST/Install_Apps"
color_prompt="auto"
DETECT_ROOT_ALTER="auto"
KEEP_DATA=0
# Here are the lists of caches that can be removed
PHONE_CACHE_DIRECTORIES_ROOT=(
'/data/data/*/cache/*'
'/data/data/*/code_cache/*'
'/data/data/*/app_google_tagmanager'
'/data/data/*/app_textures'
'/data/data/*/app_fiverocks'
'/data/data/*/app_webview'
'/data/data/*/no_backup/.flurryNoBackup'
'/data/data/*/files/.com.google.firebase.crashlytics'
'/data/data/*/files/.Fabric'
'/data/data/*/files/al'
'/data/data/*/files/audience_network.dex'
'/data/data/*/files/CountlyINSTALLATION'
'/data/data/*/files/oat/audience_network.dex*'
'/data/data/*/databases/webviewCache'
'/data/data/*/databases/google_app_measurement*.db*'
'/data/data/*/databases/google_tagmanager.db*'
'/data/anr/*'
'/data/log/*'
'/data/local/tmp/*'
'/data/system/dropbox/*'
'/data/system/usagestats/*'
'/data/backup/pending/*'
'/data/tombstones/*'
'/cache/*'
)
# Here are the lists of caches that can be removed without root access
PHONE_CACHE_DIRECTORIES=(
'/sdcard/Android/data/*/cache'
'/sdcard/Android/data/*/files/il2cpp'
'/sdcard/Android/data/*/files/Unity'
'/sdcard/Android/data/*/files/logs'
'/sdcard/Android/data/*/files/vungle_cache'
'/storage/*-*/Android/data/*/cache'
'/storage/*-*/Android/data/*/files/il2cpp'
'/storage/*-*/Android/data/*/files/Unity'
'/storage/*-*/Android/data/*/files/logs'
'/storage/*-*/Android/data/*/files/vungle_cache'
)
#############
### Other stuff ###
NJASD_VERSION='1.6'
NJASD_LAST_CHANGED='07/06/2022 10:00'
NJASD_RELEASE_BRANCH='MAIN'
set -uo pipefail # Safer bash script (especially on command pipes and stuff, add -e for easier debugging (abort on any non-zero exit code, aka. error))
PHONE_CACHE_DIRECTORIES_ROOT="${PHONE_CACHE_DIRECTORIES_ROOT[@]}"
PHONE_CACHE_DIRECTORIES="${PHONE_CACHE_DIRECTORIES[@]}"
HOST_TYPE="$([ -d '/system' ] && echo android || echo linux)"
###################
### "CLGUI" menu ###
MAIN(){
print_header;echo -en $C_YELLOW
echo -e "[1] Remove bloatware "$C_END"("$C_GREEN"Recommended"$C_END")"$C_YELLOW
echo -e "[2] Deny bloatware package's permission"
echo -e "[3] Install your custom packages"
echo -e "[4] Install open-source alternative packages "$C_END"(TODO, "$C_GREEN"Recommended for root users"$C_END")"$C_YELLOW
echo -e "[5] Restore uninstalled bloatwares"
echo -e "[r] Restart your android phone"
echo -e "[ ] Reload"
echo -e "[R] Root options"
echo -e "[a] ADB Connection manager"
echo -e "[X] Stop ADB Server and Exit"
echo -e $C_LRED"[Ctrl+C] Exit"
read -sn1
print_header
case $REPLY in
X) echo -e "$C_INFO Stopping ADB Server and Exiting..."
adb kill-server
fxbgyclr
;;1|2|3|4|5|r) if ! adb get-state &>/dev/null;then echo -e "$C_ERR No Devices Detected";unset REPLY;ssleep 1;MAIN;fi
;;\ ) MAIN
;;a) MAIN_adb
;;R) MAIN_root
esac
case $REPLY in
1) debloat_wrapper
;;2) restrict_appops
;;3) install_packages
;;4) install_foss
;;5) restore_packages
;;r) echo -e "$C_WARN Restarting your connected Android phone..."
adb reboot
;;*) echo -e "$C_ERR Invalid option";ssleep 1;;
esac
MAIN
}
MAIN_adb(){
print_header
echo -e $C_INFO" ADB Connection manager"$C_YELLOW
echo -e "[1] Restart ADB listening on TCP "$C_END"("$C_YELLOW"Wireless ADB, make sure you're connected to an access point"$C_END")"$C_YELLOW
echo -e "[2] Restart ADB listening on USB "$C_END"("$C_YELLOW"Wired ADB"$C_END")"$C_YELLOW
echo -e "[3] Connect a device "$C_END"("$C_YELLOW"only if the device is set to listen TCP previously"$C_END")"$C_RED
echo -e "[4] Disconnect everything"$C_YELLOW
echo -e "[5] List connected devices"$C_YELLOW
echo -e "[ ] Reload"
echo -e "[x] Go back"
read -sn1
print_header
case $REPLY in
x) MAIN
;;1|2|5|r) if ! adb get-state &>/dev/null;then echo -e "$C_ERR No Devices Detected";unset REPLY;ssleep 1;MAIN_adb;fi
;;\ ) MAIN_adb
esac
case $REPLY in
1) echo -en "$C_INFO Type the port you want to use (default:5555)\n$C_INFO > "
prompt
if [ "$REPLY" ];then
echo -e "$C_INFO Reinitiating connection to TCP port $REPLY..."
adb tcpip $REPLY
fi
;;2) echo -e "$C_INFO Reinitiating connection to USB..."
adb usb
;;3) echo -en "$C_INFO Type your device Local IP (port is optional and will use 5555 by default, make sure the server and the device is on the same network)\n$C_INFO > "
prompt
if [ "$REPLY" ];then
echo -en "$C_INFO Connecting to $REPLY..."
adb connect $REPLY
echo -e "\r$C_INFO Connected to $REPLY!\e[0K"
ssleep 1
fi
;;4) echo -e "$C_INFO Disconnecting all devices..."
adb disconnect
;;5) adb devices | sed -E -e "s/List of devices attached/$C_INFO List of devices attached/g" | printf
pause
;;*) echo -e "$C_ERR Invalid option";ssleep 1;;
esac
MAIN_adb
}
MAIN_root(){
print_header;echo -en $C_YELLOW
echo -e "For-Root-user options"
echo -e "[1] Clean App Cache "$C_END"("$C_GREEN"Recommended"$C_END")"$C_YELLOW
echo -e "[ ] Reload"
echo -e "[x] Go back"
echo -e $C_LRED"[Ctrl+C] Exit"
read -sn1
print_header
case $REPLY in
1) if ! adb get-state &>/dev/null;then echo -e "$C_ERR No Devices Detected";unset REPLY;ssleep 1;MAIN;fi
;;x) MAIN
;;\ ) MAIN_root
esac
case $REPLY in
1) cleancache_wrapper
;;*) echo -e "$C_ERR Invalid option";ssleep 1;;
esac
MAIN_root
}
debloat_wrapper(){
print_header
if [ "$(detect_root)" = "1" ];then
echo -e "$C_SUCCESS Root user detected, using root method is "$C_GREEN"recommended"$C_END
elif [ $(fetch_info_from_device android_version) -ge 9 ];then
echo -e "$C_INFO Non-root and Android 8+, using default method is "$C_GREEN"recommended"$C_END
else
echo -e "$C_WARN Detected using Android 8-."
fi
echo -e "$C_INFO Choose the method of removing bloatware "$C_END"("$C_YELLOW"remember, these will also "$C_LRED"CLEAR data"$C_YELLOW". to "$C_GREEN"keep data"$C_YELLOW", RERUN this script with "$C_END$C_BOLD"--keep-data"$C_END$C_YELLOW" argument"$C_END"):"
echo -e $C_LRED"[R] Delete APK Directly "$C_END"("$C_GREEN"root required"$C_END")"
echo -e $C_YELLOW"[U] Uninstall "$C_END"(default)"
echo -e $C_GREEN"[D] Disable "$C_END"(if you want to easy-reinstall w/o pc)"$C_END
echo -e $C_LRED"[F] Delete Bloatware-related system files "$C_END"("$C_GREEN"root required"$C_END")"
echo -e "[p] View the list of apps/files that going to be removed ("$C_GREEN"recommended"$C_END" before you "$C_YELLOW"do removal process"$C_END")"
echo -e "[x] Go back"
echo -e $C_LRED"[Ctrl+C] Exit"$C_END
read -sn1
print_header
case $REPLY in
R) debloat_root
;;U) debloat
;;D) debloat_disable
;;F) debloat_filesystems
;;p) declare -A BLOAT_LIST=();local tmp0
associate_path_with_package BLOAT_LIST
echo -e "$C_INFO Apps that going to be removed:"
for i in ${!BLOAT_LIST[@]};do tmp0+="$i ${BLOAT_LIST[$i]}\n";done
if [ -z "$tmp0" ];then
echo -e "$C_SUCCESS No apps that are going to be removed."
else
echo -e "$C_LGRAY$tmp0" | sort -ui
fi
echo -e "$C_END"
unset BLOAT_LIST tmp0
echo -e "$C_INFO Files that going to be removed:$C_LGRAY"
cat System_Bloatwares.txt
pause
debloat_wrapper
;;x) MAIN
;;*) echo -e "$C_ERR Invalid option";ssleep 1;debloat_wrapper;;
esac
home
}
cleancache_wrapper(){
print_header
if [ "$(detect_root)" = "1" ];then
echo -e "$C_SUCCESS Root user detected, everything should work as intended"$C_END
else
echo -e "$C_WARN Non-root detected. without root, NJASD cant clean everything"
fi
echo -e $C_RED"[C] Clean caches"$C_END
echo -e $C_YELLOW"[T] Wreck tracking properties (Experimental)"$C_END
echo -e "[c] View the list of caches that going to be removed ("$C_GREEN"recommended"$C_END" before you "$C_YELLOW"do cleanup process"$C_END")"
echo -e "[t] View the list of tracking xml that going to be modified"
echo -e "[x] Go back"
echo -e $C_LRED"[Ctrl+C] Exit"$C_END
read -sn1
print_header
case $REPLY in
C) cleancache
pause
;;T) voluntarywrenchtracker
pause
;;c) echo -e $C_LGRAY
if [ "$(detect_root)" = "1" ];then
adb shell "su -c ls -Aqd1 $PHONE_CACHE_DIRECTORIES_ROOT"
else
echo -e $C_WARN' No root'
fi
adb shell "ls -Aqd1 $PHONE_CACHE_DIRECTORIES"
pause
cleancache_wrapper
;;t) echo -e $C_LGRAY
if [ "$(detect_root)" = "1" ];then
adb shell 'su -c ls -Aqd1 /data/data/*/shared_prefs/{_HANSEL_FILTERS_SP,_HANSEL_TRACKER_SP,adjust_preferences,com.applovin.sdk.1,com.applovin.sdk.impl.postbackQueue.domain,com.applovin.sdk.preferences.*,com.applovin.sdk.shared,com.crashlytics.prefs,com.crashlytics.sdk.android:answers:settings,com.dynatrace.android.dtxPref,com.google.android.gms.measurement.prefs,com.google.android.gms.appid,com.google.firebase.crashlytics,com.facebook.sdk.appEventPreferences,com.facebook.sdk.attributionTracking,com.facebook.sdk.USER_SETTINGS,com.fyber.unity.ads.OfferWallUnityActivity,com.medallia.*,FBAdPrefs,FirebaseAppHeartBeat,fiverocks,FyberPreferences,fyber*,tjcPrefrences,TwitterAdvertisingInfoPreferences}.xml'
else
echo -e $C_WARN' No root'
fi
pause
cleancache_wrapper
;;x) MAIN
;;*) echo -e "$C_ERR Invalid option";ssleep 1;cleancache_wrapper;;
esac
cleancache_wrapper
}
restore_packages(){
print_header
echo -e "$C_INFO This menu allows you to restore apps that has been uninstalled"
echo "using normal method (pm uninstall --user 0 [package_name])"
echo
echo -e "$C_ERR WIP (Work In Progress..., this area should show uninstalled package names)"
echo
echo -e "$C_INFO Type the package name you want to restore (eg com.facebook.katana)"
echo "and press Enter to confirm the option"
echo "[] Go Back (press enter without typing anything)"
echo -en $C_LRED"[Ctrl+C] Exit"$C_END"\n > "
prompt
case $REPLY in
"") MAIN
;;*) print_header
if [ "$(adb shell 'pm list packages -u'|grep $REPLY)" = "package:$REPLY" ];then
echo -en $C_SUCCESS Package $REPLY found, Reinstalling $REPLY...
adb shell "pm install-existing $REPLY"
else
echo -e $C_ERR Package $REPLY not found.
fi
pause
;;
esac
MAIN
}
####################
### Core Functions ###
debloat(){
local RESULT
local COMMAND
for i in $(get_bloatware_list);do
COMMAND+="echo -e \"$C_INFO Uninstalling $i... \""
if [ "$KEEP_DATA" = "0" ];then
COMMAND+="am force-stop $i;pm uninstall $i || pm uninstall --user 0 $i"
else
COMMAND+="am force-stop $i;pm uninstall -k $i || pm uninstall --user 0 -k $i"
fi
COMMAND+="'[ \"$RESULT\" = \"Success\" -a \"$?\" = \"0\" ] && echo -e \"$C_SUCCESS Success\" || echo -e \"$C_ERR $RESULT\"'"
done
adb shell "$COMMAND"
echo -e $C_SUCCESS Done!
pause
}
debloat_root(){
if [ $(fetch_info_from_device android_version) -gt 9 ];then
echo -en "$C_INFO Android 9+ detected\n$C_INFO remounting / as read-write...\r"
adb shell "su -c 'mount -wo remount /'" && echo -e "\e[0K$C_SUCCESS / remounted as read-write" || echo -e "\e[0K$C_ERR Failed to remount / as read-write"
else
echo -en "$C_INFO Android 9 or below detected\n$C_INFO remounting /system as read-write...\r"
adb shell "su -c 'mount -wo remount /system'" && echo -e "\e[0K$C_SUCCESS /system remounted as read-write" || echo -e "\e[0K$C_ERR Failed to remount /system as read-write"
fi
echo -en "$C_INFO Remounting /odm as Read-write...\r"
adb shell "su -c 'mount -wo remount /odm'" && echo -e "\e[0K$C_SUCCESS /odm remounted as read-write" || echo -e "\e[0K$C_ERR Failed to remount /odm as read-write"
declare -A BLOAT_LIST=()
associate_path_with_package BLOAT_LIST
for i in "${!BLOAT_LIST[@]}";do
echo -en "$C_WARN Deleting $i (${BLOAT_LIST[$i]})...\r"
#TODO: should remove /system/app/NAME instead of just its ./NAME.apk, maybe use basename??
#for now, we use workaround, remove blank folders in /system/app and /system/priv-app
adb shell "am force-stop $i &>/dev/null;pm clear $i &>/dev/null;pm uninstall --user 0 $i &>/dev/null;su -c rm -r ${BLOAT_LIST[$i]} &>/dev/null" && echo -e "\e[0K$C_SUCCESS $i (${BLOAT_LIST[$i]}) Removed!" || echo -e "\e[0K$C_ERR Can't remove $i (${BLOAT_LIST[$i]}). Error code: $?"
done
echo -e $C_INFO' Cleaning empty folders in /system/app...'$C_LGRAY
adb shell "su -c find /system/app -type d -empty -print -delete -o -type f -empty -print -delete"
echo -e $C_INFO' Cleaning empty folders in /system/priv-app...'$C_LGRAY
adb shell "su -c find /system/priv-app -type d -empty -print -delete -o -type f -empty -print -delete"
echo -e $C_INFO 'Remounting /system as Read-only (for security reason)...'
adb shell "su -c mount -fro remount /"
echo -e $C_SUCCESS' Done! reboot is recommended'
pause
}
debloat_disable(){
for i in $(get_bloatware_list);do
if [ "$KEEP_DATA" = "0" ];then
echo -en "$C_INFO $C_YELLOW(clearing data)$C_END and disabling $i...\r"
adb shell "pm clear $i &>/dev/null" || echo -e "$C_ERR Can't clear $i data. Error code: $?"
else
echo -en "$C_INFO Disabling $i..."
fi
adb shell "am force-stop $i &>/dev/null;pm disable $i &>/dev/null;pm disable-user $i &>/dev/null"
[ "$?" = "0" ] && echo -e "$C_SUCCESS $i Disabled!" || echo -e "$C_ERR Can't disable $i. Error code: $?"
done
echo -e $C_SUCCESS Done!
pause
}
debloat_filesystems(){
echo -e "$C_ERR Work-in-progress, this section should remove bloatware-related files defined in System_Bloatwares."
}
restrict_appops(){
echo -e $C_WARN This feature is still barebone
if [ -f "modules/DenyBloatPermsNOps.sh" ];then
modules/DenyBloatPermsNOps.sh
echo -e $C_SUCCESS Done!
else
echo -e "$C_ERR modules/DenyBloatPermsNOps.sh did'nt exist! make sure ./modules folder exist"
fi
pause
}
install_packages(){
if ! [ -d "$INSTALL_APPS_DIR" ];then
echo -e $C_WARN" $INSTALL_APPS_DIR didn't exist, creating one..."
mkdir -p "$INSTALL_APPS_DIR"
fi
echo -e $C_INFO" Now put any APKs you want to install to $INSTALL_APPS_DIR."
echo -e $C_INFO" If you have split apk, put it in a directory (TODO), or zipped with .apkm/.apks as extension (TODO)"
echo -e $C_INFO" Note: Installed APK on the directory will be removed"
pause
for i in $(ls $INSTALL_APPS_DIR/*.apk);do
echo -en $C_INFO" Installing $i... "
adb install "$INSTALL_APPS_DIR/$i" && rm -r "$INSTALL_APPS_DIR/$i" || read -N1 -t10
done
#TODO
for i in $(ls *.{apkm,apks,zip});do
ii=${i%.apkm}
ii=${ii%.apks}
ii=${ii%.zip}
mv -T $i $ii.zip
echo "Unpacking $ii..."
unzip $ii.zip *.apk -d $ii
echo "Installing $ii... "
installSplitApk $ii
done
echo -e $C_SUCCESS' Done!'
pause
}
install_foss(){
echo -e "$C_INFO To be implemented, coming soon";ssleep 1
}
cleancache(){
#Clear any caches that can be cleaned (root)
if [ "$(detect_root)" = "1" ];then
echo -e $C_INFO' Root detected, the procedure can begin now'
for i in $(adb shell "su -c ls -Aqd1 $PHONE_CACHE_DIRECTORIES_ROOT" | grep -E '^/');do
echo -e "$C_INFO Removing $i..."
#adb shell 'su -c rm -r $i/*'
done
else
echo -e "$C_WARN No root detected. Can't clean files/folders that requires root access"
echo -e "$C_WARN Ignoring the error, and continuing clearing possible directories"
fi
#Clear Caches in Internal/external(sdcard) storage
for i in $(adb shell echo $PHONE_CACHE_DIRECTORIES);do
echo -e "$C_INFO Removing $i..."
#adb shell 'rm -rf $i'
done
#Clear logcat logs
adb logcat -c
}
voluntarywrenchtracker(){
echo -e $C_LGRAY
echo -e $C_WARN This might overwrite wrong files, make sure to have a backup!
echo -e $C_WARN This is a very barebone and experimental work-in-progress script!
if [ "$(detect_root)" = "1" ];then
if [ -d "modules/WrenchTrackers" -a -f "modules/WrenchTrackers/WrenchTrackers.sh" ];then
adb shell "rm -r $BASE_DIR_PHONE"
echo -e "$C_INFO Pushing required files to phone... ($BASE_DIR_PHONE/WrenchTrackers)"
adb push $BASE_DIR_HOST/modules/WrenchTrackers $BASE_DIR_PHONE/WrenchTrackers > /dev/null
echo -e "$C_INFO Executing shell script on phone..."
adb shell "su -c sh $BASE_DIR_PHONE/WrenchTrackers/WrenchTrackers.sh"
echo -e "$C_INFO Phone-side script exited with exit code $?"
echo -e "$C_INFO Removing temporary njasd files located on phone..."
adb shell "rm -r $BASE_DIR_PHONE"
echo -e $C_SUCCESS Done!
else
echo -e "$C_ERR modules/WrenchTrackers did'nt exist! make sure its exist"
fi
else
echo -e $C_ERR' This requires root, but no root detected.'
fi
}
optimize_sql_databases(){
echo -e $C_ERR' Work-in-progress, this should query all possible SQL databases and optimize them'
pause
}
######################
### Helper functions ###
prompt(){ # only used when inputting text, not choice
tput cnorm
read $@
tput civis
}
pause(){
echo -en $C_INFO Press any key to continue...;
read -sn1
}
ssleep(){ # soft sleep (aka. interuptable sleep, usually for pausing stuff)
read -sn1 -t$1
}
associate_path_with_package(){
local -n ASSOCIATE="$1"
declare -a PACKAGES=()
readarray -t PACKAGES < <(adb shell 'pm list packages -f'|sed 's/^package:https://'|grep -F "$(cat $BLOATWARES_LIST_UNINSTALL_SYSTEM|sed '/^#/d'|egrep -hv "^[[:space:]]*$"|awk '{gsub(/^[ \t]+|[ \t]+$/,"");print}')"|sort -ui)
for i in "${PACKAGES[@]}";do
ASSOCIATE["${i##*=}"]="${i%=*}"
done
}
get_bloatware_list(){
adb shell 'pm list packages'|sed 's/^package:https://'|grep -F "$(cat $BLOATWARES_LIST_UNINSTALL_SYSTEM|sed '/^#/d'|egrep -hv "^[[:space:]]*$"|awk '{gsub(/^[ \t]+|[ \t]+$/,"");print}')"|sort -ui
}
detect_root(){
if [ "$DETECT_ROOT_ALTER" = "auto" ];then
if [ "$(adb shell su -c whoami 2&>/dev/null)" = "root" ];then
echo 1
else
echo 0
fi
elif [ "$DETECT_ROOT_ALTER" = "yes" ];then
echo 1
elif [ "$DETECT_ROOT_ALTER" = "no" ];then
echo 0
fi
}
fetch_info_from_device(){
if [ "$1" = "brand" ];then
local brand
brand=$(adb shell getprop ro.product.brand | tr -d '\r' | awk '{print tolower($0)}')
case "$brand" in
"redmi"|"poco") echo xiaomi
;; "honor") echo oppo
;; *) echo $brand
esac
elif [ "$1" = "Brand" ];then
local brand
brand=$(adb shell getprop ro.product.brand | tr -d '\r')
case "$(echo $brand | awk '{print tolower($0)}')" in
"redmi"|"poco") echo Xiaomi
;; "honor") echo Oppo
;; *) echo $brand
esac
elif [ "$1" = "android_sdk_version" ];then
local ANDROID_SDK_VERSION
ANDROID_SDK_VERSION=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
echo $ANDROID_SDK_VERSION
elif [ "$1" = "android_version" ];then
local ANDROID_SDK_VERSION
ANDROID_SDK_VERSION=$(adb shell getprop ro.build.version.release | tr -d '\r')
echo $ANDROID_SDK_VERSION
# elif [ "$1" = "installed_packages" ];then
#
fi
}
print_header(){
local SEP="$C_LBLUE$(printf "=%.0s" `seq -s' ' $COLUMNS`)$C_END"
clear
echo -e $SEP$C_LGREEN"\n $TITLE"$C_END
if adb get-state &>/dev/null;then
echo -en "\n$SEP\r\e[A Brand: $C_YELLOW.......$C_END, Android version: $C_YELLOW..$C_END, Android SDK version: $C_YELLOW..$C_END\r"
echo -e "\e[0K Brand: "$C_YELLOW$(fetch_info_from_device Brand)$C_END", Android version: "$C_YELLOW$(fetch_info_from_device android_version)$C_END", Android SDK version: "$C_YELLOW$(fetch_info_from_device android_sdk_version)$C_END
else
echo -e "$C_LRED No devices detected$C_END\n Make sure "$C_YELLOW"USB Debugging"$C_END" is "$C_GREEN"enabled"$C_END" on your phone"
fi
echo -e $SEP
}
installSplitApk(){ #TODO, ported from Batch version
#Configuration
DIR_OF_SPLIT_APKS=$1
#For each APKs
for i in $DIR_OF_SPLIT_APKS/*.apk;do
#Calculate all of the APK in a directory, and move them to device temporary directory
APK_SIZE=$((APK_SIZE + $(du -abc --apparent-size $i|grep -E "total$"|cut -f1)))
adb push $i $BASE_DIR_PHONE/SA/$DIR_OF_SPLIT_APKS/$i
done
#Output of command below: `Success: created install session [451298401]`, TODO: grab that install session
PM_INSTALL_SESSION=$(adb shell pm install-create -S $APK_SIZE) #<< apk + all the splits
#Set the index to 0
local APK_INDEX=0
#For each APKs
for i in $1/*.apk;do
#Get APK size
APK_SIZE=$(du -abc --apparent-size $i|grep -E "total$"|cut -f1)
#Write the apks to buffer
adb shell pm install-write -S $APK_SIZE $PM_SESSION $APK_INDEX $i
APK_INDEX+=1
done
#And initialize install
adb shell pm install-commit $PM_INSTALL_SESSION
}
########################
### Initialization ###
C_SUCCESS="[✓]"
C_INFO="[i]"
C_DEBUG="[d]"
C_WARN="[!]"
C_ERR="[✗]"
C_BLACK=''
C_DGRAY=''
C_RED=''
C_LRED=''
C_GREEN=''
C_LGREEN=''
C_BROWN=''
C_YELLOW=''
C_BLUE=''
C_LBLUE=''
C_PURPLE=''
C_LPURPLE=''
C_CYAN=''
C_LCYAN=''
C_LGRAY=''
C_WHITE=''
C_END=''
C_BOLD=''
print_version(){
echo "NJASD (Not Just A System Debloater) v$NJASD_VERSION, by mdp43140"
echo "Last changed: $NJASD_LAST_CHANGED"
echo "Release state: $NJASD_RELEASE_BRANCH"
echo "GitHub: https://github.com/mdp43140/NJASD_linux"
}
# argument processor...
for i in "$@";do
case "${i,,}" in
--color=*)
color_prompt="${i#*=}"
;;
--detect-root=*)
DETECT_ROOT_ALTER="${i#*=}"
;;
--bloatlist=*)
BLOATWARES_LIST_UNINSTALL_SYSTEM="${i#*=}"
;;
--host-type=*)
HOST_TYPE="${i#*=}"
;;
--keep-data)
KEEP_DATA=1
;;
-h|--help)
echo " "
echo " NJASD v$NJASD_VERSION, by mdp43140"
echo " Usage: ./njasd_linux.sh [options]"
echo "-------------------------"
echo " [no parameter] | Opens NJASD in \"command-line gui\" mode"
echo " -h --help | Display this help page"
echo " --color | Use color (possible values:auto,yes,no. default:$color_prompt)"
echo " --detect-root | Force to return custom root state (possible values:auto,yes,no. default:$DETECT_ROOT_ALTER)"
echo " --host-type | Force to return custom host type (possible values:auto,linux,android. default:$HOST_TYPE)"
echo " --bloatlist | Use custom bloatware list (WARNING: bloatware list CANNOT contain blank spaces,supports comment by adding # on the start)"
echo " --keep-data | Chose whether to clear data or not on uninstall/disabling process (i recommend doing this if you deal with other peoples phone you not own, just in case it removes something bad)"
echo " --no-header | Don't print header"
echo " -v --version | Print version"
echo ""
exit 0
;;
-v|--version)
print_version;exit 0
;;
*)
echo "Invalid argument. try --help to show help page,"
echo "or no arguments at all to open interactive clgui mode"
exit 1
;;
esac
done
#below are settings that are customizable using arguments
if [ "$color_prompt" = "auto" ];then
case "$TERM" in
xterm-color|*-256color)color_prompt=yes;;
*)color_prompt=no;;
esac
fi
if [ "$color_prompt" = "yes" ];then
readonly C_BLACK="\e[0;30m"
readonly C_DGRAY="\e[1;30m"
readonly C_RED="\e[0;31m"
readonly C_LRED="\e[1;31m"
readonly C_GREEN="\e[0;32m"
readonly C_LGREEN="\e[1;32m"
readonly C_BROWN="\e[0;33m"
readonly C_YELLOW="\e[1;33m"
readonly C_BLUE="\e[0;34m"
readonly C_LBLUE="\e[1;34m"
readonly C_PURPLE="\e[0;35m"
readonly C_LPURPLE="\e[1;35m"
readonly C_CYAN="\e[0;36m"
readonly C_LCYAN="\e[1;36m"
readonly C_LGRAY="\e[0;37m"
readonly C_WHITE="\e[1;37m"
readonly C_END="\e[0m"
readonly C_BOLD="\e[1m"
readonly C_SUCCESS="$C_LGRAY[$C_GREEN✓$C_LGRAY]$C_END"
readonly C_INFO="$C_LBLUE[$C_CYAN"i"$C_LBLUE]$C_END"
readonly C_DEBUG="$C_LGRAY[d]$C_END"
readonly C_WARN="$C_YELLOW[$C_BROWN!$C_YELLOW]$C_END"
readonly C_ERR="$C_BROWN[$C_LRED✗$C_BROWN]$C_END"
fi
# Hook the event that whenever NJASD:
# - quit in any way (except getting KILL signal), restore current text color to prevent kinda buggy color.
# - encountered error, show the error and encourage people to report on GitHub.
for i in {ABRT,QUIT,INT,EXIT,TERM,HUP,ERR};do trap "fxbgyclr \$? \$LINENO $i" $i;done
fxbgyclr(){ # ExitCode LineNo Sig
local ERRCODE="$1"
for i in {ABRT,QUIT,INT,EXIT,TERM,HUP,ERR};do trap - $i;done # remove trap events
[ "$3" -a "$3" = "ERR" -a "$ERRCODE" -ne 0 ] && (
echo -e "$C_INFO NJASD $C_LGRAY(Not Just A System Debloater)$C_END v$NJASD_VERSION, by mdp43140"
echo -e "$C_INFO Last changed: $NJASD_LAST_CHANGED"
echo -e "$C_INFO Release state: $NJASD_RELEASE_BRANCH"
[ "$2" -a "$2" -ne 1 ] && (echo -e "$C_ERR$C_YELLOW Error code $C_RED$ERRCODE$C_YELLOW. Something is wrong at line $C_RED$2$C_YELLOW: $C_GRAY$(sed -n $2p $0)$C_YELLOW") || (echo -e "$C_ERR$C_BROWN Unknown error: $ERRCODE")
echo -e " $C_INFO If you think this is a bug, Report it on GitHub:"
echo -e " https://github.com/mdp43140/NJASD/issues"
)
[ "$3" = "EXIT" -o "$3" = "QUIT" -o "$3" = "INT" ] && clear
echo -en "$C_END\e[0K\r"
tput cnorm
exit $ERRCODE
}
# Make cursor invisible, make sure ADB server is started, and show the TUI menu
clear
tput civis
TITLE="NJASD v$NJASD_VERSION (`[ "$HOST_TYPE" = "android" ] && echo Phone || echo PC`, `[ "$HOST_TYPE" = "android" ] && echo Android || echo Linux`)"
SEP="$C_LBLUE$(printf "=%.0s" `seq -s' ' $COLUMNS`)$C_END"
echo -e $SEP$C_LGREEN"\n $TITLE"\n$SEP
echo -e "$C_INFO "$C_LGREEN"Starting ADB Server (if not running)..."$C_END
adb start-server
if [ "$?" = "0" ];then echo -e "$C_SUCCESS Success"
elif [ "$?" = "127" ];then echo -e "$C_ERR ADB Not found or not installed, try to install it by running \"apt install android-sdk-platform-tools\"";ssleep 3
else echo -e "Unknown error occured with code $?";ssleep 3
fi
unset SEP
MAIN
######################