summaryrefslogtreecommitdiffstats
path: root/etc/rc.firmware
blob: 93607d70640a1c10031ae5f9ff2ddc5021b665bb (plain)
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

# $Id$
# /etc/rc.firmware
# part of m0n0wall (http://neon1.net/m0n0wall)
#
# Copyright (C) 2003 Manuel Kasper <mk@neon1.net>.
# All rights reserved.

#CFDEVICE=`cat /var/etc/cfdevice`

if [ $1 != "upgrade" ]; then
	/sbin/umount -f /ftmp > /dev/null 2>&1
fi

binary_update() {
	TGZ=$1
	rm /tmp/errors
	mkdir /tmp/patched /tmp/patches
	cd /tmp/patches
	for i in `tar tzf $TGZ | egrep -v "(^d|_md5)" | nawk '{print $9;}'`;
	 do 
	   echo "Working on ${i}"
	   # Untar patch file and md5 files
	   /usr/bin/tar xvzf ${TGZ} ${i} ${i}.old_file_md5 ${i}.new_patch_md5 ${i}.new_file_md5

	   # Apply patch - oldfile newfile patchfile
	   /usr/local/bin/bspatch /${i} /tmp/patched/${i} /tmp/patches/${i}

	   OLD_FILE_MD5=`cat /tmp/patches/${i}.old_file_md5`
	   NEW_PATCH_MD5=`cat /tmp/patches/${i}.new_patch_md5`
	   NEW_FILE_MD5=`cat /tmp/patches/${i}.new_file_md5`
	   PATCHED_MD5=`/sbin/md5 -q /tmp/patched/${i}`

	   if [ "$PATCHED_MD5" = "$NEW_PATCH_MD5" ]; then
		/bin/mv /tmp/patched/${i} /${i}
	   else
		echo "${i} file does not match intended final md5."
		echo "${i} file does not match intended final md5." >> /tmp/errors
	   fi

	   /bin/rm /tmp/patched/${i}
	   /bin/rm /tmp/patches/${i}
	   /bin/rm /tmp/patches/${i}.*
	done
}

case $1 in
enable)
	/sbin/mount_mfs -s 15360 -T qp120at -b 8192 -f 1024 dummy /ftmp \
		> /dev/null 2>&1
	;;
auto)
	/etc/rc.firmware_auto
	;;
upgrade)
	# wait 5 seconds before beginning
	sleep 5

	exec </dev/console >/dev/console 2>/dev/console

	echo
	echo "Firmware upgrade in progress..."  | logger -p daemon.info -i -t Upgrade

	# backup config
	mkdir /tmp/configbak
	cp -p /conf/* /tmp/configbak

	# unmount /cf
	/sbin/umount -f /cf

	# dd image onto card
	if [ -r $2 ]; then
		/usr/bin/gunzip -S "" -c $2 | dd of=/dev/r$CFDEVICE bs=16k > /dev/null 2>&1
		echo "Image installed."
	fi

	# mount /cf
	/sbin/mount -w -o noatime /cf

	# restore config
	cp -p /tmp/configbak/* /conf

	# remount /cf ro
	/sbin/umount -f /cf
	/sbin/mount -r /cf

	echo "Done - rebooting system..."
	/sbin/reboot
	;;
pfSenseupgrade)
	# wait 5 seconds before beginning
	sleep 5

	exec </dev/console >/dev/console 2>/dev/console

	echo "Firmware upgrade in progress..."  | logger -p daemon.info -i -t Upgrade

	# backup config
	mkdir /tmp/configbak
	cp -p /conf/* /tmp/configbak
	# mount /cf
	/sbin/mount -w -o noatime /cf

	# tar explode image onto hd
	if [ -r $2 ]; then
		tar xzPf $2 -U -C / | logger -p daemon.info -i -t Upgrade
		echo "Image installed." | logger -p daemon.info -i -t Upgrade
	fi

        # process custom image if its passed
        if [ -r $3 ]; then
            echo "Custom image $3 found." | logger -p daemon.info -i -t Upgrade
            tar xzPf $3 -U -C / | logger -p daemon.info -i -t Upgrade
            echo "Custom image $3 installed." | logger -p daemon.info -i -t Upgrade
        fi

	# restore config
	cp -p /tmp/configbak/* /conf

	# remount /cf ro
	/sbin/umount -f /cf
	/sbin/mount -r /cf

	echo "Done - rebooting system..." | logger -p daemon.info -i -t Upgrade
	/sbin/shutdown -r now
	;;
pfSense)
	binary_update /tmp/latest.tgz
	;;
pfSense_base)
	binary_update /tmp/latest_base.tgz
	;;
pfSense_kernel)
	binary_update /tmp/latest_kernel.tgz
	;;
esac
OpenPOWER on IntegriCloud