forked from Map-A-Droid/MAD-ATV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
42mad
371 lines (355 loc) · 15 KB
/
42mad
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
#!/system/bin/sh
#This is for update_mad version
uver="3.5"
#This is for pingreboot version
pver="2.0"
#This is for nfs install script
nver="1.2"
# mad rom version
madver="0.2"
#magisk version / url
magisk_ver="20.3"
msum="959e46971c2eb500b91a053b2f1c1a8c"
url_magisk="https://github.com/Map-A-Droid/MAD-ATV/raw/master/Magisk-v20.3.zip"
url_gapps="https://netcologne.dl.sourceforge.net/project/opengapps/arm64/20200715/open_gapps-arm64-7.1-pico-20200715.zip"
rgcconf="/data/data/de.grennith.rgc.remotegpscontroller/shared_prefs/de.grennith.rgc.remotegpscontroller_preferences.xml"
pdconf="/data/data/com.mad.pogodroid/shared_prefs/com.mad.pogodroid_preferences.xml"
requires_autoconf=1
reboot_required=0
cachereboot=0
download(){
# $1 = url
# $2 = local path
# lets see that curl exits successfully
until /system/bin/curl -s -k -L -A "$useragent" -o "$2" "$1" ;do
sleep 15
done
}
log_msg() {
# $1 = severity
# $2 = msg
echo "$msg"
if [[ "$session_id" ]] ;then
/system/bin/curl -s -k -L -d "$1,$2" --user "$pdauth" -H 'Content-Type: text/html' "${pdserver}/autoconfig/${session_id}/log"
fi
}
autoconf_google_signin() {
until [[ -f /sdcard/google-account ]] ;do
/system/bin/curl -s -k -L -o /sdcard/google-account --user "$pdauth" -H "origin: $origin" "${pdserver}/autoconfig/${session_id}/google"
sleep 10
done
if [[ -f /sdcard/google-account ]] ;then
am start -a android.settings.ADD_ACCOUNT_SETTINGS
sleep 40
input keyevent 20
input keyevent 20
sleep 5
input text $(sed -n 1p /sdcard/google-account)
sleep 5
input keyevent 66
sleep 5
input keyevent 20
sleep 5
input text $(sed -n 2p /sdcard/google-account)
sleep 5
input keyevent 66
sleep 5
i=0
while (( "$i" < 9 )); do
input keyevent 20
i=$((i+1))
sleep 1
done
input keyevent 66
sleep 5
i=0
while (( "$i" < 3 )); do
input keyevent 20
i=$((i+1))
sleep 1
done
input keyevent 66
fi
}
execute_autoupdates(){
if ! grep -q "version $uver" /system/bin/update_mad.sh; then
download https://raw.githubusercontent.com/Map-A-Droid/MAD-ATV/master/update_mad.sh /system/bin/update_mad.sh
chmod +x /system/bin/update_mad.sh
fi
if ! grep -q "version $pver" /system/bin/pingreboot.sh; then
download https://raw.githubusercontent.com/Map-A-Droid/MAD-ATV/master/pingreboot.sh /system/bin/pingreboot.sh
chmod +x /system/bin/pingreboot.sh
fi
#if ! grep -q "version $nver" /system/bin/nfs_install.sh; then
# download https://raw.githubusercontent.com/Map-A-Droid/MAD-ATV/master/nfs_install.sh /system/bin/nfs_install.sh
# chmod +x /system/bin/nfs_install.sh
#fi
! [[ -f /sdcard/disableautopogoupdate ]] && log_msg 2 "Downloading PoGo" && sh -x /system/bin/update_mad.sh -p
! [[ -f /sdcard/disableautopogodroidupdate ]] && log_msg 2 "Downloading PogoDroid" && sh -x /system/bin/update_mad.sh -wd
! [[ -f /sdcard/disableautorgcupdate ]] && log_msg 2 "Downloading RGC" && sh -x /system/bin/update_mad.sh -wr
}
#don't add it for execution as long as no one else is having issues with wrong language
set_android_language() {
if ! [[ "$(getprop persist.sys.locale)" == "en-US" ]] ;then
setprop persist.sys.locale en-US; setprop ctl.restart zygote
fi
}
set_mac(){
echo 1 > /sys/class/unifykeys/lock
echo mac > /sys/class/unifykeys/name
echo "$1" >/sys/class/unifykeys/write
cat /sys/class/unifykeys/read
echo 0 > /sys/class/unifykeys/lock
}
checkmac(){
if [[ "$(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" -H "origin: $origin" "${pdserver}/autoconfig/mymac")" == "200" ]] ;then
all_macs="$(/system/bin/curl -s -k -L --user "$pdauth" -H "origin: $origin" "${pdserver}/autoconfig/mymac")"
interface="$(sed -n 1p <<< "$all_macs")"
mac="$(sed -n 2p <<< "$all_macs")"
if ifconfig|grep -A5 wlan0|grep -q inet ;then
current_mac=$(ifconfig wlan0|awk '/HWaddr/{print $5}')
elif ifconfig|grep -A5 eth0|grep -q inet ;then
current_mac=$(ifconfig eth0|awk '/HWaddr/{print $5}')
echo "MAD-assigned MAC: \"$mac\""
echo "Current MAC: \"$current_mac\""
if [[ "$mac" == "" ]] ;then
# use our current mac for now on
set_mac "$current_mac"
/system/bin/curl -s -k -L --user "$pdauth" -H 'Content-Type: text/html' -H "origin: $origin" "${pdserver}/autoconfig/mymac" -d "$current_mac"
elif [[ "$mac" != "$current_mac" ]] ;then
#use the mac suppplied from madmin
set_mac "$mac"
fi
fi
else
echo "Maybe the origin $origin does not exist in madmin or something?"
fi
}
wait_for_network(){
echo "Waiting for network"
until ping -c1 8.8.8.8 >/dev/null 2>/dev/null; do
"No network detected. Sleeping 10s"
sleep 10
done
echo "Network connection detected"
}
repack_magisk(){
log_msg 2 "Starting Magisk repackaging"
monkey -p com.topjohnwu.magisk 1
sleep 30
input tap 39 42
sleep 5
input tap 150 537
sleep 5
input tap 315 552
sleep 5
input tap 881 277
}
install_magisk() {
download "$url_magisk" /sdcard/magisk.zip
mkdir -p /cache/recovery
touch /cache/recovery/command
echo '--update_package=/sdcard/magisk.zip' >> /cache/recovery/command
cachereboot=1
}
check_magisk(){
# We'll attempt to do this a little early since apparently people get impatient
if [[ -f /sbin/magisk ]] ;then
log_msg 2 "Setting Magisk permissions"
/sbin/magiskhide --add com.nianticlabs.pokemongo
[[ -f /sdcard/magisk.zip ]] && rm /sdcard/magisk.zip
[[ -f /sdcard/smali.zip ]] && rm /sdcard/smali.zip
#make sure rgc and pogodroid and shell have su root
puid="$(stat -c %u /data/data/com.mad.pogodroid/)"
ruid="$(stat -c %u /data/data/de.grennith.rgc.remotegpscontroller/)"
suid="$(id -u shell)"
pol="$(sqlite3 /data/adb/magisk.db "select policy from policies where package_name='de.grennith.rgc.remotegpscontroller'")"
if [[ "$ruid" ]] && [[ "$pol" != 2 ]] ;then
magisk --sqlite "DELETE from policies WHERE package_name='de.grennith.rgc.remotegpscontroller'"
magisk --sqlite "INSERT INTO policies (uid,package_name,policy,until,logging,notification) VALUES($ruid,'de.grennith.rgc.remotegpscontroller',2,0,1,0)"
fi
pol="$(sqlite3 /data/adb/magisk.db "select policy from policies where package_name='com.mad.pogodroid'")"
if [[ "$puid" ]] && [[ "$pol" != 2 ]] ;then
magisk --sqlite "DELETE from policies WHERE package_name='com.mad.pogodroid'"
magisk --sqlite "INSERT INTO policies (uid,package_name,policy,until,logging,notification) VALUES($puid,'com.mad.pogodroid',2,0,1,0)"
fi
pol="$(sqlite3 /data/adb/magisk.db "select policy from policies where package_name='com.android.shell'")"
if [[ "$suid" ]] && [[ "$pol" != 2 ]] ;then
magisk --sqlite "DELETE from policies WHERE package_name='com.android.shell'"
magisk --sqlite "INSERT INTO policies (uid,package_name,policy,until,logging,notification) VALUES($suid,'com.android.shell',2,0,1,1)"
fi
fi
# Install magisk. If it already exists, check for an update
if ! [[ -f /sbin/magisk ]] ;then
log_msg 2 "Installing Magisk"
touch /sdcard/magisk_repackage
install_magisk
elif ! magisk -c|grep -q "$magisk_ver"; then
touch /sdcard/magisk_update
install_magisk
elif [[ -f /sdcard/magisk_repackage ]] ;then
log_msg 2 "Magisk repackaging required"
# After installation the manager may not be fully installed. Wait for it to show then repackage
until [[ $(pm list packages com.topjohnwu.magisk) ]] ;do
sleep 10
done
repack_magisk
r=0
while [[ $(pm list packages com.topjohnwu.magisk) ]] ;do
sleep 10
# if repackaging didnt take place in 200 seconds, try again
if ! (( $((r%20)) )); then
log_msg 2 "Magisk repackaging was not successful in the timeframe. Re-attempting the repacakge"
repack_magisk
fi
r=$((r+1))
done
log_msg 2 "Magisk successfully repackaged"
rm -f /sdcard/magisk_repackage
sleep 10
elif [[ -f /sdcard/magisk_update ]] ;then
while [[ $(pm list packages com.topjohnwu.magisk) ]] ;do
pm uninstall com.topjohnwu.magisk
sleep 3
done
rm -f /sdcard/magisk_update
elif [[ $(pm list packages com.topjohnwu.magisk) ]] ;then
log_msg 4 "Magisk manager is installed and not repackaged. This should not happen. Please report it and tell us if you were installing or updating."
fi
}
test_session(){
[[ "$session_id" ]] || return 5
case "$(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/status")" in
406) sleep 15 && test_session
;;
40*) return 3
;;
200) return 0
;;
"") return 2
;;
*) echo "unexpected status $(/system/bin/curl -s -k -L -o /dev/null -w "%{http_code}" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/status") from madmin" && return 4
;;
esac
}
make_session(){
until test_session ;do
echo "Trying to register session"
session_id=$(/system/bin/curl -s -k -L -X POST --user "$pdauth" "${pdserver}/autoconfig/register")
sleep 15
done
echo "$session_id" > /sdcard/reg_session
}
check_session(){
if ! [[ -f /sdcard/reg_session ]] ;then
make_session
else
session_id="$(cat /sdcard/reg_session)"
if ! test_session ;then
rm -f /sdcard/reg_session
make_session
fi
fi
}
################ start of execution
wait_for_network
if [[ -f "$pdconf" ]] ;then
origin="$(awk -F'>' '/post_origin/{print $2}' "$pdconf"|awk -F'<' '{print $1}')"
pdserver="$(grep -v raw "$pdconf"|awk -F'>' '/post_destination/{print $2}'|awk -F'<' '{print $1}')"
pduser="$(grep -v raw "$pdconf"|awk -F'>' '/auth_username/{print $2}'|awk -F'<' '{print $1}')"
pdpass="$(grep -v raw "$pdconf"|awk -F'>' '/auth_password/{print $2}'|awk -F'<' '{print $1}')"
pdauth="$pduser:$pdpass"
elif [[ -f /data/local/pdconf ]] ;then
origin="$(awk -F'>' '/post_origin/{print $2}' /data/local/pdconf|awk -F'<' '{print $1}')"
pdserver="$(grep -v raw /data/local/pdconf|awk -F'>' '/post_destination/{print $2}'|awk -F'<' '{print $1}')"
pduser="$(grep -v raw /data/local/pdconf|awk -F'>' '/auth_username/{print $2}'|awk -F'<' '{print $1}')"
pdpass="$(grep -v raw /data/local/pdconf|awk -F'>' '/auth_password/{print $2}'|awk -F'<' '{print $1}')"
pdauth="$pduser:$pdpass"
check_session
else
usbfile="$(find /mnt/media_rw/ -name mad_autoconf.txt|head -n1)"
if [[ "$usbfile" ]] ;then
pdserver="$(awk 'NR==1{print $1}' "$usbfile")"
pdauth="$(awk 'NR==2{print $1}' "$usbfile")"
check_session
origin=$(/system/bin/curl -s -k -L --user "$pdauth" "${pdserver}/autoconfig/${session_id}/origin")
/system/bin/curl -s -k -L -o "/data/local/pdconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/pd"
checkmac
echo "Installing the apps from the wizard"
if ! grep -q "version $uver" /system/bin/update_mad.sh; then
download https://raw.githubusercontent.com/Map-A-Droid/MAD-ATV/master/update_mad.sh /system/bin/update_mad.sh
chmod +x /system/bin/update_mad.sh
fi
sh -x /system/bin/update_mad.sh -pdc -wa
fi
fi
mount -o remount,rw /system
check_magisk
# Install gapps
if [[ ! $(pm list packages android.vending) ]] ;then
download "$url_gapps" /sdcard/gapps.zip
mkdir -p /cache/recovery
touch /cache/recovery/command
echo '--update_package=/sdcard/gapps.zip' >> /cache/recovery/command
cachereboot=1
fi
[[ -d /sdcard/TWRP ]] && rm -rf /sdcard/TWRP
[[ $(settings get global hdmi_control_enabled) != "0" ]] && settings put global hdmi_control_enabled 0
[[ "$(/system/bin/getprop persist.sys.app.rotation)" != "middle_port" ]] && /system/bin/setprop persist.sys.app.rotation middle_port
[[ $(settings get global stay_on_while_plugged_in) != 3 ]] && settings put global stay_on_while_plugged_in 3
[[ "$(/system/bin/appops get de.grennith.rgc.remotegpscontroller android:mock_location)" = "No operations." ]] && /system/bin/appops set de.grennith.rgc.remotegpscontroller android:mock_location allow
! settings get secure location_providers_allowed|grep -q gps && settings put secure location_providers_allowed +gps
echo "$madver" > /sdcard/madversion
if (( "$cachereboot" )) ;then
log_msg "2" "Rebooting into recovery mode for required installations"
echo '--wipe_cache' >> /cache/recovery/command
reboot recovery
fi
pdir="/data/data/com.mad.pogodroid/"
puser="$(stat -c %u "$pdir")"
rgcdir="/data/data/de.grennith.rgc.remotegpscontroller/"
ruser="$(stat -c %u "$rgcdir")"
if [[ "$puser" ]] && [[ "$pdauth" ]] && [[ -d "$pdir" ]] && ! [[ -f "$pdconf" ]] && [[ "$session_id" ]] ;then
if [[ ! -d "$pdir/shared_prefs" ]] ;then
mkdir -p "$pdir/shared_prefs"
chmod 771 "$pdir/shared_prefs"
chown "$puser":"$puser" "$pdir/shared_prefs"
fi
/system/bin/curl -s -k -L -o "$pdconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/pd"
chmod 660 "$pdconf" && chown "$puser":"$puser" "$pdconf"
rm -f /data/local/pdconf
fi
if [[ "$puser" ]] && [[ "$pdauth" ]] && [[ -d "$rgcdir" ]] && ! [[ -f "$rgcconf" ]] ;then
if [[ ! -d "$rgcdir/shared_prefs" ]] ;then
mkdir -p "$rgcdir/shared_prefs"
chmod 771 "$rgcdir/shared_prefs"
chown "$ruser":"$ruser" "$rgcdir/shared_prefs"
fi
/system/bin/curl -s -k -L -o "$rgcconf" --user "$pdauth" "${pdserver}/autoconfig/${session_id}/rgc"
chmod 660 "$rgcconf" && chown "$ruser":"$ruser" "$rgcconf"
fi
if [[ "$(pm list packages com.mad.pogodroid)" ]] && ! dumpsys package com.mad.pogodroid |grep READ_EXTERNAL_STORAGE|grep granted|grep -q 'granted=true'; then
pm grant com.mad.pogodroid android.permission.READ_EXTERNAL_STORAGE
pm grant com.mad.pogodroid android.permission.WRITE_EXTERNAL_STORAGE
fi
if [[ "$(pm list packages com.nianticlabs.pokemongo)" ]] && ! dumpsys package com.nianticlabs.pokemongo|grep ACCESS_FINE_LOCATION|grep granted|grep -q 'granted=true'; then
pm grant com.nianticlabs.pokemongo android.permission.ACCESS_FINE_LOCATION
pm grant com.nianticlabs.pokemongo android.permission.ACCESS_COARSE_LOCATION
pm grant com.nianticlabs.pokemongo android.permission.CAMERA
pm grant com.nianticlabs.pokemongo android.permission.GET_ACCOUNTS
fi
if [[ "$(pm list packages de.grennith.rgc.remotegpscontroller)" ]] && ! dumpsys package de.grennith.rgc.remotegpscontroller|grep ACCESS_FINE_LOCATION|grep granted|grep -q 'granted=true'; then
pm grant de.grennith.rgc.remotegpscontroller android.permission.ACCESS_FINE_LOCATION
pm grant de.grennith.rgc.remotegpscontroller android.permission.READ_EXTERNAL_STORAGE
pm grant de.grennith.rgc.remotegpscontroller android.permission.ACCESS_COARSE_LOCATION
pm grant de.grennith.rgc.remotegpscontroller android.permission.WRITE_EXTERNAL_STORAGE
fi
[[ -f "$pdconf" ]] && [[ -f "$rgcconf" ]] && [[ "$origin" ]] && ! [[ "$(grep 'com.android.contacts"' /data/system/sync/accounts.xml | cut -d'"' -f8)" ]] && autoconf_google_signin
if [[ -f /sdcard/reg_session ]] && [[ -f "$pdconf" ]] && [[ -f "$rgcconf" ]] ;then
/system/bin/curl -s -k -L -X DELETE --user "$pdauth" "${pdserver}/autoconfig/${session_id}/complete"
rm -f /sdcard/reg_session
reboot
fi
execute_autoupdates
mount -o remount,ro /system
# initdebug