-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbda
executable file
·348 lines (327 loc) · 9.99 KB
/
bda
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
#!/bin/bash
# ===== Variables
PROJECT_NAME="Debloat Android No Root"
VERSION="$PROJECT_NAME v2.0"
DESCRIPTION="Debloat non rooted Android devices"
BASE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
THIS_SCRIPT=$BASE/$(basename $0)
CONFIG_DIR=$BASE/configs
ADB=$CONFIG_DIR/adb
DESKTOP_SHORTCUT=/home/$(whoami)/.local/share/applications/debloat-android.desktop
ICON=$CONFIG_DIR/icon.svg
UPDATE_URL="https://techstop.github.io/debloat-android-no-root/"
REPO_URL="https://github.com/GameTheory-/debloat-android-no-root"
# ===== ANSI color code variables
BOLD="\e[1m"
CYAN="\e[96m"
BLUEBG="\e[104m"
GREEN="\e[0;32m"
HRED="\e[0;91m"
WHITE="\e[97m"
NC="\e[0m"
EXPND="\e[K"
# ===== make sure adb has exec permission
if [[ ! -x "$ADB" ]]; then
chmod +x "$ADB"
fi
# ===== for centering strings
ECHO_CENTER() {
printf "%*s\n" $((( ${#1} + $(tput cols) ) / 2)) "$1"
}
# ===== ECHO_CENTER variables go here
NAME_TXT=$(ECHO_CENTER "$PROJECT_NAME")
# ===== continue
PRESS_ENTER() {
echo ""
echo -n -e " ${GREEN}Press Enter to continue${NC} "
read
clear
}
# ===== incorrect selection
INCORRECT_SELECTION() {
echo -e "${HRED}Incorrect selection! Try again.${NC}"
}
# ===== PS3 variable
PS3_VAR() {
echo ""
echo "Enter a selection: "
}
# ===== disable applications
DISABLE_PACKAGES() {
echo -e "${GREEN}Please Wait...${NC}"
echo ""
DISABLE=$(echo -e "${GREEN}${BOLD}Disable Applications${NC}")
QUIT=$(echo -e "${HRED}${BOLD}Quit${NC}")
PS3="$(PS3_VAR)"
readarray -t OPTIONS < <("$ADB" shell pm list packages -f -s | grep -oP "(?<=package:).*" | sed 's?^\(.*\)=?\1 = ?')
select OPT in "${OPTIONS[@]}" "$DISABLE" "$QUIT"; do
if (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); then
while (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); do
LIST_PACKS=$(grep -oP "(?<== ).*" <<< $OPT)
echo -e "${GREEN}$LIST_PACKS${NC}"
PACK_LIST+=("$LIST_PACKS")
break
done
elif (( REPLY == 1 + ${#OPTIONS[@]} )); then
clear
echo -e "${GREEN}Please Wait...${NC}"
echo ""
for plist in ${PACK_LIST[@]}; do
read ADB_VAR < <("$ADB" shell pm disable-user --user 0 "$plist")
done
if [[ "$ADB_VAR" == *disabled-user* ]]; then
echo -e "${GREEN}Done!${NC}"
else
echo -e "${HRED}Could not disable 1 or more of your selected apps.${NC}"
fi
break
elif (( REPLY == 2 + ${#OPTIONS[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
else
echo -e "${HRED}Incorrect selection! Try again.${NC}"
fi
done
unset PACK_LIST
}
# ===== re-enable applications
REENABLE_PACKAGES() {
echo -e "${GREEN}Please Wait...${NC}"
echo ""
REENABLE=$(echo -e "${GREEN}${BOLD}Re-enable Applications${NC}")
QUIT=$(echo -e "${HRED}${BOLD}Quit${NC}")
PS3="$(PS3_VAR)"
readarray -t OPTIONS < <("$ADB" shell pm list packages -d | grep -oP "(?<=package:).*")
if [ ! -z $OPTIONS ]; then
select OPT in "${OPTIONS[@]}" "$REENABLE" "$QUIT"; do
if (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); then
while (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); do
echo -e "${GREEN}$OPT${NC}"
PACK_LIST+=("$OPT")
break
done
elif (( REPLY == 1 + ${#OPTIONS[@]} )); then
clear
echo -e "${GREEN}Please Wait...${NC}"
echo ""
for plist in ${PACK_LIST[@]}; do
read ADB_VAR < <("$ADB" shell pm enable "$plist")
done
if [[ "$ADB_VAR" == *enabled* ]]; then
echo -e "${GREEN}Done!${NC}"
else
echo -e "${HRED}Could not re-enable 1 or more of your selected apps.${NC}"
fi
break
elif (( REPLY == 2 + ${#OPTIONS[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
else
echo -e "${HRED}Incorrect selection! Try again.${NC}"
fi
done
unset PACK_LIST
else
echo -e "${HRED}There are no previously disabled apps to re-enable.${NC}"
fi
}
# ===== uninstall applications
UNINSTALL_PACKAGES() {
echo -e "${GREEN}Please Wait...${NC}"
echo ""
UNINSTALL=$(echo -e "${GREEN}${BOLD}Uninstall Applications${NC}")
QUIT=$(echo -e "${HRED}${BOLD}Quit${NC}")
PS3="$(PS3_VAR)"
readarray -t OPTIONS < <("$ADB" shell pm list packages -f -s | grep -oP "(?<=package:).*" | sed 's?^\(.*\)=?\1 = ?')
select OPT in "${OPTIONS[@]}" "$UNINSTALL" "$QUIT"; do
if (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); then
while (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); do
LIST_PACKS=$(grep -oP "(?<== ).*" <<< $OPT)
echo -e "${GREEN}$LIST_PACKS${NC}"
PACK_LIST+=("$LIST_PACKS")
break
done
elif (( REPLY == 1 + ${#OPTIONS[@]} )); then
clear
echo -e "${GREEN}Please Wait...${NC}"
echo ""
for plist in ${PACK_LIST[@]}; do
read ADB_VAR < <("$ADB" shell pm uninstall --user 0 "$plist")
done
if [[ "$ADB_VAR" == *Success* ]]; then
echo -e "${GREEN}Done!${NC}"
else
echo -e "${HRED}Could not uninstall 1 or more of your selected apps.${NC}"
fi
break
elif (( REPLY == 2 + ${#OPTIONS[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
else
echo -e "${HRED}Incorrect selection! Try again.${NC}"
fi
done
unset PACK_LIST
}
# ===== re-install applications
REINSTALL_PACKAGES() {
echo -e "${GREEN}Please Wait...${NC}"
echo ""
REINSTALL=$(echo -e "${GREEN}${BOLD}Re-install Applications${NC}")
QUIT=$(echo -e "${HRED}${BOLD}Quit${NC}")
PS3="$(PS3_VAR)"
readarray -t OPTIONS < <(diff <("$ADB" shell pm list packages) <("$ADB" shell pm list packages -u) | grep -oP '(?<=package:).*')
if [ ! -z $OPTIONS ]; then
select OPT in "${OPTIONS[@]}" "$REINSTALL" "$QUIT"; do
if (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); then
while (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )); do
echo -e "${GREEN}$OPT${NC}"
PACK_LIST+=("$OPT")
break
done
elif (( REPLY == 1 + ${#OPTIONS[@]} )); then
clear
echo -e "${GREEN}Please Wait...${NC}"
echo ""
for plist in ${PACK_LIST[@]}; do
packs=$("$ADB" shell pm dump "$plist" | grep -oP '(?<=path: ).*')
read ADB_VAR < <("$ADB" shell pm install -r --user 0 "$packs")
done
if [[ "$ADB_VAR" == *Success* ]]; then
echo -e "${GREEN}Done!${NC}"
else
echo -e "${HRED}Could not re-install 1 or more of your selected apps.${NC}"
fi
break
elif (( REPLY == 2 + ${#OPTIONS[@]} )); then
clear
echo -e "${HRED}Aborted!${NC}"
break
else
echo -e "${HRED}Incorrect selection! Try again.${NC}"
fi
done
unset PACK_LIST
else
echo -e "${HRED}There are no previously un-installed apps to re-install.${NC}"
fi
}
# ===== get device properties/info
DEVICE_INFO() {
var=$("$ADB" shell getprop)
echo -e "${GREEN}${BOLD}$var${NC}"
}
# ===== install android udev rules
UDEV_RULES() {
echo -e " ${GREEN}${BOLD}Android Udev Rules${NC}"
echo -e "${GREEN}If your device is not being recognized when plugged to"
echo -e "usb, then you may be missing the '51-android.rules' file in"
echo -e "/etc/udev/rules.d directory.${NC}"
echo ""
echo "Install 51-android.rules?"
read -ep "(Y/n) $ " Y_UDEV
echo ""
if [[ -z "$Y_UDEV" || "$Y_UDEV" =~ ^([yY|[yY][eE][sS]]) ]]; then
sudo cp -f "$CONFIG_DIR"/51-android.rules /etc/udev/rules.d/51-android.rules
sudo chmod a+r /etc/udev/rules.d/51-android.rules
if [ $(cat /etc/os-release | grep -oP '(?<=ID_LIKE=).*') = debian ]; then
sudo service udev restart
else
sudo udevadm control --reload-rules && sudo udevadm trigger
fi
if [[ -f /etc/udev/rules.d/51-android.rules ]]; then
echo -e "${GREEN}Done!${NC}"
else
echo -e "${HRED}Aborted! Could not install. Try manual installation.${NC}"
fi
else
echo -e "${HRED}Aborted!${NC}"
fi
}
# ===== check for update
VISIT_ITG() {
echo ""
echo -e "${GREEN}Visit website?${NC}"
read -ep "(Y/n) $ " VISIT
if [[ -z "$VISIT" || "$VISIT" =~ ^([yY]|[yY][eE][sS]) ]]; then
if command -v xdg-open > /dev/null; then
xdg-open "$UPDATE_URL" > /dev/null 2>&1
elif command -v gnome-open > /dev/null; then
gnome-open "$UPDATE_URL" > /dev/null 2>&1
fi
fi
clear
}
CHECK_FOR_UPDATE() {
echo -e "${GREEN}Please wait...${NC}"
echo ""
SITE_VERSION=$(wget -q "$REPO_URL" -O - | grep -m 1 -o -P '.{0,0}Debloat Android No Root v.{0,3}')
clear
if [ "$VERSION" = "$SITE_VERSION" ]; then
echo -e "${GREEN}$VERSION"
echo ""
echo "No update available. Check again later."
echo ""
echo -e "For more info visit:${NC}"
echo -e "${CYAN}$UPDATE_URL${NC}"
VISIT_ITG
else
echo -e "${GREEN}Update available!"
echo ""
echo -e "To download the latest version go to:${NC}"
echo -e "${CYAN}$UPDATE_URL${NC}"
VISIT_ITG
fi
}
# ===== create desktop shortcut
DESKTOP_SHORTCUT() {
echo "[Desktop Entry]" > "$DESKTOP_SHORTCUT"
echo "Type=Application" >> "$DESKTOP_SHORTCUT"
echo "Name=$PROJECT_NAME" >> "$DESKTOP_SHORTCUT"
echo "Comment=$DESCRIPTION" >> "$DESKTOP_SHORTCUT"
echo "Exec=\"$THIS_SCRIPT\"" >> "$DESKTOP_SHORTCUT"
echo "Icon=$ICON" >> "$DESKTOP_SHORTCUT"
echo "Categories=Development;" >> "$DESKTOP_SHORTCUT"
echo "Terminal=true" >> "$DESKTOP_SHORTCUT"
if [[ -f "$DESKTOP_SHORTCUT" ]]; then
echo -e "${GREEN}Desktop entry added for ${CYAN}${BOLD}$(whoami)${NC}"
echo -e "${GREEN}Check your apps menu for the shortcut.${NC}"
else
echo -e "${HRED}oops! Shortcut failed. Please try again.${NC}"
fi
}
# ===== menu
SELECTION=
until [ "$SELECTION" = "0" ]; do
clear
echo -e "${BLUEBG}${EXPND}${WHITE}${BOLD}$NAME_TXT${NC}"
echo ""
echo " 1 - Disable Apps"
echo " 2 - Re-enable Apps"
echo " 3 - Uninstall Apps"
echo " 4 - Re-install Apps"
echo " 5 - Device Info"
echo " 6 - Install 51-android.rules"
echo " 7 - Check For Updates"
echo " 00 - Add Desktop Shortcut"
echo " 0 - Exit"
echo ""
echo -n " Enter selection: "
read SELECTION
echo ""
case $SELECTION in
1 ) clear ; DISABLE_PACKAGES ; PRESS_ENTER ;;
2 ) clear ; REENABLE_PACKAGES ; PRESS_ENTER ;;
3 ) clear ; UNINSTALL_PACKAGES ; PRESS_ENTER ;;
4 ) clear ; REINSTALL_PACKAGES ; PRESS_ENTER ;;
5 ) clear ; DEVICE_INFO ; PRESS_ENTER ;;
6 ) clear ; UDEV_RULES ; PRESS_ENTER ;;
7 ) clear ; CHECK_FOR_UPDATE ; PRESS_ENTER ;;
00 ) clear ; DESKTOP_SHORTCUT ; PRESS_ENTER ;;
0 ) clear ; exit ;;
* ) clear ; INCORRECT_SELECTION ; PRESS_ENTER ;;
esac
done