forked from zaclimon/android_device_samsung_ypg1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.sh
executable file
·155 lines (123 loc) · 4.55 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
#!/tmp/busybox sh
#
# Universal Updater Script for Samsung Galaxy S Phones
# (c) 2011 by Teamhacksung
# GSM version
#
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 || [ $(grep mtdblock2 /proc/partitions | awk '{ print $3 }') -lt 395264 ]; then
# we're running on a bml device or using an older mtd partition layout
check_mount() {
local MOUNT_POINT=`/tmp/busybox readlink $1`
if ! /tmp/busybox test -n "$MOUNT_POINT" ; then
# readlink does not work on older recoveries for some reason
# doesn't matter since the path is already correct in that case
/tmp/busybox echo "Using non-readlink mount point $1"
MOUNT_POINT=$1
fi
if ! /tmp/busybox grep -q $MOUNT_POINT /proc/mounts ; then
/tmp/busybox mkdir -p $MOUNT_POINT
/tmp/busybox umount -l $2
if ! /tmp/busybox mount -t $3 $2 $MOUNT_POINT ; then
/tmp/busybox echo "Cannot mount $1 ($MOUNT_POINT)."
exit 1
fi
fi
}
set_log() {
rm -rf $1
exec >> $1 2>&1
}
fix_package_location() {
local PACKAGE_LOCATION=$1
# Remove leading /mnt
PACKAGE_LOCATION=${PACKAGE_LOCATION#/mnt}
# Convert to modern sdcard path
PACKAGE_LOCATION=`echo $PACKAGE_LOCATION | /tmp/busybox sed -e "s|^/sdcard|/storage/sdcard0|"`
PACKAGE_LOCATION=`echo $PACKAGE_LOCATION | /tmp/busybox sed -e "s|^/emmc|/storage/sdcard1|"`
echo $PACKAGE_LOCATION
}
# make sure sdcard is mounted
check_mount /mnt/sdcard dev/block/mmcblk0p1 vfat
# everything is logged into /mnt/sdcard/cyanogenmod_bml.log
set_log /mnt/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 /mnt/sdcard/backup/efs ; then
/tmp/busybox mv /mnt/sdcard/backup/efs /mnt/sdcard/backup/efs-$$
fi
/tmp/busybox rm -rf /mnt/sdcard/backup/efs
/tmp/busybox mkdir -p /mnt/sdcard/backup/efs
/tmp/busybox cp -R /efs/ /mnt/sdcard/backup
# write the package path to sdcard cyanogenmod.cfg
if /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
/tmp/busybox echo `fix_package_location $UPDATE_PACKAGE` > /sdcard/cyanogenmod.cfg
fi
# Scorch any ROM Manager settings to require the user to reflash recovery
/tmp/busybox rm -f /mnt/sdcard/clockworkmod/.settings
# write decoy recovery to recovery partition
/tmp/flash_image recovery /tmp/recovery.bin
if [ "$?" != "0" ] ; then
exit 8
fi
/tmp/busybox sync
# write new kernel to boot partition
/tmp/flash_image boot /tmp/boot.img
if [ "$?" != "0" ] ; then
exit 3
fi
/tmp/busybox sync
/tmp/busybox reboot now
exit 9
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
# remove old log
rm -rf /sdcard/cyanogenmod_mtd.log
# everything is logged into /sdcard/cyanogenmod.log
set_log /sdcard/cyanogenmod_mtd.log
# if a cyanogenmod.cfg exists, then this is a first time install
# let's format the volumes and restore efs
if ! /tmp/busybox test -e /sdcard/cyanogenmod.cfg ; then
exit 0
fi
# remove the cyanogenmod.cfg to prevent this from looping
/tmp/busybox rm -f /sdcard/cyanogenmod.cfg
# unmount, format and mount system
/tmp/busybox umount -l /system
/tmp/erase_image system
/tmp/busybox mount -t yaffs2 /dev/block/mtdblock2 /system
# unmount and format cache
/tmp/busybox umount -l /cache
/tmp/erase_image cache
# unmount and format data
/tmp/busybox umount /data
/tmp/make_ext4fs -b 4096 -g 32768 -i 8192 -I 256 -a /data /dev/block/mmcblk0p2
# unmount and format datadata
/tmp/busybox umount -l /datadata
/tmp/erase_image dbdatafs
# restore efs backup
if /tmp/busybox test -e /sdcard/backup/efs/serial.info ; then
/tmp/busybox umount -l /efs
/tmp/erase_image efs
/tmp/busybox mkdir -p /efs
if ! /tmp/busybox grep -q /efs /proc/mounts ; then
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock4 /efs ; then
/tmp/busybox echo "Cannot mount efs."
exit 6
fi
fi
/tmp/busybox cp -R /sdcard/backup/efs /
/tmp/busybox umount -l /efs
else
/tmp/busybox echo "Cannot restore efs."
exit 7
fi
# flash boot image
/tmp/bml_over_mtd.sh boot 72 reservoir 2004 /tmp/boot.img
exit 0
fi