-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.sh
137 lines (122 loc) · 2.98 KB
/
upgrade.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
#!/bin/sh
export UpdateStatus=/mnt/mtd/Update.dat
export UpdateFileStatus=/mnt/mtd/UpdateFile.dat
export UpgradePath=/tmp/upgrade/
export UpgradeFilePath=$UpgradePath/upgrade.tar.gz
export PreUpgradeSh=/tmp/upgrade/preupgrade.sh
export UsbPath=/mnt/u
#挂载USB
mount_usb()
{
cat /proc/partitions | tr -s "[\ ]" | cut -d\ -f5 | tr "[\n]" "[ ]" > /tmp/dev_tmp
for dev_name in $(cat /tmp/dev_tmp) ; do
RESULT=`cat "/sys/block/$dev_name/removable"`
if [ "$RESULT" = "1" ] ; then
mkdir $UsbPath
mount -t vfat -o codepage=936,iocharset=utf8 /dev/${dev_name}1 $UsbPath
return
fi
done
}
upgrade_by_usb()
{
insmod /tmp/modules/extdrv/ehci-hcd.ko
sleep 2
rm -rf $UsbPath/*
mount_usb
sleep 2
}
#从硬盘读取文件到UpgradePath
upgrade_by_disk()
{
cd /dev
for i in `ls sd?` ;
do
RESULT=`cat "/sys/block/$i/removable"`
if [ "$RESULT" = "0" ] ; then
dd if=/dev/$i of=/tmp/disk_$i.data bs=1 count=4 skip=440 >& /dev/null
flag=`cat /tmp/disk_$i.data`
if [ "x$flag" != "xDUMP" ] ; then
dd if=/dev/$i of=/tmp/mark_$i.data bs=1 count=4 skip=260 >& /dev/null
flag=`cat /tmp/mark_$i.data`
if [ "x$flag" = "xxT" ] ; then
export DISKNAME=$i
echo $DISKNAME
break
fi
fi
fi
done
/mnt/mtd/upgradeFileFromDisk $DISKNAME
}
#升级开始1为usb,2为硬盘
RESULT=`cat "$UpdateStatus"`
echo "RESULT=$RESULT"
rm $UpdateStatus
mkdir $UpgradePath
#mount -t tmpfs tmpfs $UpgradePath
if [ "$RESULT" = "1" ] ; then
if [ -f $UpdateFileStatus ] ; then
echo "------------- $UpdateFileStatus exist ---------------"
UPGRADE_FILENAME=`cat "$UpdateFileStatus"`
rm $UpdateFileStatus
upgrade_by_usb
echo "------------- $UPGRADE_FILENAME ---------------"
export UpgradeFilePath=${UsbPath}/${UPGRADE_FILENAME}
echo "------------- $UpgradeFilePath ---------------"
else
echo "file $UpdateFileStatus not exist"
return
fi
elif [ "$RESULT" = "2" ] ; then
upgrade_by_disk
else
echo "No need to recovery program from device"
#umount $UpgradePath && rm -rf $UpgradePath
return
fi
if [ ! -f "$UpgradeFilePath" ]; then
echo "can not find file $UpgradeFilePath"
#umount $UpgradePath && rm -rf $UpgradePath
umount $UsbPath && rm -rf $UsbPath
reboot
exit -1;
else
tar -zxvf "$UpgradeFilePath" -C $UpgradePath
sleep 2
cd $UpgradePath
md5sum -c upgradeCheck.dat
if [ "$?" != 0 ] ; then
echo "$UpgradeFilePath file error md5sum fail"
#umount $UpgradePath &&
rm -rf $UpgradePath
umount $UsbPath
reboot
exit -1;
fi
fi
#升级开始
sh ${PreUpgradeSh}
if [ -f $UpgradePath/kvms35n ]; then
echo "upgrade kernel"
fi
if [ -f $UpgradePath/rootfs.tar.gz ]; then
echo "upgrade rootfs"
fi
if [ -f $UpgradePath/qtfs.tar.gz ]; then
echo "upgrade qtfs"
rm -rf /mnt/mtd/qte
cd $UpgradePath
tar -zxvf qtfs.tar.gz -C /mnt/mtd/
sleep 5
fi
if [ -f $UpgradePath/appfs.tar.gz ]; then
echo "upgrade appfs"
cd /mnt/mtd/ && find ./ | grep -v qte | grep -v u| xargs rm -rf
cd $UpgradePath
tar -zxvf appfs.tar.gz -C /mnt/mtd/
sleep 5
fi
sync
reboot
exit -1;