-
Notifications
You must be signed in to change notification settings - Fork 0
/
recoverycheck.sh
134 lines (109 loc) · 3.5 KB
/
recoverycheck.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
#!/tmp/busybox sh
#
# Recovery Check Script for the Galaxy Player 5
#
# (c) 2014 Meticulus
#
# This script checks to see if recovery update is needed due to SELinux setperm
# implemented in 4.3. If we are below that version then we need an update. so
# we flash the kernel and reboot back to recovery.
if [[ -e /cache/recovery/recoveryupgraded ]]; then
rm /cache/recovery/recoveryupgraded
exit 0
fi
VERSION=""
THISZIP=""
NEEDUPGRADE=0
NEEDRECOVERYPRECOMMAND=0
NEEDZIPPATHCORRECTION=0
NEEDFORMATCACHE=0
# Stock gingerbread didn't have much in the default.prop but new version
# of android do, check here first then use getprop.
if [[ "$VERSION" == "" ]]; then
while read LINE
do
PROP=$(echo $LINE | cut -d '=' -f1)
if [[ "$PROP" == "ro.build.version.release" ]]; then
VERSION=$(echo $LINE | cut -d '=' -f2)
break
fi
done < /default.prop
fi
if [[ "$VERSION" == "" ]]; then
VERSION=$(getprop ro.build.version.release)
fi
if [[ "$VERSION" == "" ]]; then
echo "Unable to find android version!" >> /tmp/recovery.log
NEEDUPGRADE=1
fi
MAJOR=$(echo "$VERSION" | cut -d '.' -f1)
MINOR=$(echo "$VERSION" | cut -d '.' -f2)
echo "Android version = $VERSION" >> /tmp/recovery.log
if [[ $MAJOR -lt 4 ]]; then
NEEDUPGRADE=1
NEEDZIPPATHCORRECTION=1
NEEDFORMATCACHE=1
fi
if [[ $MAJOR -eq 4 ]]; then
if [[ $MINOR -lt 3 ]]; then
NEEDUPGRADE=1
NEEDRECOVERYPRECOMMAND=1
NEEDZIPPATHCORRECTION=1
fi
fi
if [[ $MAJOR -eq 4 ]]; then
if [[ $MINOR -lt 4 ]]; then
NEEDRECOVERYPRECOMMAND=1
fi
fi
# Find the path of the zip we are flashing...
while read LINE
do
PROP=$(echo $LINE | cut -d ':' -f1)
if [[ "$PROP" == "-- Installing" ]]; then
THISZIP=$(echo $(echo $LINE | cut -d ':' -f2) | tr -d ' ')
# For Gingerbread, paths need to be switched for new CWM paths.
if [[ $NEEDZIPPATHCORRECTION -eq 1 ]]; then
echo "$THISZIP" > /tmp/path.txt
sed 's/\/sdcard/\external_sd/g' /tmp/path.txt > /tmp/path2.txt
sed 's/\/emmc/\/sdcard/g' /tmp/path2.txt > /tmp/path3.txt
THISZIP=$(cat /tmp/path3.txt)
fi
# don't break here, we want the last one
fi
done < /tmp/recovery.log
if [[ $NEEDUPGRADE -eq 1 ]]; then
if [[ -e /tmp/recoveryupdate.img ]]; then
# Flash the kernel with update recovery in it.
/tmp/busybox dd if=/tmp/recoveryupdate.img of=/dev/block/mmcblk0p11
if [[ $NEEDFORMATCACHE -eq 1 ]]; then
/tmp/busybox umount /cache
/tmp/make_ext4fs -b 4096 -g 32768 -i 8192 -I 256 /dev/block/mmcblk0p15 /cache
fi
/tmp/busybox mount /cache
# create automatic installation recovery script.
mkdir -p /cache/recovery
echo "Updating Recovery" >> /tmp/recovery.log
echo "run_program(\"/sbin/busybox\", \"touch\", \"/tmp/noreboot\");" > /cache/recovery/extendedcommand
echo "format(\"/cache\");" >> /cache/recovery/extendedcommand
echo "install_zip(\"$THISZIP\");" >> /cache/recovery/extendedcommand
# Marker so we can skip this on first reboot to new recovery
touch /cache/recovery/recoveryupgraded
sleep 10
cp /tmp/recovery.log /cache/recovery
if [[ $NEEDRECOVERYPRECOMMAND -eq 1 ]]; then
echo "1" > /cache/.startrecovery
reboot
else
reboot recovery
fi
else
echo "recoveryupdate.img missing?" >> /tmp/recovery.log
cp /tmp/recovery.log /cache/recovery
exit 9
fi
else
echo "Recovery update not needed" >> /tmp/recovery.log
fi
cp /tmp/recovery.log /cache/recovery
exit 0