Project

General

Profile

Download (12.1 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
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
84
/etc/rc.disable_hdd_apm
85

    
86
if [ ! "$PLATFORM" = "jail" ]; then
87
	# Check to see if a compact flash mountpoint exists
88
	# If it fails to mount then run a fsck -fy
89
	if grep -q cf /etc/fstab; then
90
		/sbin/mount -w /cf 2>/dev/null
91
		/sbin/mount -uw /cf || \
92
			(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
93
	fi
94
fi
95

    
96
# sync pw database after mount.
97
rm -f /etc/spwd.db.tmp
98
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
99

    
100
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
101
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
102
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
103

    
104
if [ "$hideplatform" -gt "0" ]; then
105
	platformbanner="" # hide the platform
106
else
107
	platformbanner=" on the '${PLATFORM}' platform"
108
fi
109

    
110
echo
111
cat /etc/ascii-art/pfsense-logo-small.txt
112
echo
113
echo
114
echo "Welcome to ${product} ${version} ${platformbanner} ..."
115
echo
116

    
117
if [ ! "$PLATFORM" = "jail" ]; then
118
	# Enable console output if its muted.
119
	/sbin/conscontrol mute off >/dev/null
120
fi
121

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

    
139
if [ "$PLATFORM" = "cdrom" ] ; then
140
	echo -n "Mounting unionfs directories..."
141
	/bin/mkdir /tmp/unionfs
142
	/bin/mkdir /tmp/unionfs/usr
143
	/bin/mkdir /tmp/unionfs/root
144
	/bin/mkdir /tmp/unionfs/sbin
145
	/bin/mkdir /tmp/unionfs/bin
146
	/bin/mkdir /tmp/unionfs/boot
147
	/bin/mkdir /tmp/unionfs/confdefault
148
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
149
	/sbin/mount_unionfs /tmp/unionfs/root /root/
150
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
151
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
152
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
153
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
154
	echo "done."
155
fi
156

    
157
echo -n "Creating symlinks..."
158
# Make sure symlink is correct on embedded
159
if [ "$PLATFORM" = "embedded" ] ; then
160
	/bin/rm /conf
161
	/bin/ln -s /cf/conf/ /conf
162
fi
163

    
164
# Make sure symlink is correct on nanobsd
165
if [ "$PLATFORM" = "nanobsd" ] ; then
166
	/bin/rm /conf
167
	/bin/ln -s /cf/conf/ /conf
168
fi
169

    
170
# Repair symlinks if they are broken
171
if [ ! -L /etc/syslog.conf ]; then
172
	/bin/rm -rf /etc/syslog.conf
173
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
174
fi
175

    
176
# Repair symlinks if they are broken
177
if [ ! -L /etc/hosts ]; then
178
	/bin/rm -rf /etc/hosts
179
	/bin/ln -s /var/etc/hosts /etc/hosts
180
fi
181

    
182
if [ ! -L /etc/resolv.conf ]; then
183
    /bin/rm -rf /etc/resolv.conf
184
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
185
fi
186

    
187
# Setup compatibility link for packages that
188
# have trouble overriding the PREFIX configure
189
# argument since we build our packages in a
190
# seperated PREFIX area
191
# Only create if symlink does not exist. 
192
if [ ! -h /tmp/tmp ]; then
193
    /bin/ln -hfs / /tmp/tmp
194
fi
195

    
196
# Make sure our /tmp is 777 + Sticky
197
if [ ! "$PLATFORM" = "cdrom" ] ; then
198
	/bin/rm -rf /tmp/*
199
fi
200
/bin/chmod 1777 /tmp
201

    
202
if [ ! "$PLATFORM" = "cdrom" ] ; then
203
	# Malloc debugging check
204
	if [ -L /etc/malloc.conf ]; then
205
	    #ln -s aj /etc/malloc.conf
206
		/bin/rm /etc/malloc.conf
207
	fi
208
fi
209

    
210
if [ ! -L /etc/dhclient.conf ]; then
211
    /bin/rm -rf /etc/dhclient.conf
212
fi
213

    
214
if [ ! -L /etc/sasyncd.conf ]; then
215
    /bin/mkdir -p /var/etc/
216
    /usr/bin/touch /var/etc/sasyncd.conf
217
    /bin/rm -rf /etc/sasyncd.conf
218
    /bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
219
    /usr/sbin/chown root:wheel /var/etc/sasyncd.conf
220
    /bin/chmod 0600 /var/etc/sasyncd.conf
221
fi
222

    
223
if [ ! -d /var/tmp ]; then
224
	/bin/mkdir -p /var/tmp
225
fi
226

    
227
if [ ! -d /cf/conf/backup/ ]; then
228
	/bin/mkdir -p /cf/conf/backup/ 
229
fi
230

    
231
# OpenVPN storage
232
if [ ! -d /var/etc/openvpn ]; then
233
	/bin/mkdir -p /var/etc/openvpn
234
fi
235
if [ ! -d /var/etc/openvpn-csc ]; then
236
	/bin/mkdir -p /var/etc/openvpn-csc
237
fi
238

    
239
set -T
240
trap "echo 'Reboot interrupted'; exit 1" 3
241

    
242
# Remove old nameserver resolution files
243
/bin/rm -f /var/etc/nameserver*
244

    
245
# Create uploadbar tmp directory
246
/bin/mkdir -p /tmp/uploadbar
247
/bin/chmod 0777 /tmp/uploadbar
248

    
249
# make some directories in /var
250
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
251
/bin/rm /var/log/* 2>/dev/null
252
/bin/rm -rf /var/run/*
253

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

    
316
echo -n "."
317
if [ ! "$PLATFORM" = "jail" ]; then
318
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
319
	if [ "$DEVFS" = "0" ]; then
320
		mount_devfs devfs /dev
321
	fi
322
fi
323

    
324
# Create an initial utmp file
325
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
326

    
327
echo -n "."
328
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
329

    
330
# Make sure /etc/rc.conf doesn't exist.
331
if [ -f /etc/rc.conf ]; then
332
    /bin/rm -rf /etc/rc.conf
333
fi
334

    
335
if [ ! "$PLATFORM" = "jail" ]; then
336
	# Launching kbdmux(4)
337
	if [ -f "/dev/kbdmux0" ]; then
338
		echo -n "."
339
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
340
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
341
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
342
	fi
343

    
344
	# Fire up unionfs if mount points exist.
345
	if [ -f /dist/uniondirs ]; then
346
		echo -n "."
347
		/etc/rc.d/unionfs start
348
	fi
349
fi
350

    
351
echo "done."
352

    
353
# Ensure gettytab is of a sane size
354
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
355
	echo ">>> Restoring /etc/gettytab due to unusal size"
356
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
357
	/bin/cp /etc/gettytab.bak /etc/gettytab
358
fi
359

    
360
# Recreate capabilities DB
361
/usr/bin/cap_mkdb /etc/login.conf
362

    
363
# Run the php.ini setup file and populate
364
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
365
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
366

    
367
# Launch external configuration loader for supported platforms
368
if [ "$PLATFORM" = "embedded" ]; then
369
	/usr/local/bin/php -q /etc/ecl.php
370
fi
371

    
372
# Launch external configuration loader for supported platforms
373
if [ "$PLATFORM" = "nanobsd" ]; then
374
	/usr/local/bin/php -q /etc/ecl.php
375
fi
376

    
377
# Launch external configuration loader for supported platforms
378
if [ "$PLATFORM" = "pfSense" ]; then
379
	/usr/local/bin/php -q /etc/ecl.php
380
fi
381

    
382
if [ -f /etc/rc.custom_boot_early ]; then
383
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
384
	/etc/rc.custom_boot_early
385
	echo "Done"
386
fi
387

    
388
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
389

    
390
# let the PHP-based configuration subsystem set up the system now
391
echo -n "Launching the init system..."
392
/bin/rm -f /cf/conf/backup/backup.cache
393
/bin/rm -f /root/lighttpd*
394
/usr/bin/touch $varrunpath/booting
395
/etc/rc.bootup
396

    
397
# If a shell was selected from recovery 
398
# console then just drop to the shell now.
399
if [ -f "/tmp/donotbootup" ]; then
400
	echo "Dropping to recovery shell."
401
	exit 0
402
fi
403

    
404
echo -n "Starting CRON... "
405
cd /tmp && /usr/sbin/cron -s 2>/dev/null
406
echo "done."
407

    
408
# Start packages
409
/etc/rc.start_packages
410

    
411
/bin/rm -rf /usr/local/pkg/pf/CVS
412

    
413
# Start ping handler every 240 seconds
414
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
415

    
416
# Start account expire handler every hour
417
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
418

    
419
# Start alias url updater every 24 hours
420
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
421

    
422
/bin/chmod a+rw /tmp/.
423

    
424
echo "Bootup complete"
425
/bin/rm $varrunpath/booting
426

    
427
/usr/local/bin/beep.sh start 2>&1 >/dev/null
428

    
429
# Reset the cache.  read-only requires this.
430
/bin/rm -f /tmp/config.cache
431

    
432
exit 0
(34-34/107)