Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

    
179
if [ ! -L /etc/resolv.conf ]; then
180
    /bin/rm -rf /etc/resolv.conf
181
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
182
fi
183

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

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

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

    
207
if [ ! -L /etc/dhclient.conf ]; then
208
    /bin/rm -rf /etc/dhclient.conf
209
fi
210

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

    
220
if [ ! -d /var/tmp ]; then
221
	/bin/mkdir -p /var/tmp
222
fi
223

    
224
if [ ! -d /cf/conf/backup/ ]; then
225
	/bin/mkdir -p /cf/conf/backup/ 
226
fi
227

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

    
236
set -T
237
trap "echo 'Reboot interrupted'; exit 1" 3
238

    
239
# Remove old nameserver resolution files
240
/bin/rm -f /var/etc/nameserver*
241

    
242
# Create uploadbar tmp directory
243
/bin/mkdir -p /tmp/uploadbar
244
/bin/chmod 0777 /tmp/uploadbar
245

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

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

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

    
321
# Create an initial utmp file
322
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
323

    
324
echo -n "."
325
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
326

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

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

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

    
348
echo "done."
349

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

    
357
# Recreate capabilities DB
358
/usr/bin/cap_mkdb /etc/login.conf
359

    
360
# Run the php.ini setup file and populate
361
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
362
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
363

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

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

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

    
379
if [ -f /etc/rc.custom_boot_early ]; then
380
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
381
	/etc/rc.custom_boot_early
382
	echo "Done"
383
fi
384

    
385
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
386

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

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

    
401
echo -n "Starting CRON... "
402
cd /tmp && /usr/sbin/cron -s 2>/dev/null
403
echo "done."
404

    
405
# Start packages
406
/etc/rc.start_packages
407

    
408
/bin/rm -rf /usr/local/pkg/pf/CVS
409

    
410
# Start ping handler every 240 seconds
411
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
412

    
413
# Start account expire handler every hour
414
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
415

    
416
# Start alias url updater every 24 hours
417
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
418

    
419
/bin/chmod a+rw /tmp/.
420

    
421
echo "Bootup complete"
422
/bin/rm $varrunpath/booting
423

    
424
/usr/local/bin/beep.sh start 2>&1 >/dev/null
425

    
426
# Reset the cache.  read-only requires this.
427
/bin/rm -f /tmp/config.cache
428

    
429
exit 0
(34-34/106)