Project

General

Profile

Download (10 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
# Mount memory file system if it exists
29
echo "Mounting filesystems..."
30

    
31
# Handle ZFS read-only case
32
WHEREISROOT=`/sbin/mount | /usr/bin/grep " / " | /usr/bin/grep "tank" | /usr/bin/cut -d' ' -f1`
33
if [ "$WHEREISROOT" != "" ]; then
34
	/sbin/zfs set readonly=off $WHEREISROOT
35
fi
36

    
37
if [ "$PLATFORM" = "cdrom" ]; then
38
	/etc/rc.cdrom
39
fi
40

    
41
if [ "$PLATFORM" = "embedded" ]; then
42
	/etc/rc.embedded
43
fi
44

    
45
if [ "$PLATFORM" = "nanobsd" ]; then
46
	/etc/rc.embedded
47
fi
48

    
49
if [ "$PLATFORM" = "pfSense" ]; then
50
	mdmfs -S -M -s 4m md /var/run
51
fi
52

    
53
# Mount /. If it fails run a fsck.
54
if [ ! "$PLATFORM" = "cdrom" ] ; then
55
	if [ "$PLATFORM" = "nanobsd" ]; then
56
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
57
	else 
58
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
59
	fi
60
	# If /conf is a directory, convert it to a symlink to /cf/conf
61
	if [ -d "/conf" ]; then
62
		# If item is not a symlink then rm and recreate
63
		CONFPOINTSTO=`readlink /conf` 
64
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
65
			rm -rf /conf
66
			ln -s /cf/conf /conf
67
		fi
68
	fi
69
fi
70

    
71
# Check to see if a compact flash mountpoint exists
72
# If it fails to mount then run a fsck -fy
73
if grep -q cf /etc/fstab; then
74
	/sbin/mount -w /cf 2>/dev/null
75
    /sbin/mount -uw /cf || \
76
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
77
fi
78

    
79
product=`grep product_name /etc/inc/globals.inc | cut -d'"' -f4`
80
hideplatform=`grep hideplatform /etc/inc/globals.inc | wc -l`
81
varrunpath=`grep varrun_path /etc/inc/globals.inc | cut -d'"' -f4`
82

    
83
if [ "$hideplatform" -gt "0" ]; then
84
	platformbanner="" # hide the platform
85
else
86
	platformbanner=" on the '${PLATFORM}' platform"
87
fi
88

    
89
echo
90
cat /etc/ascii-art/pfsense-logo-small.txt
91
echo
92
echo
93
echo "Welcome to ${product} ${version} ${platformbanner} ..."
94
echo
95

    
96
# Enable console output if its muted.
97
/sbin/conscontrol mute off >/dev/null
98

    
99
if [ "$PLATFORM" = "cdrom" ] ; then
100
	# do nothing for cdrom platform
101
elif [ "$PLATFORM" = "embedded" ] ; then
102
    # do nothing for embedded platform
103
elif [ "$PLATFORM" = "nanobsd" ] ; then
104
	# Ensure that packages can be persistent across reboots
105
	/bin/mkdir -p /root/var/db/pkg
106
	rm -rf /var/db/pkg
107
	ln -s /root/var/db/pkg/ /var/db/pkg
108
else
109
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
110
    /sbin/swapon -a 2>/dev/null >/dev/null
111
fi
112

    
113
if [ "$PLATFORM" = "cdrom" ] ; then
114
	mkdir /tmp/unionfs
115
	mkdir /tmp/unionfs/usr
116
	mkdir /tmp/unionfs/root
117
	mkdir /tmp/unionfs/sbin
118
	mkdir /tmp/unionfs/bin
119
	mkdir /tmp/unionfs/boot
120
	mkdir /tmp/unionfs/confdefault
121
	echo -n "Mounting unionfs directories:"
122
	echo -n " usr"
123
	mount_unionfs /tmp/unionfs/usr /usr/
124
	echo -n " root"
125
	mount_unionfs /tmp/unionfs/root /root/
126
	echo -n " bin"
127
	mount_unionfs /tmp/unionfs/bin /bin/		
128
	echo -n " sbin"
129
	mount_unionfs /tmp/unionfs/sbin /sbin/	
130
	echo -n " boot"
131
	mount_unionfs /tmp/unionfs/boot /boot/
132
	echo -n " conf.default"
133
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
134
	echo -n " installer"
135
	echo "... done."
136
fi
137

    
138
echo -n "Creating symlinks..."
139
# Make sure symlink is correct on embedded
140
if [ "$PLATFORM" = "embedded" ] ; then
141
	rm /conf
142
	ln -s /cf/conf/ /conf
143
fi
144

    
145
# Make sure symlink is correct on nanobsd
146
if [ "$PLATFORM" = "nanobsd" ] ; then
147
	rm /conf
148
	ln -s /cf/conf/ /conf
149
fi
150

    
151
# Repair symlinks if they are broken
152
if [ ! -L /etc/syslog.conf ]; then
153
	rm -rf /etc/syslog.conf
154
	ln -s /var/etc/syslog.conf /etc/syslog.conf
155
fi
156

    
157
# Repair symlinks if they are broken
158
if [ ! -L /etc/hosts ]; then
159
	rm -rf /etc/hosts
160
	ln -s /var/etc/hosts /etc/hosts
161
fi
162

    
163
if [ ! -L /etc/resolv.conf ]; then
164
    rm -rf /etc/resolv.conf
165
    ln -s /var/etc/resolv.conf /etc/resolv.conf
166
fi
167

    
168
# Setup compatibility link for packages that
169
# have trouble overriding the PREFIX configure
170
# argument since we build our packages in a
171
# seperated PREFIX area
172
# Only create if symlink does not exist. 
173
if [ ! -h /tmp/tmp ]; then
174
    ln -hfs / /tmp/tmp
175
fi
176

    
177
# Make sure our /tmp is 777 + Sticky
178
if [ ! "$PLATFORM" = "cdrom" ] ; then
179
	rm -rf /tmp/*
180
fi
181
chmod 1777 /tmp
182

    
183
if [ ! "$PLATFORM" = "cdrom" ] ; then
184
	# Malloc debugging check
185
	if [ -L /etc/malloc.conf ]; then
186
	    #ln -s aj /etc/malloc.conf
187
		rm /etc/malloc.conf
188
	fi
189
fi
190

    
191
if [ ! -L /etc/dhclient.conf ]; then
192
    rm -rf /etc/dhclient.conf
193
fi
194

    
195
if [ ! -L /etc/sasyncd.conf ]; then
196
    mkdir -p /var/etc/
197
    touch /var/etc/sasyncd.conf
198
    rm -rf /etc/sasyncd.conf
199
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
200
    chown root:wheel /var/etc/sasyncd.conf
201
    chmod 0600 /var/etc/sasyncd.conf
202
fi
203

    
204
if [ ! -d /var/tmp ]; then
205
	mkdir -p /var/tmp
206
fi
207

    
208
if [ ! -d /cf/conf/backup/ ]; then
209
	mkdir -p /cf/conf/backup/ 
210
fi
211

    
212
# OpenVPN storage
213
if [ ! -d /var/etc/openvpn ]; then
214
	mkdir -p /var/etc/openvpn
215
fi
216
if [ ! -d /var/etc/openvpn-csc ]; then
217
	mkdir -p /var/etc/openvpn-csc
218
fi
219

    
220
set -T
221
trap "echo 'Reboot interrupted'; exit 1" 3
222

    
223
# Remove old nameserver resolution files
224
rm -f /var/etc/nameserver*
225

    
226
# Create uploadbar tmp directory
227
mkdir -p /tmp/uploadbar
228
chmod 0777 /tmp/uploadbar
229

    
230
# make some directories in /var
231
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
232
rm /var/log/* 2>/dev/null
233
rm -rf /var/run/*
234

    
235
echo -n "."
236
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
237
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
238
	touch /var/log/system.log
239
	touch /var/log/filter.log
240
	touch /var/log/dhcpd.log
241
	touch /var/log/vpn.log
242
	touch /var/log/pptp.log
243
	touch /var/log/pppoe.log
244
	touch /var/log/l2tp.log
245
	touch /var/log/openvpn.log
246
	touch /var/log/portalauth.log
247
	touch /var/log/ipsec.log
248
	touch /var/log/ppp.log
249
	touch /var/log/relayd.log
250
	touch /var/log/lighttpd.log
251
	touch /var/log/ntpd.log
252
	touch /var/log/apinger.log
253
else 
254
	ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
255
	if [ "$ENABLEFIFOLOG" -gt "0" ]; then
256
		# generate fifolog files
257
		/usr/sbin/fifolog_create -s 511488 /var/log/system.log
258
		/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
259
		/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
260
		/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
261
		/usr/sbin/fifolog_create -s 50688 /var/log/pptp.log
262
		/usr/sbin/fifolog_create -s 50688 /var/log/pppoe.log
263
		/usr/sbin/fifolog_create -s 50688 /var/log/l2tp.log
264
		/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
265
		/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
266
		/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
267
		/usr/sbin/fifolog_create -s 50688 /var/log/ppp.log
268
		/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
269
		/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
270
		/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
271
		/usr/sbin/fifolog_create -s 50688 /var/log/apinger.log
272
	else 
273
		/usr/sbin/clog -i -s 512144 /var/log/system.log
274
		/usr/sbin/clog -i -s 512144 /var/log/filter.log
275
		/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
276
		/usr/sbin/clog -i -s 65535 /var/log/vpn.log
277
		/usr/sbin/clog -i -s 50688 /var/log/pptp.log
278
		/usr/sbin/clog -i -s 50688 /var/log/pppoe.log
279
		/usr/sbin/clog -i -s 50688 /var/log/l2tp.log
280
		/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
281
		/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
282
		/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
283
		/usr/sbin/clog -i -s 65535 /var/log/ppp.log
284
		/usr/sbin/clog -i -s 65535 /var/log/slbd.log
285
		/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
286
		/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
287
		/usr/sbin/clog -i -s 65535 /var/log/relayd.log	
288
		/usr/sbin/clog -i -s 65535 /var/log/apinger.log	
289
	fi
290
fi 
291
# change permissions on newly created fifolog files.
292
chmod 0600 /var/log/*.log
293

    
294
echo -n "."
295
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
296
if [ "$DEVFS" = "0" ]; then
297
    mount_devfs devfs /dev
298
fi
299

    
300
# Create an initial utmp file
301
cd /var/run && cp /dev/null utmp && chmod 644 utmp
302

    
303
echo -n "."
304
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
305

    
306
# Make sure /etc/rc.conf doesn't exist.
307
if [ -f /etc/rc.conf ]; then
308
    rm -rf /etc/rc.conf
309
fi
310

    
311
# Launching kbdmux(4)
312
if [ -f "/dev/kbdmux0" ]; then
313
	echo -n "."
314
	kbdcontrol -k /dev/kbdmux0 < /dev/console
315
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
316
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
317
fi
318

    
319
# Fire up unionfs if mount points exist.
320
if [ -f /dist/uniondirs ]; then
321
	echo -n "."
322
	/etc/rc.d/unionfs start
323
fi
324

    
325
echo "done."
326

    
327
# Recreate capabilities DB
328
cap_mkdb /etc/login.conf
329

    
330
# Run the php.ini setup file and populate
331
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
332
. /etc/rc.php_ini_setup
333

    
334
# let the PHP-based configuration subsystem set up the system now
335
echo -n "Launching the init system..."
336
rm -f /cf/conf/backup/backup.cache
337
rm -f /root/lighttpd*
338
touch $varrunpath/booting
339
/etc/rc.bootup
340

    
341
# If a shell was selected from recovery 
342
# console then just drop to the shell now.
343
if [ -f "/tmp/donotbootup" ]; then
344
	echo "Dropping to recovery shell."
345
	exit 0
346
fi
347

    
348
echo -n "Starting CRON... "
349
cd /tmp && /usr/sbin/cron -s 2>/dev/null
350
echo "done."
351

    
352
# Start packages
353
/etc/rc.start_packages
354

    
355
rm -rf /usr/local/pkg/pf/CVS
356

    
357
# Remove stale files that have already been processed by bootup
358
# scripts
359
rm -f /tmp/filter_dirty
360
rm -f /tmp/rc.linkup
361
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
362

    
363
# Start ping handler every 240 seconds
364
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
365

    
366
# Start account expire handler every hour
367
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
368

    
369
# Start alias url updater every 24 hours
370
minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
371

    
372
/bin/chmod a+rw /tmp/.
373

    
374
echo "Bootup complete"
375
rm $varrunpath/booting
376

    
377
/usr/local/bin/beep.sh start 2>&1 >/dev/null
378

    
379
# Reset the cache.  read-only requires this.
380
rm /tmp/config.cache
381

    
382
/etc/rc.conf_mount_ro
383

    
384
exit 0
(30-30/97)