1 |
5b237745
|
Scott Ullrich
|
#!/bin/sh
|
2 |
|
|
|
3 |
1b8df11b
|
Bill Marquette
|
# $Id$
|
4 |
5b237745
|
Scott Ullrich
|
# /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 |
18ff56f2
|
Scott Ullrich
|
#CFDEVICE=`cat /var/etc/cfdevice`
|
11 |
5b237745
|
Scott Ullrich
|
|
12 |
|
|
if [ $1 != "upgrade" ]; then
|
13 |
|
|
/sbin/umount -f /ftmp > /dev/null 2>&1
|
14 |
|
|
fi
|
15 |
|
|
|
16 |
704ea918
|
Scott Ullrich
|
backup_chflags() {
|
17 |
3465f09f
|
Scott Ullrich
|
/usr/sbin/mtree -Pcp / | bzip2 -9 > /tmp/chflags.dist.bz2 | logger -p daemon.info -i -t UpgradeFlags
|
18 |
704ea918
|
Scott Ullrich
|
}
|
19 |
|
|
|
20 |
|
|
restore_chflags() {
|
21 |
3465f09f
|
Scott Ullrich
|
cd / && /usr/bin/bzcat /tmp/chflags.dist.bz2 | /usr/sbin/mtree -PU -p / | logger -p daemon.info -i -t UpgradeFlags
|
22 |
704ea918
|
Scott Ullrich
|
}
|
23 |
|
|
|
24 |
|
|
remove_chflags() {
|
25 |
8a1691dd
|
Scott Ullrich
|
/usr/bin/chflags -R noschg /
|
26 |
|
|
/bin/chmod -R u+rw /
|
27 |
704ea918
|
Scott Ullrich
|
}
|
28 |
|
|
|
29 |
e607da61
|
Scott Ullrich
|
binary_update() {
|
30 |
|
|
TGZ=$1
|
31 |
0a5aabe6
|
Colin Smith
|
ERR_F="/tmp/bdiff.log"
|
32 |
9f7369a1
|
Bill Marquette
|
rm ${ERR_F} 2>/dev/null
|
33 |
8a1691dd
|
Scott Ullrich
|
/bin/mkdir /tmp/patched /tmp/patches 2>>${ERR_F}
|
34 |
704ea918
|
Scott Ullrich
|
backup_chflags
|
35 |
|
|
remove_chflags
|
36 |
b8575f61
|
Bill Marquette
|
cd /tmp/patches
|
37 |
316d02b3
|
Scott Ullrich
|
for i in `/usr/bin/tar tvzf $TGZ | egrep -v "(^d|_md5)" | nawk '{print $9;}'`;
|
38 |
3200f985
|
Bill Marquette
|
do
|
39 |
03485a22
|
Bill Marquette
|
FILE=`basename ${i}`
|
40 |
3200f985
|
Bill Marquette
|
echo "Working on ${i}"
|
41 |
e7fb2f76
|
Bill Marquette
|
# Untar patch file and md5 files
|
42 |
9f7369a1
|
Bill Marquette
|
/usr/bin/tar xzf ${TGZ} ${i} ${i}.old_file_md5 ${i}.new_patch_md5 ${i}.new_file_md5 2>>${ERR_F}
|
43 |
e7fb2f76
|
Bill Marquette
|
|
44 |
|
|
# Apply patch - oldfile newfile patchfile
|
45 |
9f7369a1
|
Bill Marquette
|
/usr/local/bin/bspatch /${i} /tmp/patched/${FILE} /tmp/patches/${i} 2>>${ERR_F}
|
46 |
3200f985
|
Bill Marquette
|
|
47 |
9f7369a1
|
Bill Marquette
|
OLD_FILE_MD5=`cat /tmp/patches/${i}.old_file_md5 2>/dev/null`
|
48 |
|
|
NEW_PATCH_MD5=`cat /tmp/patches/${i}.new_patch_md5 2>/dev/null`
|
49 |
|
|
NEW_FILE_MD5=`cat /tmp/patches/${i}.new_file_md5 2>/dev/null`
|
50 |
|
|
PATCHED_MD5=`/sbin/md5 -q /tmp/patched/${FILE} 2>/dev/null`
|
51 |
3200f985
|
Bill Marquette
|
|
52 |
|
|
if [ "$PATCHED_MD5" = "$NEW_PATCH_MD5" ]; then
|
53 |
9f7369a1
|
Bill Marquette
|
/usr/bin/install -S /tmp/patched/${FILE} /${i}
|
54 |
e607da61
|
Scott Ullrich
|
else
|
55 |
9f7369a1
|
Bill Marquette
|
#echo "${i} file does not match intended final md5."
|
56 |
|
|
echo "${i} file does not match intended final md5." >> ${ERR_F}
|
57 |
e607da61
|
Scott Ullrich
|
fi
|
58 |
e7fb2f76
|
Bill Marquette
|
|
59 |
9f7369a1
|
Bill Marquette
|
/bin/rm /tmp/patched/${FILE} >> ${ERR_F}
|
60 |
|
|
/bin/rm /tmp/patches/${i} >> ${ERR_F}
|
61 |
|
|
/bin/rm /tmp/patches/${i}.* >> ${ERR_F}
|
62 |
e607da61
|
Scott Ullrich
|
done
|
63 |
8a1691dd
|
Scott Ullrich
|
/bin/rm -rf /tmp/patched /tmp/patches >> ${ERR_F}
|
64 |
704ea918
|
Scott Ullrich
|
restore_chflags
|
65 |
e607da61
|
Scott Ullrich
|
}
|
66 |
|
|
|
67 |
5b237745
|
Scott Ullrich
|
case $1 in
|
68 |
|
|
enable)
|
69 |
|
|
/sbin/mount_mfs -s 15360 -T qp120at -b 8192 -f 1024 dummy /ftmp \
|
70 |
|
|
> /dev/null 2>&1
|
71 |
|
|
;;
|
72 |
18ff56f2
|
Scott Ullrich
|
auto)
|
73 |
704ea918
|
Scott Ullrich
|
backup_chflags
|
74 |
|
|
remove_chflags
|
75 |
18ff56f2
|
Scott Ullrich
|
/etc/rc.firmware_auto
|
76 |
704ea918
|
Scott Ullrich
|
restore_chflags
|
77 |
18ff56f2
|
Scott Ullrich
|
;;
|
78 |
5b237745
|
Scott Ullrich
|
upgrade)
|
79 |
|
|
# wait 5 seconds before beginning
|
80 |
|
|
sleep 5
|
81 |
704ea918
|
Scott Ullrich
|
backup_chflags
|
82 |
|
|
remove_chflags
|
83 |
|
|
|
84 |
5b237745
|
Scott Ullrich
|
exec </dev/console >/dev/console 2>/dev/console
|
85 |
|
|
|
86 |
|
|
echo
|
87 |
be3239e3
|
Scott Ullrich
|
echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade
|
88 |
5b237745
|
Scott Ullrich
|
|
89 |
|
|
# backup config
|
90 |
|
|
mkdir /tmp/configbak
|
91 |
|
|
cp -p /conf/* /tmp/configbak
|
92 |
|
|
|
93 |
|
|
# unmount /cf
|
94 |
|
|
/sbin/umount -f /cf
|
95 |
|
|
|
96 |
|
|
# dd image onto card
|
97 |
|
|
if [ -r $2 ]; then
|
98 |
|
|
/usr/bin/gunzip -S "" -c $2 | dd of=/dev/r$CFDEVICE bs=16k > /dev/null 2>&1
|
99 |
|
|
echo "Image installed."
|
100 |
|
|
fi
|
101 |
|
|
|
102 |
|
|
# mount /cf
|
103 |
|
|
/sbin/mount -w -o noatime /cf
|
104 |
|
|
|
105 |
|
|
# restore config
|
106 |
|
|
cp -p /tmp/configbak/* /conf
|
107 |
|
|
|
108 |
390c8e72
|
Scott Ullrich
|
restore_chflags
|
109 |
|
|
|
110 |
5b237745
|
Scott Ullrich
|
# remount /cf ro
|
111 |
|
|
/sbin/umount -f /cf
|
112 |
|
|
/sbin/mount -r /cf
|
113 |
|
|
|
114 |
7d894a89
|
Colin Smith
|
echo "Done."
|
115 |
1e7ab453
|
Scott Ullrich
|
sh /etc/rc.reboot
|
116 |
4668f9f7
|
Scott Ullrich
|
;;
|
117 |
|
|
pfSenseupgrade)
|
118 |
|
|
# wait 5 seconds before beginning
|
119 |
|
|
sleep 5
|
120 |
704ea918
|
Scott Ullrich
|
backup_chflags
|
121 |
|
|
remove_chflags
|
122 |
4668f9f7
|
Scott Ullrich
|
|
123 |
|
|
exec </dev/console >/dev/console 2>/dev/console
|
124 |
3db58e13
|
Scott Ullrich
|
|
125 |
be3239e3
|
Scott Ullrich
|
echo "Firmware upgrade in progress..." | logger -p daemon.info -i -t Upgrade
|
126 |
4668f9f7
|
Scott Ullrich
|
|
127 |
|
|
# backup config
|
128 |
7d7bd7ca
|
Scott Ullrich
|
/bin/mkdir -p /tmp/configbak
|
129 |
|
|
cp -p /conf/* /tmp/configbak 2>/dev/null
|
130 |
4668f9f7
|
Scott Ullrich
|
# mount /cf
|
131 |
7d7bd7ca
|
Scott Ullrich
|
/sbin/mount -w -o noatime /cf 2>/dev/null
|
132 |
4668f9f7
|
Scott Ullrich
|
|
133 |
|
|
# tar explode image onto hd
|
134 |
|
|
if [ -r $2 ]; then
|
135 |
0d0a2294
|
Scott Ullrich
|
echo "Installing $2." | logger -p daemon.info -i -t Upgrade
|
136 |
316d02b3
|
Scott Ullrich
|
/usr/bin/tar xzPf $2 -U -C / | logger -p daemon.info -i -t Upgrade
|
137 |
8a1691dd
|
Scott Ullrich
|
/usr/bin/find / -name CVS -exec rm {} \;
|
138 |
316d02b3
|
Scott Ullrich
|
echo "Image installed $2." | logger -p daemon.info -i -t Upgrade
|
139 |
|
|
else
|
140 |
|
|
echo "2nd paramater has not been passed; skipping." | logger -p daemon.info -i -t Upgrade
|
141 |
4668f9f7
|
Scott Ullrich
|
fi
|
142 |
|
|
|
143 |
cbd61550
|
Scott Ullrich
|
# process custom image if its passed
|
144 |
|
|
if [ -r $3 ]; then
|
145 |
|
|
echo "Custom image $3 found." | logger -p daemon.info -i -t Upgrade
|
146 |
316d02b3
|
Scott Ullrich
|
/usr/bin/tar xzPf $3 -U -C / | logger -p daemon.info -i -t Upgrade
|
147 |
cbd61550
|
Scott Ullrich
|
echo "Custom image $3 installed." | logger -p daemon.info -i -t Upgrade
|
148 |
|
|
fi
|
149 |
|
|
|
150 |
4668f9f7
|
Scott Ullrich
|
# restore config
|
151 |
7d7bd7ca
|
Scott Ullrich
|
cp -p /tmp/configbak/* /conf 2>/dev/null
|
152 |
4668f9f7
|
Scott Ullrich
|
|
153 |
6a2b5f1c
|
Scott Ullrich
|
# restore /etc symlinks
|
154 |
|
|
rm /etc/hosts
|
155 |
|
|
ln -s /var/etc/hosts /etc/hosts
|
156 |
|
|
|
157 |
d20aaef3
|
Scott Ullrich
|
# we dont use freebsd's rc, we have our own.
|
158 |
|
|
rm -rf /etc/rc.subr
|
159 |
|
|
rm -rf /etc/rc.d
|
160 |
|
|
|
161 |
390c8e72
|
Scott Ullrich
|
restore_chflags
|
162 |
|
|
|
163 |
4668f9f7
|
Scott Ullrich
|
# remount /cf ro
|
164 |
7d7bd7ca
|
Scott Ullrich
|
/sbin/umount -f /cf 2>/dev/null
|
165 |
|
|
/sbin/mount -r /cf 2>/dev/null
|
166 |
390c8e72
|
Scott Ullrich
|
|
167 |
7d894a89
|
Colin Smith
|
echo "Done." | logger -p daemon.info -i -t Upgrade
|
168 |
1e7ab453
|
Scott Ullrich
|
sh /etc/rc.reboot
|
169 |
5b237745
|
Scott Ullrich
|
;;
|
170 |
f704d5b0
|
Colin Smith
|
delta_update)
|
171 |
704ea918
|
Scott Ullrich
|
backup_chflags
|
172 |
|
|
remove_chflags
|
173 |
89a5f445
|
Colin Smith
|
binary_update $2
|
174 |
704ea918
|
Scott Ullrich
|
restore_chflags
|
175 |
3db58e13
|
Scott Ullrich
|
;;
|
176 |
8b33f440
|
Scott Ullrich
|
esac
|