-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfw_update.sh
executable file
·180 lines (141 loc) · 6.09 KB
/
fw_update.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
177
178
179
180
#!/bin/sh
##############################################################################
## Copyright (c) 2007-2008, Calaos. All Rights Reserved.
##
## This file is part of Calaos Home.
##
## Calaos Home is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Calaos Home is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Foobar; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
##############################################################################
#
# Extract/Check/Update the firmware to another revision
#
# Do the work in a detached process, so it can't be killed by
# the parent (calaosd/calaos_gui)
drive=`cat /etc/drive`
if [ $PPID -ne 1 ] ; then
( ( fw_update.sh & ) & )
exit 0
fi
test -f /tmp/update_in_progress && exit 0
echo "update" > /tmp/update_in_progress
mkdir -p /mnt/ext3/log
LOG="/mnt/ext3/log/fwupdate_log"
rm -f $LOG
log ()
{
echo $1 >> $LOG
}
exit_with_error ()
{
log $1
exit 1
}
log "Starting update system"
log "`date`"
#Mount the vfat partition
log "Unmounting vfat partition in case it's already mounted"
umount -n /mnt/vfat/ >> $LOG 2>> $LOG
log "Done."
log "Mounting vfat partition"
mount -n ${drive}1 /mnt/vfat/ >> $LOG 2>> $LOG || exit_with_error "Command failed: mount -n ${drive}1 /mnt/vfat/"
test -d /mnt/vfat/tmp && (rm -fr /mnt/vfat/tmp >> $LOG 2>> $LOG)
mkdir /mnt/vfat/tmp >> $LOG 2>> $LOG
log "Done."
#extract and check
log "Extract files..."
( cd /tmp/; tar xjvf /tmp/image.tar.bz2 -C /mnt/vfat/tmp >> $LOG 2>> $LOG );
log "Test files"
test -f /mnt/vfat/tmp/rootfs >> $LOG 2>> $LOG || exit_with_error "Command failed: test -f /mnt/vfat/tmp/rootfs"
test -f /mnt/vfat/tmp/vmlinuz >> $LOG 2>> $LOG || exit_with_error "Command failed: test -f /mnt/vfat/tmp/vmlinuz"
test -f /mnt/vfat/tmp/syslinux.cfg >> $LOG 2>> $LOG || exit_with_error "Command failed: test -f /mnt/vfat/tmp/syslinux.cfg"
test -f /mnt/vfat/tmp/VERSION >> $LOG 2>> $LOG || exit_with_error "Command failed: test -f /mnt/vfat/tmp/VERSION"
log "Files OK."
log "Clean /tmp"
rm -fr /tmp/image.tar.bz2 >> $LOG 2>> $LOG
log "Done."
log "Getting version:"
VERSION=`cat /mnt/vfat/tmp/VERSION`
log "fw revision $VERSION"
#clean old files if any
log "Cleaning old rootfs files..."
rm -f /mnt/vfat/rootfs.old /mnt/vfat/vmlinuz.old /mnt/vfat/syslinux.old >> $LOG 2>> $LOG
log "Done."
#copy
log "Begin copy of rootfs..."
mv /mnt/vfat/tmp/rootfs /mnt/vfat/rootfs.new >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/tmp/rootfs /mnt/vfat/rootfs.new"
log "Done."
log "Begin copy of kernel..."
mv /mnt/vfat/tmp/vmlinuz /mnt/vfat/vmlinuz.new >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/tmp/vmlinuz /mnt/vfat/vmlinuz.new"
log "Done."
log "Begin copy of syslinux.cfg..."
mv /mnt/vfat/tmp/syslinux.cfg /mnt/vfat/syslinux.new >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/tmp/syslinux.cfg /mnt/vfat/syslinux.new"
log "Done."
log "## Start Critical Operations ##"
#now we do some critical operations, if the power fails now
#the system could not be able to boot anymore !
log "Moving old rootfs"
mv /mnt/vfat/rootfs /mnt/vfat/rootfs.old >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/rootfs /mnt/vfat/rootfs.old"
log "Done."
log "Moving old kernel"
mv /mnt/vfat/vmlinuz /mnt/vfat/vmlinuz.old >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/vmlinuz /mnt/vfat/vmlinuz.old"
log "Done."
log "Moving old syslinux.cfg"
mv /mnt/vfat/syslinux.cfg /mnt/vfat/syslinux.old >> $LOG 2>> $LOG || exit_with_error "Command failed: mv /mnt/vfat/syslinux.cfg /mnt/vfat/syslinux.old"
log "Done."
log "Moving new rootfs"
mv /mnt/vfat/rootfs.new /mnt/vfat/rootfs >> $LOG 2>> $LOG || ( mv /mnt/vfat/rootfs.old /mnt/vfat/rootfs ; exit_with_error "Command failed: mv /mnt/vfat/rootfs.new /mnt/vfat/rootfs" )
log "Done."
log "Moving new kernel"
mv /mnt/vfat/vmlinuz.new /mnt/vfat/vmlinuz >> $LOG 2>> $LOG || ( mv /mnt/vfat/vmlinuz.old /mnt/vfat/vmlinuz ; exit_with_error "Command failed: mv /mnt/vfat/vmlinuz.new /mnt/vfat/vmlinuz" )
log "Done."
log "Moving new syslinux.cfg"
mv /mnt/vfat/syslinux.new /mnt/vfat/syslinux.cfg >> $LOG 2>> $LOG || ( mv /mnt/vfat/syslinux.old /mnt/vfat/syslinux.cfg ; exit_with_error "Command failed: mv /mnt/vfat/syslinux.new /mnt/vfat/syslinux.cfg" )
log "Done."
#done
log "## Done ##"
#Ok, the update is now installed. The last thing is to update the firmware info
#in the local_config.xml
log "Update firmware version in local_config.xml"
/sbin/calaos_config set "fw_version" "$VERSION" >> $LOG 2>> $LOG
log "version: `/sbin/calaos_config set "fw_version"`"
log "Clean vfat partition."
rm -fr /mnt/vfat/tmp >> $LOG 2>> $LOG
log "Done."
#Do a backup of all config files to the VFAT partition, in case something failed we can restore from here
log "Backup config files"
rm /mnt/vfat/backup_conf.tar.gz -f >> $LOG 2>> $LOG
(cd /etc/calaos/ ;
tar czvf /mnt/vfat/backup_conf.tar.gz * >> $LOG 2>> $LOG
);
log "Done."
#clean old files if any
log "Cleaning old rootfs files..."
rm -f /mnt/vfat/rootfs.old /mnt/vfat/vmlinuz.old /mnt/vfat/syslinux.old >> $LOG 2>> $LOG
log "Done."
#we don't care about all files in /tmp, they'll be erased the next time we boot
log "Unmount vfat filesystem"
umount -n /mnt/vfat/ >> $LOG 2>> $LOG
log "Done."
#tell calaos.fr that we have updated
USER_ID=`/sbin/calaos_config get "calaos_id"`
CALAOS_URL="https://home.calaos.fr:8445/"
VERSION=`/sbin/calaos_config get "fw_version"`
if [ "$USER_ID" != "" ] ; then
wget $CALAOS_URL --post-data "id=$USER_ID&fw_version=$VERSION&set=fw_version" --no-check-certificate --quiet --output-document=/dev/null
fi
log "Sync FS before reboot"
sync >> $LOG 2>> $LOG
reboot