|
1 | 1 | #!/system/bin/sh |
2 | | -#Bootloop saver by HuskyDG |
| 2 | +#Bootloop saver by HuskyDG, modified by ez-me |
3 | 3 |
|
4 | | -MODDIR=${0%/*} |
5 | | -. "$MODDIR/utils.sh" |
| 4 | +# Get variables |
| 5 | +MODPATH=${0%/*} |
| 6 | +MESSAGE="$(cat "$MODPATH"/msg.txt | head -c100)" |
6 | 7 |
|
| 8 | +if [ -n "$(getprop ro.product.cpu.abi | grep 64)" ] |
| 9 | +then |
| 10 | + ZYGOTE_NAME=zygote64 |
| 11 | +else |
| 12 | + ZYGOTE_NAME=zygote |
| 13 | +fi |
7 | 14 |
|
8 | | -rm -rf /cache/bootloop_saver.log.bak |
9 | | -mv -f /cache/bootloop_saver.log /cache/bootloop_saver.log.bak 2>/dev/null |
10 | | -write_log "bootloop saver started" |
11 | | -MAIN_ZYGOTE_NICENAME=zygote |
12 | | -CPU_ABI=$(getprop ro.product.cpu.api) |
13 | | -[ "$CPU_ABI" = "arm64-v8a" -o "$CPU_ABI" = "x86_64" ] && MAIN_ZYGOTE_NICENAME=zygote64 |
| 15 | +# Log |
| 16 | +log(){ |
| 17 | + TEXT=$@; echo "[`date -Is`]: $TEXT" >> $MODPATH/log.txt |
| 18 | +} |
14 | 19 |
|
15 | | -check(){ |
16 | | -TEXT1="$1" |
17 | | -TEXT2="$2" |
18 | | -result=false |
19 | | -for i in $TEXT1; do |
20 | | - for j in $TEXT2; do |
21 | | - [ "$i" == "$j" ] && result=true |
22 | | - done |
23 | | -done |
24 | | -$result |
| 20 | +log "Started" |
| 21 | + |
| 22 | +# Modify description |
| 23 | +cp "$MODPATH/module.prop" "$MODPATH/temp.prop" |
| 24 | +sed -Ei "s/^description=(\[.*][[:space:]]*)?/description=[Working. $MESSAGE] /g" "$MODPATH/temp.prop" |
| 25 | +mv "$MODPATH/temp.prop" "$MODPATH/module.prop" |
| 26 | + |
| 27 | +# Define the function |
| 28 | +disable_modules(){ |
| 29 | + log "Disabling modules..." |
| 30 | + list="$(find /data/adb/modules/* -prune -type d)" |
| 31 | + for module in $list |
| 32 | + do |
| 33 | + touch $module/disable |
| 34 | + done |
| 35 | + rm -rf "$MODPATH/disable" |
| 36 | + echo "Disabled modules at $(date -Is)" > "$MODPATH/msg.txt" |
| 37 | + rm -rf /cache/.system_booting /data/unencrypted/.system_booting /metadata/.system_booting /persist/.system_booting /mnt/vendor/persist/.system_booting |
| 38 | + log "Rebooting" |
| 39 | + reboot |
| 40 | + exit |
25 | 41 | } |
26 | 42 |
|
27 | 43 |
|
28 | | -# Wait for zygote starts |
| 44 | +# Gather PIDs |
29 | 45 | sleep 5 |
| 46 | +ZYGOTE_PID1=$(pidof "$ZYGOTE_NAME") |
| 47 | +log "PID1: $ZYGOTE_PID1" |
30 | 48 |
|
31 | | -ZYGOTE_PID1=$(pidof "$MAIN_ZYGOTE_NICENAME") |
32 | | -write_log "pid of zygote stage 1: $ZYGOTE_PID1" |
33 | | -sleep 15 |
34 | | -ZYGOTE_PID2=$(pidof "$MAIN_ZYGOTE_NICENAME") |
35 | | -write_log "pid of zygote stage 2: $ZYGOTE_PID2" |
36 | 49 | sleep 15 |
37 | | -ZYGOTE_PID3=$(pidof "$MAIN_ZYGOTE_NICENAME") |
38 | | -write_log "pid of zygote stage 3: $ZYGOTE_PID3" |
| 50 | +ZYGOTE_PID2=$(pidof "$ZYGOTE_NAME") |
| 51 | +log "PID2: $ZYGOTE_PID2" |
39 | 52 |
|
| 53 | +sleep 15 |
| 54 | +ZYGOTE_PID3=$(pidof "$ZYGOTE_NAME") |
| 55 | +log "PID3: $ZYGOTE_PID3" |
40 | 56 |
|
41 | | -if check "$ZYGOTE_PID1" "$ZYGOTE_PID2" && check "$ZYGOTE_PID2" "$ZYGOTE_PID3"; then |
42 | | - if [ -z "$ZYGOTE_PID1" ]; then |
43 | | - write_log "maybe zygote not start :(" |
44 | | - write_log "zygote meets the trouble, disable all modules and restart" |
| 57 | +# Check for BootLoop |
| 58 | +log "Checking..." |
45 | 59 |
|
46 | | - disable_modules |
47 | | - else |
48 | | - exit_log "pid of 3 stage zygote is the same" |
49 | | - fi |
50 | | -else |
51 | | - write_log "pid of 3 stage zygote is different, continue check to make sure... " |
| 60 | +if [ -z "$ZYGOTE_PID1" ] |
| 61 | +then |
| 62 | + log "Zygote didn't start?" |
| 63 | + disable_modules |
52 | 64 | fi |
53 | 65 |
|
| 66 | +if [ "$ZYGOTE_PID1" != "$ZYGOTE_PID2" -o "$ZYGOTE_PID2" != "$ZYGOTE_PID3" ] |
| 67 | +then |
| 68 | + log "PID mismatch, checking again" |
| 69 | + sleep 15 |
| 70 | + ZYGOTE_PID4=$(pidof "$ZYGOTE_NAME") |
| 71 | + log "PID4: $ZYGOTE_PID4" |
| 72 | + |
| 73 | + if [ "$ZYGOTE_PID3" != "$ZYGOTE_PID4" ] |
| 74 | + then |
| 75 | + log "They don't match..." |
| 76 | + disable_modules |
| 77 | + fi |
| 78 | +fi |
54 | 79 |
|
55 | | - |
56 | | - |
57 | | -sleep 15 |
58 | | -ZYGOTE_PID4=$(pidof "$MAIN_ZYGOTE_NICENAME") |
59 | | -write_log "pid of zygote stage 4: $ZYGOTE_PID4" |
60 | | -check "$ZYGOTE_PID3" "$ZYGOTE_PID4" && exit_log "pid of zygote stage 3 and 4 is the same." |
61 | | - |
62 | | -write_log "zygote meets the trouble, disable all modules and restart" |
63 | | - |
64 | | -disable_modules |
65 | | - |
| 80 | +# If we reached this section we should be fine |
| 81 | +log "looks good to me!" |
| 82 | +exit |
0 commit comments