forked from teamacid/android_device_samsung_galaxys4gmtd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.sh
executable file
·176 lines (140 loc) · 5.33 KB
/
updater.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
#!/tmp/busybox sh
#
# Universal Updater Script for Samsung Galaxy S Phones
# (c) 2011 by Teamhacksung
# GSM version
#
check_mount() {
if ! /tmp/busybox grep -q $1 /proc/mounts ; then
/tmp/busybox mkdir -p $1
/tmp/busybox umount -l $2
if ! /tmp/busybox mount -t $3 $2 $1 ; then
/tmp/busybox echo "Cannot mount $1."
exit 1
fi
fi
}
set_log() {
rm -rf $1
exec >> $1 2>&1
}
set -x
export PATH=/:/sbin:/system/xbin:/system/bin:/tmp:$PATH
# check if we're running on a bml or mtd device
if /tmp/busybox test -e /dev/block/bml7 ; then
# we're running on a bml device
# make sure sdcard is mounted
check_mount /sdcard /dev/block/mmcblk0p1 vfat
# everything is logged into /mnt/sdcard/cyanogenmod_bml.log
set_log /sdcard/cyanogenmod_bml.log
# make sure efs is mounted
check_mount /efs /dev/block/stl3 rfs
# create a backup of efs
if /tmp/busybox test -e /sdcard/backup/efs.tar ; then
/tmp/busybox mv /sdcard/backup/efs.tar /sdcard/backup/efs-$$.tar
/tmp/busybox mv /sdcard/backup/efs.tar.md5 /sdcard/backup/efs-$$.tar.md5
fi
/tmp/busybox rm -f /sdcard/backup/efs.tar
/tmp/busybox rm -f /sdcard/backup/efs.tar.md5
/tmp/busybox mkdir -p /sdcard/backup
cd /efs
/tmp/busybox tar cf /sdcard/backup/efs.tar *
# Now we checksum the file. We'll verify later when we do a restore
cd /sdcard/backup/
/tmp/busybox md5sum -t efs.tar > efs.tar.md5
# write the package path to sdcard cyanogenmod.cfg
if /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
PACKAGE_LOCATION=${UPDATE_PACKAGE#/mnt}
/tmp/busybox echo "$PACKAGE_LOCATION" > /sdcard/cyanogenmod.cfg
# Make sure that the zip file gets flashed upon reboot
/tmp/busybox echo "install_zip(\"$PACKAGE_LOCATION\");" > /sdcard/extendedcommand
fi
# Scorch any ROM Manager settings to require the user to reflash recovery
/tmp/busybox rm -f /sdcard/clockworkmod/.settings
# write new kernel to boot partition
/tmp/flash_image boot /tmp/boot.img
if [ "$?" != "0" ] ; then
/tmp/busybox echo "Failed to write kernel to boot partition"
exit 3
fi
/tmp/busybox echo "Successfully wrote kernel to boot partition"
/tmp/busybox sync
/sbin/reboot
exit 0
elif /tmp/busybox test -e /dev/block/mtdblock0 ; then
# we're running on a mtd device
# make sure sdcard is mounted
check_mount /sdcard /dev/block/mmcblk0p1 vfat
# everything is logged into /sdcard/cyanogenmod.log
set_log /sdcard/cyanogenmod_mtd.log
# create mountpoint for radio partition
/tmp/busybox mkdir -p /radio
# make sure radio partition is mounted
if ! /tmp/busybox grep -q /radio /proc/mounts ; then
/tmp/busybox umount -l /dev/block/mtdblock6
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock6 /radio ; then
/tmp/busybox echo "Cannot mount radio partition."
exit 5
fi
fi
# if modem.bin doesn't exist on radio partition, format the partition and copy it
if ! /tmp/busybox test -e /radio/modem.bin ; then
/tmp/busybox umount -l /dev/block/mtdblock6
/tmp/erase_image radio
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock6 /radio ; then
/tmp/busybox echo "Cannot copy modem.bin to radio partition."
exit 5
else
/tmp/busybox cp /tmp/modem.bin /radio/modem.bin
/tmp/busybox sync
fi
fi
# unmount radio partition
/tmp/busybox umount -l /dev/block/mtdblock6
# flash boot image
/tmp/erase_image boot
/tmp/bml_over_mtd.sh boot 72 reservoir 4012 /tmp/boot.img
# unmount and format system (recovery seems to expect system to be unmounted)
/tmp/busybox umount -l /system
/tmp/erase_image system
# if a cyanogenmod.cfg exists, then this is a first time install
# let's format the volumes and restore radio and efs
if ! /tmp/busybox test -e /sdcard/cyanogenmod.cfg ; then
/tmp/busybox echo "Updating CyanogenMod, Not formating /cache and /data, not restoring /efs"
exit 0
fi
/tmp/busybox echo "Updating from a BML rom. Format /cache and /data, and attempt to restore /efs"
# remove the cyanogenmod.cfg to prevent this from looping
/tmp/busybox rm -f /sdcard/cyanogenmod.cfg
# unmount and format cache
/tmp/busybox umount -l /cache
/tmp/erase_image cache
# unmount and format data
/tmp/busybox umount -l /data
/tmp/erase_image userdata
# restore efs backup
if /tmp/busybox test -e /sdcard/backup/efs.tar ; then
/tmp/busybox umount -l /efs
/tmp/erase_image efs
/tmp/busybox mkdir -p /efs
# make sure we can mount /efs
check_mount /efs /dev/block/mtdblock4 yaffs2
# verify the md5sum of efs.tar before restore
cd /sdcard/backup/
/tmp/busybox md5sum -c efs.tar.md5
# save the exit status of md5sum
MD5RESULT=$?
if ! /tmp/busybox test $MD5RESULT; then
echo "efs.tar could not be verified."
exit 7
fi
# extract the tar file in the /efs partition
cd /efs
/tmp/busybox tar xf /sdcard/backup/efs.tar
/tmp/busybox umount -l /efs
else
/tmp/busybox echo "/sdcard/backup/efs.tar does not exist. Not restoring efs."
exit 8
fi
exit 0
fi