1
|
#!/bin/sh
|
2
|
|
3
|
# $Id$
|
4
|
# /etc/rc.firmware
|
5
|
# part of m0n0wall (http://neon1.net/m0n0wall)
|
6
|
#
|
7
|
# Copyright (C) 2003 Manuel Kasper <mk@neon1.net>.
|
8
|
# All rights reserved.
|
9
|
|
10
|
#CFDEVICE=`cat /var/etc/cfdevice`
|
11
|
|
12
|
if [ $1 != "upgrade" ]; then
|
13
|
/sbin/umount -f /ftmp > /dev/null 2>&1
|
14
|
fi
|
15
|
|
16
|
backup_chflags() {
|
17
|
TOPROCESS="bin lib libexec sbin usr"
|
18
|
for files in $TOPROCESS; do
|
19
|
/usr/sbin/mtree -Pcp /${files} | bzip2 -9 > /tmp/chflags.dist.${files} | logger -p daemon.info -i -t UpgradeFlags
|
20
|
done
|
21
|
}
|
22
|
|
23
|
restore_chflags() {
|
24
|
TOPROCESS="bin lib libexec sbin usr"
|
25
|
for files in $TOPROCESS; do
|
26
|
cd / && /usr/bin/bzcat /tmp/chflags.dist.${files}.bz2 | /usr/sbin/mtree -PU -p /${files} | logger -p daemon.info -i -t UpgradeFlags
|
27
|
done
|
28
|
}
|
29
|
|
30
|
remove_chflags() {
|
31
|
TOPROCESS="bin lib libexec sbin usr"
|
32
|
for files in $TOPROCESS; do
|
33
|
/bin/chflags -R noschg /${files}
|
34
|
/bin/chmod -R u+rw /${files}
|
35
|
done
|
36
|
}
|
37
|
|
38
|
binary_update() {
|
39
|
TGZ=$1
|
40
|
ERR_F="/tmp/bdiff.log"
|
41
|
rm ${ERR_F} 2>/dev/null
|
42
|
/bin/mkdir /tmp/patched /tmp/patches 2>>${ERR_F}
|
43
|
backup_chflags
|
44
|
remove_chflags
|
45
|
cd /tmp/patches
|
46
|
for i in `/usr/bin/tar tvzf $TGZ | egrep -v "(^d|_md5)" | nawk '{print $9;}'`;
|
47
|
do
|
48
|
FILE=`basename ${i}`
|
49
|
echo "Working on ${i}"
|
50
|
# Untar patch file and md5 files
|
51
|
/usr/bin/tar xzf ${TGZ} ${i} ${i}.old_file_md5 ${i}.new_patch_md5 ${i}.new_file_md5 2>>${ERR_F}
|
52
|
|
53
|
# Apply patch - oldfile newfile patchfile
|
54
|
/usr/local/bin/bspatch /${i} /tmp/patched/${FILE} /tmp/patches/${i} 2>>${ERR_F}
|
55
|
|
56
|
OLD_FILE_MD5=`cat /tmp/patches/${i}.old_file_md5 2>/dev/null`
|
57
|
NEW_PATCH_MD5=`cat /tmp/patches/${i}.new_patch_md5 2>/dev/null`
|
58
|
NEW_FILE_MD5=`cat /tmp/patches/${i}.new_file_md5 2>/dev/null`
|
59
|
PATCHED_MD5=`/sbin/md5 -q /tmp/patched/${FILE} 2>/dev/null`
|
60
|
|
61
|
if [ "$PATCHED_MD5" = "$NEW_PATCH_MD5" ]; then
|
62
|
/usr/bin/install -S /tmp/patched/${FILE} /${i}
|
63
|
else
|
64
|
#echo "${i} file does not match intended final md5."
|
65
|
echo "${i} file does not match intended final md5." >> ${ERR_F}
|
66
|
fi
|
67
|
|
68
|
/bin/rm /tmp/patched/${FILE} >> ${ERR_F}
|
69
|
/bin/rm /tmp/patches/${i} >> ${ERR_F}
|
70
|
/bin/rm /tmp/patches/${i}.* >> ${ERR_F}
|
71
|
done
|
72
|
/bin/rm -rf /tmp/patched /tmp/patches >> ${ERR_F}
|
73
|
restore_chflags
|
74
|
}
|
75
|
|
76
|
case $1 in
|
77
|
enable)
|
78
|
/sbin/mount_mfs -s 15360 -T qp120at -b 8192 -f 1024 dummy /ftmp \
|
79
|
> /dev/null 2>&1
|
80
|
;;
|
81
|
auto)
|
82
|
backup_chflags
|
83
|
remove_chflags
|
84
|
/etc/rc.firmware_auto
|
85
|
restore_chflags
|
86
|
;;
|
87
|
upgrade)
|
88
|
# wait 5 seconds before beginning
|
89
|
sleep 5
|
90
|
backup_chflags
|
91
|
remove_chflags
|
92
|
|
93
|
exec </dev/console >/dev/console 2>/dev/console
|
94
|
|
95
|
echo
|
96
|
echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade
|
97
|
|
98
|
# backup config
|
99
|
mkdir /tmp/configbak
|
100
|
cp -p /conf/* /tmp/configbak
|
101
|
|
102
|
# unmount /cf
|
103
|
/sbin/umount -f /cf
|
104
|
|
105
|
# dd image onto card
|
106
|
if [ -r $2 ]; then
|
107
|
/usr/bin/gunzip -S "" -c $2 | dd of=/dev/r$CFDEVICE bs=16k > /dev/null 2>&1
|
108
|
echo "Image installed."
|
109
|
fi
|
110
|
|
111
|
# mount /cf
|
112
|
/sbin/mount -w -o noatime /cf
|
113
|
|
114
|
# restore config
|
115
|
cp -p /tmp/configbak/* /conf
|
116
|
|
117
|
restore_chflags
|
118
|
|
119
|
rm -f /var/run/firmware.lock
|
120
|
|
121
|
# remount /cf ro
|
122
|
/sbin/umount -f /cf
|
123
|
/sbin/mount -r /cf
|
124
|
|
125
|
echo "Done."
|
126
|
sh /etc/rc.reboot
|
127
|
;;
|
128
|
pfSenseupgrade)
|
129
|
# wait 5 seconds before beginning
|
130
|
sleep 5
|
131
|
|
132
|
# Sanity check - bail early if there's no firmware file!
|
133
|
if [ ! -r $2 ]; then
|
134
|
echo "2nd parameter has not been passed or file does not exist. Exiting." | logger -p daemon.info
|
135
|
-i -t Upgrade
|
136
|
exit
|
137
|
fi
|
138
|
|
139
|
backup_chflags
|
140
|
remove_chflags
|
141
|
|
142
|
#exec </dev/console >/dev/console 2>/dev/console
|
143
|
|
144
|
echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade
|
145
|
|
146
|
# backup config
|
147
|
/bin/mkdir -p /tmp/configbak
|
148
|
cp -p /conf/* /tmp/configbak 2>/dev/null
|
149
|
# mount /cf
|
150
|
/etc/rc.conf_mount_rw
|
151
|
/sbin/mount -w -o noatime /cf 2>/dev/null
|
152
|
/sbin/mount -w -o noatime / 2>/dev/null
|
153
|
|
154
|
# tar explode image onto hd
|
155
|
echo "Installing $2." | logger -p daemon.info -i -t Upgrade
|
156
|
/usr/bin/tar xzPf $2 -U -C / | logger -p daemon.info -i -t Upgrade
|
157
|
/usr/bin/find / -name CVS -exec rm {} \;
|
158
|
echo "Image installed $2." | logger -p daemon.info -i -t Upgrade
|
159
|
|
160
|
# process custom image if its passed
|
161
|
if [ -r $3 ]; then
|
162
|
echo "Custom image $3 found." | logger -p daemon.info -i -t Upgrade
|
163
|
/usr/bin/tar xzPf $3 -U -C / | logger -p daemon.info -i -t Upgrade
|
164
|
echo "Custom image $3 installed." | logger -p daemon.info -i -t Upgrade
|
165
|
fi
|
166
|
|
167
|
# restore config
|
168
|
cp -p /tmp/configbak/* /conf 2>/dev/null
|
169
|
|
170
|
# restore /etc symlinks
|
171
|
rm /etc/hosts
|
172
|
ln -s /var/etc/hosts /etc/hosts
|
173
|
|
174
|
restore_chflags
|
175
|
|
176
|
rm -f /var/run/firmware.lock
|
177
|
|
178
|
# remount /cf ro
|
179
|
/bin/sync
|
180
|
/etc/rc.conf_mount_rw
|
181
|
/sbin/umount -f /cf 2>/dev/null
|
182
|
/sbin/mount -r /cf 2>/dev/null
|
183
|
/sbin/umount -f / 2>/dev/null
|
184
|
/sbin/mount -r / 2>/dev/null
|
185
|
|
186
|
echo "Done." | logger -p daemon.info -i -t Upgrade
|
187
|
sh /etc/rc.reboot
|
188
|
;;
|
189
|
delta_update)
|
190
|
backup_chflags
|
191
|
remove_chflags
|
192
|
binary_update $2
|
193
|
restore_chflags
|
194
|
;;
|
195
|
esac
|
196
|
|
197
|
rm -rf /etc/rc.conf
|
198
|
rm -rf /etc/motd
|
199
|
find / -name CVS -type d -exec rm {} \;
|
200
|
rm -rf /usr/savecore/*
|