Project

General

Profile

Download (11.5 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-2010 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=`/bin/cat /etc/platform`
24

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

    
28
# Setup dumpdev/ddb/savecore"
29
echo "Configuring crash dumps..."
30
if [ "$PLATFORM" = "pfSense" ]; then
31
	/etc/rc.dumpon
32
fi
33

    
34
# Mount memory file system if it exists
35
echo "Mounting filesystems..."
36

    
37
# Handle ZFS read-only case
38
if [ "$PLATFORM" = "pfSense" ]; then
39
	if [ -f /usr/bin/grep ]; then
40
		WHEREISROOT=`/sbin/mount | /usr/bin/grep " / " | /usr/bin/grep "tank" | /usr/bin/cut -d' ' -f1`
41
		if [ "$WHEREISROOT" != "" ]; then
42
			/sbin/zfs set readonly=off $WHEREISROOT
43
		fi
44
	fi
45
fi
46

    
47
if [ "$PLATFORM" = "cdrom" ]; then
48
	/etc/rc.cdrom
49
fi
50

    
51
if [ "$PLATFORM" = "embedded" ]; then
52
	export PKG_TMPDIR=/root/
53
	/etc/rc.embedded
54
fi
55

    
56
if [ "$PLATFORM" = "nanobsd" ]; then
57
	export PKG_TMPDIR=/root/
58
	/etc/rc.embedded
59
fi
60

    
61
if [ "$PLATFORM" = "pfSense" ]; then
62
	/sbin/mdmfs -S -M -s 4m md /var/run
63
fi
64

    
65
# Mount /. If it fails run a fsck.
66
if [ ! "$PLATFORM" = "cdrom" ] ; then
67
	if [ "$PLATFORM" = "nanobsd" ]; then
68
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
69
	else 
70
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
71
	fi
72
	# If /conf is a directory, convert it to a symlink 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
			/bin/rm -rf /conf
78
			/bin/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 -w /cf 2>/dev/null
87
    /sbin/mount -uw /cf || \
88
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
89
fi
90

    
91
# sync pw database after mount.
92
rm -f /etc/spwd.db.tmp
93
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
94

    
95
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
96
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
97
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
98

    
99
if [ "$hideplatform" -gt "0" ]; then
100
	platformbanner="" # hide the platform
101
else
102
	platformbanner=" on the '${PLATFORM}' platform"
103
fi
104

    
105
echo
106
cat /etc/ascii-art/pfsense-logo-small.txt
107
echo
108
echo
109
echo "Welcome to ${product} ${version} ${platformbanner} ..."
110
echo
111

    
112
# Enable console output if its muted.
113
/sbin/conscontrol mute off >/dev/null
114

    
115
if [ "$PLATFORM" = "cdrom" ] ; then
116
	# do nothing for cdrom platform
117
elif [ "$PLATFORM" = "embedded" ] ; then
118
    # do nothing for embedded platform
119
elif [ "$PLATFORM" = "nanobsd" ] ; then
120
	# Ensure that packages can be persistent across reboots
121
	/bin/mkdir -p /root/var/db/pkg
122
	/bin/rm -rf /var/db/pkg
123
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
124
else
125
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
126
	/sbin/swapon -a 2>/dev/null >/dev/null
127
	/etc/rc.savecore
128
fi
129

    
130
if [ "$PLATFORM" = "cdrom" ] ; then
131
	echo -n "Mounting unionfs directories..."
132
	/bin/mkdir /tmp/unionfs
133
	/bin/mkdir /tmp/unionfs/usr
134
	/bin/mkdir /tmp/unionfs/root
135
	/bin/mkdir /tmp/unionfs/sbin
136
	/bin/mkdir /tmp/unionfs/bin
137
	/bin/mkdir /tmp/unionfs/boot
138
	/bin/mkdir /tmp/unionfs/confdefault
139
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
140
	/sbin/mount_unionfs /tmp/unionfs/root /root/
141
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
142
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
143
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
144
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
145
	echo "done."
146
fi
147

    
148
echo -n "Creating symlinks..."
149
# Make sure symlink is correct on embedded
150
if [ "$PLATFORM" = "embedded" ] ; then
151
	/bin/rm /conf
152
	/bin/ln -s /cf/conf/ /conf
153
fi
154

    
155
# Make sure symlink is correct on nanobsd
156
if [ "$PLATFORM" = "nanobsd" ] ; then
157
	/bin/rm /conf
158
	/bin/ln -s /cf/conf/ /conf
159
fi
160

    
161
# Repair symlinks if they are broken
162
if [ ! -L /etc/syslog.conf ]; then
163
	/bin/rm -rf /etc/syslog.conf
164
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
165
fi
166

    
167
# Repair symlinks if they are broken
168
if [ ! -L /etc/hosts ]; then
169
	/bin/rm -rf /etc/hosts
170
	/bin/ln -s /var/etc/hosts /etc/hosts
171
fi
172

    
173
if [ ! -L /etc/resolv.conf ]; then
174
    /bin/rm -rf /etc/resolv.conf
175
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
176
fi
177

    
178
# Setup compatibility link for packages that
179
# have trouble overriding the PREFIX configure
180
# argument since we build our packages in a
181
# seperated PREFIX area
182
# Only create if symlink does not exist. 
183
if [ ! -h /tmp/tmp ]; then
184
    /bin/ln -hfs / /tmp/tmp
185
fi
186

    
187
# Make sure our /tmp is 777 + Sticky
188
if [ ! "$PLATFORM" = "cdrom" ] ; then
189
	/bin/rm -rf /tmp/*
190
fi
191
/bin/chmod 1777 /tmp
192

    
193
if [ ! "$PLATFORM" = "cdrom" ] ; then
194
	# Malloc debugging check
195
	if [ -L /etc/malloc.conf ]; then
196
	    #ln -s aj /etc/malloc.conf
197
		/bin/rm /etc/malloc.conf
198
	fi
199
fi
200

    
201
if [ ! -L /etc/dhclient.conf ]; then
202
    /bin/rm -rf /etc/dhclient.conf
203
fi
204

    
205
if [ ! -L /etc/sasyncd.conf ]; then
206
    /bin/mkdir -p /var/etc/
207
    /usr/bin/touch /var/etc/sasyncd.conf
208
    /bin/rm -rf /etc/sasyncd.conf
209
    /bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
210
    /usr/sbin/chown root:wheel /var/etc/sasyncd.conf
211
    /bin/chmod 0600 /var/etc/sasyncd.conf
212
fi
213

    
214
if [ ! -d /var/tmp ]; then
215
	/bin/mkdir -p /var/tmp
216
fi
217

    
218
if [ ! -d /cf/conf/backup/ ]; then
219
	/bin/mkdir -p /cf/conf/backup/ 
220
fi
221

    
222
# OpenVPN storage
223
if [ ! -d /var/etc/openvpn ]; then
224
	/bin/mkdir -p /var/etc/openvpn
225
fi
226
if [ ! -d /var/etc/openvpn-csc ]; then
227
	/bin/mkdir -p /var/etc/openvpn-csc
228
fi
229

    
230
set -T
231
trap "echo 'Reboot interrupted'; exit 1" 3
232

    
233
# Remove old nameserver resolution files
234
/bin/rm -f /var/etc/nameserver*
235

    
236
# Create uploadbar tmp directory
237
/bin/mkdir -p /tmp/uploadbar
238
/bin/chmod 0777 /tmp/uploadbar
239

    
240
# make some directories in /var
241
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
242
/bin/rm /var/log/* 2>/dev/null
243
/bin/rm -rf /var/run/*
244

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

    
304
echo -n "."
305
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
306
if [ "$DEVFS" = "0" ]; then
307
    mount_devfs devfs /dev
308
fi
309

    
310
# Create an initial utmp file
311
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
312

    
313
echo -n "."
314
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
315

    
316
# Make sure /etc/rc.conf doesn't exist.
317
if [ -f /etc/rc.conf ]; then
318
    /bin/rm -rf /etc/rc.conf
319
fi
320

    
321
# Launching kbdmux(4)
322
if [ -f "/dev/kbdmux0" ]; then
323
	echo -n "."
324
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
325
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
326
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
327
fi
328

    
329
# Fire up unionfs if mount points exist.
330
if [ -f /dist/uniondirs ]; then
331
	echo -n "."
332
	/etc/rc.d/unionfs start
333
fi
334

    
335
echo "done."
336

    
337
# Ensure gettytab is of a sane size
338
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
339
	echo ">>> Restoring /etc/gettytab due to unusal size"
340
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
341
	/bin/cp /etc/gettytab.bak /etc/gettytab
342
fi
343

    
344
# Recreate capabilities DB
345
/usr/bin/cap_mkdb /etc/login.conf
346

    
347
# Run the php.ini setup file and populate
348
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
349
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
350

    
351
# Launch external configuration loader for supported platforms
352
if [ "$PLATFORM" = "embedded" ]; then
353
	/usr/local/bin/php -q /etc/ecl.php
354
fi
355

    
356
# Launch external configuration loader for supported platforms
357
if [ "$PLATFORM" = "nanobsd" ]; then
358
	/usr/local/bin/php -q /etc/ecl.php
359
fi
360

    
361
# Launch external configuration loader for supported platforms
362
if [ "$PLATFORM" = "pfSense" ]; then
363
	/usr/local/bin/php -q /etc/ecl.php
364
fi
365

    
366
if [ -f /etc/rc.custom_boot_early ]; then
367
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
368
	/etc/rc.custom_boot_early
369
	echo "Done"
370
fi
371

    
372
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
373

    
374
# let the PHP-based configuration subsystem set up the system now
375
echo -n "Launching the init system..."
376
/bin/rm -f /cf/conf/backup/backup.cache
377
/bin/rm -f /root/lighttpd*
378
/usr/bin/touch $varrunpath/booting
379
/etc/rc.bootup
380

    
381
# If a shell was selected from recovery 
382
# console then just drop to the shell now.
383
if [ -f "/tmp/donotbootup" ]; then
384
	echo "Dropping to recovery shell."
385
	exit 0
386
fi
387

    
388
echo -n "Starting CRON... "
389
cd /tmp && /usr/sbin/cron -s 2>/dev/null
390
echo "done."
391

    
392
# Start packages
393
/etc/rc.start_packages
394

    
395
/bin/rm -rf /usr/local/pkg/pf/CVS
396

    
397
# Start ping handler every 240 seconds
398
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
399

    
400
# Start account expire handler every hour
401
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
402

    
403
# Start alias url updater every 24 hours
404
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
405

    
406
/bin/chmod a+rw /tmp/.
407

    
408
echo "Bootup complete"
409
/bin/rm $varrunpath/booting
410

    
411
/usr/local/bin/beep.sh start 2>&1 >/dev/null
412

    
413
# Reset the cache.  read-only requires this.
414
/bin/rm /tmp/config.cache
415

    
416
exit 0
(33-33/104)