-
Notifications
You must be signed in to change notification settings - Fork 2
/
customize.sh
828 lines (667 loc) · 28.8 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
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# ================================================================================================
#!/system/bin/sh
SKIPUNZIP=1
# =============================================
# Work beginning
twrp() {
# Check if device is boot in TWRP/classic mode
touch "$TMPDIR/twrp_check.txt"
pstree | grep 'recovery' >> "$TMPDIR/twrp_check.txt"
if grep -q 'recovery' "$TMPDIR/twrp_check.txt"; then
BOOT_TWRP="1"
fi
}
pre_request() {
# =============================================
# Unzip everything
ui_print
ui_print "- Extracting module files"
[ ! -d "$MODPATH/system/bin" ] && mkdir -p "$MODPATH/system/bin"
#Store sqlite based on CPU Arc.
case $ARCH in
arm|ARM|Arm)
sqlite3=sqlite_arm
;;
arm64|ARM64|Arm64)
sqlite3=sqlite_arm64
;;
x86|X86)
sqlite3=sqlite_x86
;;
x64|X64)
sqlite3=sqlite_x64
;;
esac
unzip -o "$ZIPFILE" module.prop service.sh main.sh appslist.csv sepolicy.rule Detach.txt compatibility.txt "$sqlite3" sqlite.txt 'system/*' -x LICENSE .gitattributes README.md -d "$TMPDIR" 1>/dev/null
[ ! -e "$TMPDIR/system/bin/Detach" ] && unzip -o "$ZIPFILE" 'system/system/bin/Detach' "$TMPDIR/system/bin/Detach"
#Rename sqlite_* to default name
mv -f "$TMPDIR/$sqlite3" "$TMPDIR/sqlite"
#now copy it to it's location
cp -af "$TMPDIR/system/bin/Detach" "$MODPATH/system/bin/Detach"
#Write MODDIR=data/adb/modules/Detach
baseDir=$(echo $MODPATH | sed s/"_update"//)
sed -i -e 's~^MODDIR.*$~MODDIR='"${baseDir}"'~g' "$MODPATH/system/bin/Detach"
rm -f "$TMPDIR/LICENCE" && rm -f "$MODPATH/LICENCE"
rm -f "$TMPDIR/.gitattributes" && rm -f "$MODPATH/.gitattributes"
[ ! -e "$TMPDIR/sqlite" ] && abort 'sqlite no exist!'
set_perm_recursive $TMPDIR 0 0 0755 0644
chmod 0755 $TMPDIR/sqlite
chgrp 2000 $TMPDIR/sqlite
# =============================================
# Symbolic link for lowercase/UPPERCASE support in terminal
[ -d "$MODPATH/system/bin/" ] || mkdir -p "$MODPATH/system/bin/"
ln -sf Detach "$MODPATH/system/bin/detach"
Detach_version=$(grep 'version=.*' "$TMPDIR/module.prop" | sed 's/version=//')
ui_print " "
ui_print "- Detach $Detach_version"
ui_print "- By Rom, Sobuj53 @ xda-developers"
ui_print " "
ui_print "- Checking pre-requests"
sleep 1;
if [[ -e "$BBOX_PATH/disable" || -e "$BBOX_PATH/SKIP_MOUNT" || -e "$BBOX_PATH/update" ]]; then
ui_print "!- Make sure you have the 'Busybox for Android-NDK' installed on your device,"
ui_print "!- enabled and up-to-date in your Magisk Manager."
ui_print "!- It's a pre-request for the module."
fi
sleep 1;
ui_print "- Pre-request checks done"
sleep 1;
ui_print "- Prepare stuff"
SERVICESH=$TMPDIR/main.sh
CONF=$(ls /sdcard/Detach.txt || ls /sdcard/detach.txt || ls /sdcard/DETACH.txt || ls /storage/emulated/0/detach.txt || ls /storage/emulated/0/Detach.txt || ls /storage/emulated/0/DETACH.txt) 2>/dev/null;
SQLITE=$TMPDIR
if [ -d "/storage/emulated/0" ]
then
DetachFile=/storage/emulated/0/Detach.txt
else
DetachFile=/sdcard/Detach.txt
fi
if [ ! -e "$CONF" ]; then
ui_print ""
echo -e "!!! Your Detach.txt file does not exist !!!"
echo -e "!!! Copying original Detach.txt file to your storage root!!!"
echo -e "\nLocation: "$DetachFile"\n"
echo -e "Check your Detach.txt file, uncomment desired app and flash again."
cp -fr "$TMPDIR/Detach.txt" "$DetachFile"
ui_print ""
abort Fail
CONF_BAD=1
fi
if [ "$CONF" != "/sdcard/Detach.txt" -o "$CONF" != "/storage/emulated/0/Detach.txt" ]; then
mv -f "$CONF" "$DetachFile"
fi
# Check for bad syntax in the Detach.txt file due to wrong config in some BETAs versions
sed -n '5,41p' "$CONF" >> "$TMPDIR/SYN_CONF.txt"
grep -q '\.' "$TMPDIR/SYN_CONF.txt"; if [ $? -eq 0 ]; then
ui_print ""
echo -e "!- Your "$CONF" file contain error(s)"
echo -e "!!! Copying original Detach.txt file to your storage root!!!"
echo -e "\nLocation: "$DetachFile"\n"
echo -e "Check your Detach.txt file, uncomment desired app and flash again."
cp -fr "$TMPDIR/Detach.txt" "$DetachFile"
ui_print ""
CONF_BAD=1
fi
#check if new detach file is present or not
old_file=$(sed -n '5,41p;42q' "$CONF" | sed 's/^#//g')
new_file=$(sed -n '5,41p;42q' "$TMPDIR/Detach.txt" | sed 's/^#//g')
if [ "$old_file" != "$new_file" ]; then
ui_print ""
echo -e "!- Your "$CONF" file is old"
echo -e "!!! Copying orginal Detach.txt file to your storage root!!!"
echo -e "\nLocation: "$DetachFile"\n"
echo -e "Check your Detach.txt file, uncomment desired app and flash again."
cp -fr "$TMPDIR/Detach.txt" "$DetachFile"
ui_print ""
CONF_BAD=1
fi
#check if any detachable app is present in detach file, start from line 5
Last_line_no=$(sed '!d;=' "$CONF" | paste -d: - - | sed -n '$p' | cut -d: -f 1)
Contents=$(sed -n "5,$Last_line_no"p "$CONF" | grep -v '^[[:blank:]]*#'| grep '[A-Za-z0-9]')
if [ -z "${Contents}" ]; then
echo -e "- You've not uncommented any basic application"
echo -e " or"
echo -e "- written any custom application in your: "$CONF" file"
echo -e ""
echo -e "- Uncomment or write a custom package name..."
echo -e " then flash again."
echo -e "- Installation canceled..."
echo -e ""
abort Fail
CONF_BAD=1
fi
UP_SERVICESSH=$MODPATH/main.sh
if [ -e "$UP_SERVICESSH" ] && test ! "$CONF_BAD"; then
CTSERVICESH=$(awk 'END{print NR}' $UP_SERVICESSH)
if [ "$CTSERVICESH" -gt "32" ]; then
ui_print "- Cleanup file.."
sed -i -e '32,$d' "$SERVICESH"
fi
fi
rm -rf "$TMPDIR/Detach.txt" && rm -rf "$MODPATH/Detach.txt"
sleep 1;
test ! "$CONF_BAD" && ui_print "- Prepare done" || abort '- Wrong module setup'
sleep 1;
}
simple_mode_pre_request() {
ui_print "- Welcome in Simple mode :)"
ui_print ""
ui_print "- Checking your Detach.txt file"; sleep 1;
CONF=$(ls /sdcard/Detach.txt || ls /sdcard/detach.txt || ls /sdcard/DETACH.txt || ls /storage/emulated/0/detach.txt || ls /storage/emulated/0/Detach.txt || ls /storage/emulated/0/DETACH.txt) 2>/dev/null;
CONF_CHECK1=$(cat "$CONF" | grep 'Detach Market Apps Configuration')
CONF_CHECK2=$(cat "$CONF" | grep 'Remove comment (#) to detach an App.')
CONF_CHECK3=$(wc -l "$CONF" | sed "s| $CONF||")
if [ ! "$CONF_CHECK1" -o ! "$CONF_CHECK2" -o "$CONF_CHECK3" -lt "41" -a "$BOOT_TWRP" = 0 ]; then
ui_print "!- Make sure you have the original 'Detach.txt' file"; sleep 1;
ui_print "=> Download the original 'Detach.txt' file"
am start -a android.intent.action.VIEW -d https://raw.githubusercontent.com/sobuj53/Detach/master/Detach.txt
abort "!- Module setup canceled"
fi
}
# Check for automatic custom packages names to add
simple_mode_checks() {
ui_print "- Checks beginning"; sleep 1;
# Checks for custom packages names
# Check if line 46 of Detach.txt for custom packages is written or not
line_no=$(grep -n '# Other applications' $CONF | cut -d: -f 1)
line_no=$((line_no+1))
custom_check=$(tail -n +"$line_no" "$CONF" | grep '[a-zA-Z]')
# ------------------------------------------------------------------------------------
#not required anymore
# Check if there is too much spaces in custom packages from user input
#SPACES=$(sed -n '/^# Other applications/,$p' "$CONF" | sed 's/\# Other applications//' | grep '[a-zA-Z]')
#if [ $(echo "$SPACES" | grep '[:blanck:]\.') ] || [ $(echo "$SPACES" | grep '. ') ] || [ $(echo "$SPACES" | grep '[[:space:]][[:space:]]')]; then
# sed -i -e 's/ ././' -e 's/. /./' -e 's/ \+//' "$CONF" 2>/dev/null
#fi
# ------------------------------------------------------------------------------------
# Exist in detach.txt or custom packages
# Check if one of custom packages names exist in the detach.txt file (to avoid duplicates)
COMPARE_MAIN=$TMPDIR/COMPARE_MAIN.txt
COMPARE_CUSTOM=$TMPDIR/COMPARE_CUSTOM.txt
#get second last line number
match_line=$(sed '/# Other applications/q' "$CONF")
search=$(echo "$match_line" | awk 'NF { a=b ; b=$0 } END { print a }')
lines_no=$(grep -n "${search}" $CONF | cut -d: -f 1)
lines_no=$((line_no-lines_no-1))
for v in "$COMPARE_MAIN" "$COMPARE_CUSTOM"; do touch "$v" && chmod 0644 "$v"; done
cat "$CONF" | tail -n +"$lines_no" | sed '1,/\# Other applications/!d' | sed 's/# Other applications//' | grep -v -e "#.*" | grep '[A-Za-z0-9]' > "$COMPARE_MAIN"
sed -n '/# Other applications/,$p' "$CONF" | sed '1d' > "$COMPARE_CUSTOM"
# Check if there is/are duplicate(s) in the Common=Main apps
COMP_WRONG_M=$(awk 'NR==FNR{a[$1]++;next} a[$1] ' "$COMPARE_MAIN" "$COMPARE_CUSTOM")
# If there is an error in the custom apps
COMP_WRONG_C=$(awk 'NR==FNR{a[$1]++;next} a[$1] ' "$COMPARE_CUSTOM" "$COMPARE_MAIN")
if [ "$COMP_WRONG_M" ]; then
ui_print "- Be carreful! Theses following apps already exist in the common apps list"; sleep 1;
printf '%s\n' "$COMP_WRONG_C" | while IFS= read -r line
do ui_print "- $line"
done
CH_DUPLICATE=0
fi
if [ "$COMP_WRONG_C" ]; then
ui_print "- Be carreful! Theses following apps already exist in the custom apps list"; sleep 1;
printf '%s\n' "$COMP_WRONG_C" | while IFS= read -r line
do ui_print "- $line"
done
CH_DUPLICATE=0
fi
# ------------------------------------------------------------------------------------
ui_print "- Custom apps compatibility checks done."
sleep 1;
}
simple_mode_basic() {
ui_print "- Following basic apps will be hidden:"
sleep 1;
SERVICESH=$TMPDIR/main.sh
DETACH=$TMPDIR/basic_apps.txt
CONF=$(ls /sdcard/Detach.txt || ls /sdcard/detach.txt || ls /sdcard/DETACH.txt || ls /storage/emulated/0/detach.txt || ls /storage/emulated/0/Detach.txt || ls /storage/emulated/0/DETACH.txt) 2>/dev/null;
echo "" >> "$DETACH"
if grep -qo '^Gmail' $CONF; then
ui_print "- Gmail"
echo " # Gmail" >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.gm\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google App' $CONF; then
ui_print "- Google App"
echo ' # Google App' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.googlequicksearchbox\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google Plus' $CONF; then
ui_print "- Google Plus"
echo ' # Google Plus' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.plus\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Hangouts' $CONF; then
ui_print "- Hangouts"
echo ' # Hangouts' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.talk\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^YouTube' $CONF; then
ui_print "- YouTube"
echo ' # YouTube' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.youtube\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^YouTube Music' $CONF; then
ui_print "- YouTube Music"
echo ' # YouTube Music' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.youtube.music\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Gboard' $CONF; then
ui_print "- Gboard"
echo ' # Gboard' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.inputmethod.latin\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Contacts' $CONF; then
ui_print "- Contacts"
echo ' # Contacts' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.contacts\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Phone' $CONF; then
ui_print "- Phone"
echo ' # Phone' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.dialer\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Photos' $CONF; then
ui_print "- Photos"
echo ' # Photos' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.photos\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Clock' $CONF; then
ui_print "- Clock"
echo ' # Clock' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.deskclock\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Camera' $CONF; then
ui_print "- Camera"
echo ' # Camera' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.GoogleCamera\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Inbox' $CONF; then
ui_print "- Inbox"
echo ' # Inbox' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.inbox\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Duo' $CONF; then
ui_print "- Duo"
echo ' # Duo' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.tachyon\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Dropbox' $CONF; then
ui_print "- Dropbox"
echo ' # Dropbox' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.dropbox.android\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^PushBullet' $CONF; then
ui_print "- PushBullet"
echo ' # PushBullet' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.pushbullet.android\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Calendar' $CONF; then
ui_print "- Calendar"
echo ' # Calendar' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.calendar\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Keep' $CONF; then
ui_print "- Keep"
echo ' # Keep' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.keep\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Telegram' $CONF; then
ui_print "- Telegram"
echo ' # Telegram' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'org.telegram.messenger\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Swiftkey' $CONF; then
ui_print "- Swiftkey"
echo ' # Swiftkey' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.touchtype.swiftkey\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Translate' $CONF; then
ui_print "- Translate"
echo ' # Translate' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.translate\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Facebook' $CONF; then
ui_print "- Facebook"
echo ' # Facebook' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.facebook.katana\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Pandora' $CONF; then
ui_print "- Pandora"
echo ' # Pandora' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.pandora.android\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Twitter' $CONF; then
ui_print "- Twitter"
echo ' # Twitter' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.twitter.android\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Slack' $CONF; then
ui_print "- Slack"
echo ' # Slack' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.Slack\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Mega' $CONF; then
ui_print "- Mega"
echo ' ' >> $DETACH
echo ' # Mega' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'mega.privacy.android.app\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^WhatsApp' $CONF; then
ui_print "- WhatsApp"
echo ' # WhatsApp' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.whatsapp\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Voice' $CONF; then
ui_print "- Voice"
echo ' # Voice' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.googlevoice\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Drive' $CONF; then
ui_print "- Drive"
echo ' # Drive' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.docs\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Netflix' $CONF; then
ui_print "- Netflix"
echo ' # Netflix' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.netflix.mediaclient\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Pixel Launcher' $CONF; then
ui_print "- Pixel Launcher"
echo ' # Pixel Launcher' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.nexuslauncher\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Wallpapers' $CONF; then
ui_print "- Wallpapers"
echo ' # Wallpapers' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.wallpaper\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Capture' $CONF; then
ui_print "- Capture"
echo ' # Capture' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.gopro.smarty\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google Connectivity Services' $CONF; then
ui_print "- Google Connectivity Services"
echo ' # Google Connectivity Services' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.apps.gcs\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google VR Services' $CONF; then
ui_print "- Google VR Services"
echo ' # Google VR Services' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.vr.vrcore\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google Play Services' $CONF; then
ui_print "- Google Play Services"
echo ' # Google Play Services' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.gms\''";' >> $DETACH
echo '' >> $DETACH
fi
if grep -qo '^Google Carrier Services' $CONF; then
ui_print "- Google Carrier Services"
echo ' # Google Carrier Services' >> $DETACH
echo ' $SQLITE/sqlite $PLAY_DB_DIR/library.db "UPDATE ownership SET library_id = '\'u-wl\' where doc_id = \'com.google.android.ims\''";' >> $DETACH
fi
cat "$DETACH" >> "$SERVICESH"
echo " " >> "$SERVICESH"
# rm -f $DETACH
sleep 1;
ui_print "-Hiding of basic applications is done.";sleep 1;
}
nothing_to_add() {
ui_print "- You have not uncommented any basic application"
ui_print " or"
ui_print "- written any custom application in your /sdcard/Detach.txt file."
ui_print ""
ui_print "- At least uncomment one or write a custom package name..."
ui_print ""
ui_print "- Installation canceled..."
}
direct_custom_install() {
ui_print ""
ui_print "- Following custom apps will be hidden:"
sleep 1;
#FINALCUST=$TMPDIR/FINALCUST.txt
SQSH=$TMPDIR/sqlite.txt
SQSHBAK=$TMPDIR/sqlite.bak
SERVICESH=$TMPDIR/main.sh
echo -e "# Custom Packages" >> "$SERVICESH"
cp -af "$SQSH" "$SQSHBAK"
echo "$CHECK_PACKAGES" >> "$TMPDIR/CHECK_PACKAGES.txt"
FINAL_PACKS=$(awk '{ print }' "$TMPDIR/CHECK_PACKAGES.txt")
#SHOW_PACKS=$(echo "$FINAL_PACKS" | tr -d '\r')
#printf '%s\n' "$SHOW_PACKS" | while IFS= read -r line
# do ui_print "- $line"
#done
printf '%s\n' "$FINAL_PACKS" | while IFS= read -r line
do
app_name=" \$SQLITE/sqlite \$PLAY_DB_DIR/library.db \"UPDATE ownership SET library_id = 'u-wl' where doc_id = '$line'\";"
if grep -qF -- "$app_name" "$SERVICESH"; then
#already available
ui_print ""
echo -e "Package name: "$line" already added!!"
echo -e "Skipping..."
ui_print ""
else
# add if not found
echo "$app_name" >> "$SERVICESH"
echo -e "\n" >> "$SERVICESH"
ui_print "- $line"
fi
done
#cat "$FINALCUST" >> "$SERVICESH"
ui_print "- Custom apps has been added successfully"
sleep 1;
}
simple_mode_no_custom() {
ui_print "=> No custom app added"
sleep 2;
}
instant_detach() {
ui_print ""
ui_print "=========================="
ui_print "- Detach work in progress"
ui_print "..."; sleep 1;
SERVICESH=$TMPDIR/main.sh
instant_run=$TMPDIR/instant_run.sh
instant_run_two=$TMPDIR/instant_run_two.sh
test -e "$instant_run" || touch "$instant_run"
chmod 0777 "$instant_run" && chmod +x "$instant_run"
PS_DATA_PATH=/data/data/com.android.vending/databases/library.db
# Multiple Play Store accounts compatibility
ps_accounts=$("$TMPDIR/sqlite" $PS_DATA_PATH "SELECT account FROM ownership" | sort -u | wc -l)
cat /dev/null > "$instant_run"
echo -e "PLAY_DB_DIR=/data/data/com.android.vending/databases\nSQLITE=${TMPDIR}\n\n\nam force-stop com.android.vending\n\ncd \$SQLITE\nsleep 1\n" >> "$instant_run"
sed -n '32,$p' "$SERVICESH" | sed -n '/^[[:space:]]*$SQLITE\/sqlite.*/p' "$SERVICESH" >> "$instant_run"
echo -e "\n" >> "$instant_run"
test -e "$TMPDIR/first_detach_result.txt" || touch "$TMPDIR/first_detach_result.txt"
chmod 0777 "$TMPDIR/first_detach_result.txt"
sh "$instant_run" > "$TMPDIR/first_detach_result.txt" 2>&1
if [ "$ps_accounts" -gt "1" ]; then
test -e "$instant_run_two" || touch "$instant_run_two"
chmod 0777 "$instant_run_two" && chmod +x "$instant_run_two"
echo -e "PLAY_DB_DIR=/data/data/com.android.vending/databases\nSQLITE=${TMPDIR}\n\n\nam force-stop com.android.vending\n\ncd \$SQLITE\nsleep 1\n" > "$instant_run_two"
am force-stop com.android.vending
for i in {1..${ps_accounts_final}}; do sed -n '/^[[:space:]]*$SQLITE\/sqlite.*/p' "$instant_run" >> "$instant_run_two"; done
echo -e '\n' >> "$instant_run_two"
sh "$instant_run_two"
fi
wrong_result=$(echo "Error: UNIQUE constraint failed: ownership.account,")
if grep -q "$wrong_result" "$TMPDIR/first_detach_result.txt"; then
ui_print " "
ui_print "Database file corrupted"
ui_print "Database file need to be fixed, so please wait some little seconds."
ui_print "..."; sleep 1;
ACTAPPS=$TMPDIR/actapps.txt
ACTAPPSBCK=$TMPDIR/actapps.bak
FINAL=$TMPDIR/final.sh
for o in "$ACTAPPS" "$ACTAPPSBCK" "$FINAL"; do touch "$o" && cat /dev/null > "$o" && chmod 0644 "$o"; done
PLAY_DB_DIR=/data/data/com.android.vending/databases
sed -n '/^[[:space:]]*$SQLITE\/sqlite.*/p' "$SERVICESH" > "$ACTAPPS"
sed -i -e "s/\$SQLITE\/sqlite \$PLAY_DB_DIR\/library.db \"UPDATE ownership SET library_id = 'u-wl' where doc_id = '//" -i -e "s/'\";//" "$ACTAPPS"
sed -i -e 's/[ \t]*//' "$ACTAPPS"
sed -i -e 's/[[:blank:]]*//' "$ACTAPPS"
cp -f "$ACTAPPS" "$ACTAPPSBCK"
var_ACTAPPS=$(awk '{ print }' "$ACTAPPSBCK")
am force-stop com.android.vending
FIRST_PCK_NAME=$(head -n 1 "$ACTAPPS")
PRESENT_DIR="$( cd "$( dirname "$0" )" && pwd )"
SQL_ENTRY_TEST=$(cd $TMPDIR && $SQLITE/sqlite $PLAY_DB_DIR/library.db "SELECT * FROM ownership WHERE doc_id = '${FIRST_PCK_NAME}' AND library_id='3'" | wc -l)
cd "$PRESENT_DIR"
ZERO=0
chmod +x "$FINAL"
echo -e "PS_DATA_PATH=\/data\/data\/com.android.vending\/databases\/library.db\n\ncd $TMPDIR\n\n" >> "$FINAL"
if [ "$SQL_ENTRY_TEST" -eq 1 ]; then
printf '%s\n' "$var_ACTAPPS" | while IFS= read -r line
do echo -e "$TMPDIR/sqlite $PLAY_DB_DIR/library.db \"DELETE FROM ownership WHERE doc_id = '$line' AND library_id = '3'\";\n" >> "$FINAL"
done
cd "$TMPDIR"
chmod +x "$FINAL"
sh "$FINAL"
cd "$PRESENT_DIR"
else
echo -e "\ncd $TMPDIR\n\n" >> "$FINAL"
while [ "$ZERO" -le "$SQL_ENTRY_TEST" ]; do
printf '%s\n' "$var_ACTAPPS" | while IFS= read -r line
do echo -e "$TMPDIR/sqlite $PLAY_DB_DIR/library.db \"DELETE FROM ownership WHERE doc_id = '$line' AND library_id = '3'\";\n" >> "$FINAL"
done
SQL_ENTRY_TEST=$(($SQL_ENTRY_TEST - 1))
done
cd "$TMPDIR"
chmod +x "$FINAL"
sh "$FINAL"
cd "$PRESENT_DIR"
fi
for f in "$ACTAPPS" "$ACTAPPSBCK"; do rm -f "$f"; done
ui_print "Database file fixed."
ui_print "..."; sleep 1;
fi
ui_print "- Detach done"
ui_print "=========================="
ui_print ""
sleep 1;
}
# ================================================================================================
complete_script() {
# =============================================
ui_print "- Extracting module files"
for i in "$TMPDIR/compatibility.txt" "$TMPDIR/sqlite" "$TMPDIR/service.sh" "$TMPDIR/appslist.csv" "$TMPDIR/sepolicy.rule" "$TMPDIR/sqlite.txt" "$TMPDIR/module.prop"; do cp -af "$i" "$MODPATH/"; done
# =============================================
# Necessary special permissions
SERVICESH=$TMPDIR/main.sh
set_perm_recursive $MODPATH 0 0 0755 0644
set_perm_recursive $TMPDIR 0 0 0755 0644
set_perm $MODPATH/system/bin/Detach 0 0 0777
chmod 0755 $TMPDIR/sqlite
chgrp 2000 $TMPDIR/sqlite
chmod 0755 "$MODPATH/sepolicy.rule" && chmod +x "$MODPATH/sepolicy.rule"
chmod 0755 "$MODPATH/service.sh" && chmod +x "$MODPATH/service.sh"
chmod 0755 $MODPATH/sqlite
chgrp 2000 $MODPATH/sqlite
ui_print "- Finish the script file..";sleep 1;
cat "$TMPDIR/compatibility.txt" >> "$SERVICESH"
cp -af "$SERVICESH" "$MODPATH/main.sh"
chmod 0755 "$MODPATH/main.sh" && chmod +x "$MODPATH/main.sh"
ui_print "- Boot script file is now finished."
ui_print "- Reboot your device before using the terminal commands."
ui_print "=> Just reboot now (:"
sleep 1;
}
# ================================================================================================
# ================================================================================================
# ================================================================================================
# Detach Module setup
# Rom @ xda-devlopers
twrp
pre_request
test "$CONF_BAD" && exit
SIMPLE=/sdcard/simple_mode.txt
CONF=$(ls /sdcard/Detach.txt || ls /sdcard/detach.txt || ls /sdcard/DETACH.txt || ls /storage/emulated/0/detach.txt || ls /storage/emulated/0/Detach.txt || ls /storage/emulated/0/DETACH.txt) 2>/dev/null;
test -e "$SIMPLE" && simple_mode_pre_request
# ----------------------------------
#get # Other applications line number
line_no=$(grep -n '# Other applications' $CONF | cut -d: -f 1)
#how many line before the Other applications line
match_line=$(sed '/# Other applications/q' "$CONF")
search=$(echo "$match_line" | awk 'NF { a=b ; b=$0 } END { print a }')
lines_no=$(grep -n "${search}" $CONF | cut -d: -f 1)
lines_no=$((line_no-lines_no))
# Check for basics and/or customs
CHECK=$(cat "$CONF" | tail -n +"$lines_no" | sed -n '/# Other applications/q;p' | grep -v -e "#.*" | grep '[A-Za-z0-9]')
# Check if basics apps in Detach.txt file are ready or not
test "$CONF_BAD" && abort "!- WARNING: You basic applications list contain '.' symbol, delete them and try again."
CHECK_OTHER=$(sed -n "$line_no"p "$CONF")
RIGHT_OTHER="# Other applications"
if [ "$CHECK_OTHER" != "$RIGHT_OTHER" ]; then
unset CHECK_OTHER
fi
line_no=$((line_no+1))
CHECK_PACKAGES=$(cat "$CONF" | tail -n +"$line_no" | grep -v '^#' | grep '[0-9A-Za-z]')
# Checks for Detach.txt file
simple_mode_checks
[[ "$CH_DUPLICATE" == "0" ]] && abort
# For common app(s) ONLY
[ "$CHECK" ] && simple_mode_basic
# ----------------------------------
# If NO basic applications and NO custom packages names
[ -e "$SIMPLE" -a ! "$CHECK" -a ! "$CHECK_PACKAGES" ] && nothing_to_add && exit
# Simple mode - if '# Other applications' is write in Detach.txt WITHOUT custom packages names
if [ -e "$SIMPLE" -a "$CHECK_OTHER" -a ! "$CHECK_PACKAGES" ]; then
ui_print "!- Warning:"
ui_print "!- You have enable custom packages application"
ui_print "!- in your /sdcard/Detach.txt file".
ui_print "!- But you didn't write any custom packages name after that."
ui_print "!- We are going to ignore it for this time."
fi
# Simple mode - if '# Other applications' is write in Detach.txt WITH custom packages names
[ -e "$SIMPLE" -a "$CHECK_OTHER" -a "$CHECK_PACKAGES" ] && direct_custom_install
# ----------------------------------
# If '# Other applications' is write in Detach.txt with custom packages names
[ ! -e "$SIMPLE" -a "$CHECK_OTHER" -a "$CHECK_PACKAGES" ] && direct_custom_install
# ----------------------------------
# NO '# Other applications' and NO custom packages names write in Detach.txt
[ -z "$CHECK_OTHER" -a -z "$CHECK_PACKAGES" ] && simple_mode_no_custom
# ----------------------------------
# Finishing the setup
# ----------------------------------
if [ "$(grep -voq 'recovery' "$TMPDIR/twrp_check.txt")" != "recovery" ]; then
instant_detach
fi
complete_script
ui_print "- Module setup done"
ui_print " "