Project

General

Profile

Download (8.98 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2

    
3
# $Id$
4

    
5
# /etc/rc - master bootup script, invokes php setup
6
# part of pfSense by Scott Ullrich
7
# Copyright (C) 2004 Scott Ullrich, All rights reserved.
8
# originally based on m0n0wall (http://neon1.net/m0n0wall)
9
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
# All rights reserved.
11

    
12
#/bin/stty status '^T'
13
#/bin/stty susp '^-' intr '^-' quit '^-'
14

    
15
#trap : 2
16
#trap : 3
17

    
18
HOME=/
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
20
export HOME PATH
21

    
22
# Set our operating platform
23
PLATFORM=`cat /etc/platform`
24

    
25
# Set our current version
26
version=`cat /etc/version`
27

    
28
if [ "$PLATFORM" = "cdrom" ]; then
29
	/etc/rc.cdrom
30
fi
31

    
32
if [ "$PLATFORM" = "embedded" ]; then
33
	/etc/rc.embedded
34
fi
35

    
36
if [ "$PLATFORM" = "nanobsd" ]; then
37
	/etc/rc.embedded
38
fi
39

    
40
if [ "$PLATFORM" = "pfSense" ]; then
41
	mdmfs -S -M -s 4m md /var/run
42
fi
43

    
44
product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4`
45
hideplatform=`cat /etc/inc/globals.inc | grep hideplatform | wc -l`
46

    
47
if [ "$hideplatform" -gt "0" ]; then
48
	platformbanner="" # hide the platform
49
else
50
	platformbanner=" on the '${PLATFORM}' platform"
51
fi
52

    
53
echo
54
cat /etc/ascii-art/pfsense-logo-small.txt
55
echo
56
echo
57
echo "Welcome to ${product} ${version} ${platformbanner} ..."
58
echo
59

    
60
# Enable console output if its muted.
61
/sbin/conscontrol mute off >/dev/null
62

    
63
# Mount memory file system if it exists
64
echo -n "Mounting filesystems..."
65
/sbin/mount -a
66

    
67
# Mount /. If it fails run a fsck.
68
if [ ! "$PLATFORM" = "cdrom" ] ; then
69
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
70

    
71
	# If /conf is a directory, convert it to a symlink
72
	# to /cf/conf
73
	if [ -d "/conf" ]; then
74
		# If item is not a symlink then rm and recreate
75
		CONFPOINTSTO=`readlink /conf` 
76
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
77
			rm -rf /conf
78
			ln -s /cf/conf /conf
79
		fi
80
	fi
81
fi
82

    
83
# Check to see if a compact flash mountpoint exists
84
# If it fails to mount then run a fsck -fy
85
if grep -q cf /etc/fstab; then
86
    /sbin/mount -uw /cf || \
87
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
88
fi
89

    
90
if [ "$PLATFORM" = "cdrom" ] ; then
91
	# do nothing for cdrom platform
92
elif [ "$PLATFORM" = "embedded" ] ; then
93
    # do nothing for embedded platform
94
elif [ "$PLATFORM" = "nanobsd" ] ; then
95
	# Ensure that packages can be persistent across reboots
96
	/bin/mkdir -p /root/var/db/pkg
97
	rm -rf /var/db/pkg
98
	ln -s /root/var/db/pkg/ /var/db/pkg
99
else
100
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
101
    /sbin/swapon -a 2>/dev/null >/dev/null
102
fi
103
echo " done."
104

    
105
if [ "$PLATFORM" = "cdrom" ] ; then
106
	mkdir /tmp/unionfs
107
	mkdir /tmp/unionfs/usr
108
	mkdir /tmp/unionfs/root
109
	mkdir /tmp/unionfs/sbin
110
	mkdir /tmp/unionfs/bin
111
	mkdir /tmp/unionfs/boot
112
	mkdir /tmp/unionfs/confdefault
113
	echo -n "Mounting unionfs directories:"
114
	echo -n " usr"
115
	mount_unionfs /tmp/unionfs/usr /usr/
116
	echo -n " root"
117
	mount_unionfs /tmp/unionfs/root /root/
118
	echo -n " bin"
119
	mount_unionfs /tmp/unionfs/bin /bin/		
120
	echo -n " sbin"
121
	mount_unionfs /tmp/unionfs/sbin /sbin/	
122
	echo -n " boot"
123
	mount_unionfs /tmp/unionfs/boot /boot/
124
	echo -n " conf.default"
125
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
126
	echo "... done."
127
fi
128

    
129
echo -n "Creating symlinks..."
130
# Make sure symlink is correct on embedded
131
if [ "$PLATFORM" = "embedded" ] ; then
132
	rm /conf
133
	ln -s /cf/conf/ /conf
134
fi
135

    
136
# Make sure symlink is correct on nanobsd
137
if [ "$PLATFORM" = "nanobsd" ] ; then
138
	rm /conf
139
	ln -s /cf/conf/ /conf
140
fi
141

    
142
# Repair symlinks if they are broken
143
if [ ! -L /etc/syslog.conf ]; then
144
	rm -rf /etc/syslog.conf
145
	ln -s /var/etc/syslog.conf /etc/syslog.conf
146
fi
147

    
148
# Repair symlinks if they are broken
149
if [ ! -L /etc/hosts ]; then
150
	rm -rf /etc/hosts
151
	ln -s /var/etc/hosts /etc/hosts
152
fi
153

    
154
if [ ! -L /etc/resolv.conf ]; then
155
    rm -rf /etc/resolv.conf
156
    ln -s /var/etc/resolv.conf /etc/resolv.conf
157
fi
158

    
159
# Setup compatibility link for packages that
160
# have trouble overriding the PREFIX configure
161
# argument since we build our packages in a
162
# seperated PREFIX area
163
# Only create if symlink does not exist. 
164
if [ ! -h /tmp/tmp ]; then
165
    ln -hfs / /tmp/tmp
166
fi
167

    
168
# Make sure our /tmp is 777 + Sticky
169
chmod 1777 /tmp
170

    
171
if [ ! "$PLATFORM" = "cdrom" ] ; then
172
	# Malloc debugging check
173
	if [ -L /etc/malloc.conf ]; then
174
	    #ln -s aj /etc/malloc.conf
175
		rm /etc/malloc.conf
176
	fi
177
fi
178

    
179
if [ ! -L /etc/dhclient.conf ]; then
180
    rm -rf /etc/dhclient.conf
181
fi
182

    
183
if [ ! -L /etc/sasyncd.conf ]; then
184
    mkdir -p /var/etc/
185
    touch /var/etc/sasyncd.conf
186
    rm -rf /etc/sasyncd.conf
187
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
188
    chown root:wheel /var/etc/sasyncd.conf
189
    chmod 0600 /var/etc/sasyncd.conf
190
fi
191

    
192
if [ ! -d /var/tmp ]; then
193
	mkdir -p /var/tmp
194
fi
195

    
196
if [ ! -d /cf/conf/backup/ ]; then
197
	mkdir -p /cf/conf/backup/ 
198
fi
199

    
200
if [ ! -f /var/db/ez-ipupdate.cache ]; then
201
	touch /var/db/ez-ipupdate.cache
202
fi
203

    
204
# OpenVPN storage
205
if [ ! -d /var/etc/openvpn ]; then
206
	mkdir -p /var/etc/openvpn
207
fi
208
if [ ! -d /var/etc/openvpn-csc ]; then
209
	mkdir -p /var/etc/openvpn-csc
210
fi
211

    
212
set -T
213
trap "echo 'Reboot interrupted'; exit 1" 3
214

    
215
# Remove old nameserver resolution files
216
rm -f /var/etc/nameserver*
217

    
218
# Create uploadbar tmp directory
219
mkdir -p /tmp/uploadbar
220
chmod 0777 /tmp/uploadbar
221

    
222
# make some directories in /var
223
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
224
rm /var/log/* 2>/dev/null
225
rm -rf /var/run/*
226

    
227
echo -n "."
228
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
229
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
230
	touch /var/log/system.log
231
	touch /var/log/filter.log
232
	touch /var/log/dhcpd.log
233
	touch /var/log/vpn.log
234
	touch /var/log/openvpn.log
235
	touch /var/log/portalauth.log
236
	touch /var/log/ipsec.log
237
	touch /var/log/ppp.log
238
	touch /var/log/relayd.log
239
	touch /var/log/lighttpd.log
240
	touch /var/log/ntpd.log
241
else 
242
	ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
243
	if [ "$ENABLEFIFOLOG" -gt "0" ]; then
244
		# generate fifolog files
245
		/usr/sbin/fifolog_create -s 511488 /var/log/system.log
246
		/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
247
		/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
248
		/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
249
		/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
250
		/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
251
		/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
252
		/usr/sbin/fifolog_create -s 50688 /var/log/ppp.log
253
		/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
254
		/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
255
		/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
256
	else 
257
		/usr/sbin/clog -i -s 512144 /var/log/system.log
258
		/usr/sbin/clog -i -s 512144 /var/log/filter.log
259
		/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
260
		/usr/sbin/clog -i -s 65535 /var/log/vpn.log
261
		/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
262
		/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
263
		/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
264
		/usr/sbin/clog -i -s 65535 /var/log/ppp.log
265
		/usr/sbin/clog -i -s 65535 /var/log/slbd.log
266
		/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
267
		/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
268
		/usr/sbin/clog -i -s 65535 /var/log/relayd.log		
269
	fi
270
fi 
271
# change permissions on newly created fifolog files.
272
chmod 0600 /var/log/*.log
273

    
274
echo -n "."
275
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
276
if [ "$DEVFS" = "0" ]; then
277
    mount_devfs devfs /dev
278
fi
279

    
280
# Create an initial utmp file
281
cd /var/run && cp /dev/null utmp && chmod 644 utmp
282

    
283
echo -n "."
284
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
285

    
286
# Make sure /etc/rc.conf doesn't exist.
287
if [ -f /etc/rc.conf ]; then
288
    rm -rf /etc/rc.conf
289
fi
290

    
291
# Launching kbdmux(4)
292
if [ -f "/dev/kbdmux0" ]; then
293
	echo -n "."
294
	kbdcontrol -k /dev/kbdmux0 < /dev/console
295
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
296
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
297
fi
298

    
299
# Fire up unionfs if mount points exist.
300
if [ -f /dist/uniondirs ]; then
301
	echo -n "."
302
	/etc/rc.d/unionfs start
303
fi
304

    
305
echo "done."
306

    
307
# Recreate capabilities DB
308
cap_mkdb /etc/login.conf
309

    
310
# Run the php.ini setup file and populate
311
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
312
. /etc/rc.php_ini_setup
313

    
314
# let the PHP-based configuration subsystem set up the system now
315
echo -n "Launching the init system..."
316
rm -f /cf/conf/backup/backup.cache
317
rm -f /root/lighttpd*
318
/etc/rc.bootup
319

    
320
# If a shell was selected from recovery 
321
# console then just drop to the shell now.
322
if [ -f "/tmp/donotbootup" ]; then
323
	echo "Dropping to recovery shell."
324
	exit 0
325
fi
326

    
327
echo -n "Starting CRON... "
328
cd /tmp && /usr/sbin/cron -s 2>/dev/null
329
echo "done."
330

    
331
# Start packages
332
/etc/rc.start_packages
333

    
334
rm -rf /usr/local/pkg/pf/CVS
335

    
336
# Remove stale files that have already been processed by bootup
337
# scripts
338
rm -f /tmp/filter_dirty
339
rm -f /tmp/rc.linkup
340
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
341

    
342
# Start ping handler every 240 seconds
343
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
344

    
345
# Start account expire handler every hour
346
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
347

    
348
/bin/chmod a+rw /tmp/.
349

    
350
echo "Bootup complete"
351

    
352
/usr/local/bin/beep.sh start 2>&1 >/dev/null
353

    
354
# Reset the cache.  read-only requires this.
355
rm /tmp/config.cache
356

    
357
/etc/rc.conf_mount_ro
358

    
359
exit 0
(30-30/89)