Project

General

Profile

Download (11.3 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
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
92
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
93
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
94

    
95
if [ "$hideplatform" -gt "0" ]; then
96
	platformbanner="" # hide the platform
97
else
98
	platformbanner=" on the '${PLATFORM}' platform"
99
fi
100

    
101
echo
102
cat /etc/ascii-art/pfsense-logo-small.txt
103
echo
104
echo
105
echo "Welcome to ${product} ${version} ${platformbanner} ..."
106
echo
107

    
108
# Enable console output if its muted.
109
/sbin/conscontrol mute off >/dev/null
110

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

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

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

    
151
# Make sure symlink is correct on nanobsd
152
if [ "$PLATFORM" = "nanobsd" ] ; then
153
	/bin/rm /conf
154
	/bin/ln -s /cf/conf/ /conf
155
fi
156

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

    
163
# Repair symlinks if they are broken
164
if [ ! -L /etc/hosts ]; then
165
	/bin/rm -rf /etc/hosts
166
	/bin/ln -s /var/etc/hosts /etc/hosts
167
fi
168

    
169
if [ ! -L /etc/resolv.conf ]; then
170
    /bin/rm -rf /etc/resolv.conf
171
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
172
fi
173

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

    
183
# Make sure our /tmp is 777 + Sticky
184
if [ ! "$PLATFORM" = "cdrom" ] ; then
185
	/bin/rm -rf /tmp/*
186
fi
187
/bin/chmod 1777 /tmp
188

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

    
197
if [ ! -L /etc/dhclient.conf ]; then
198
    /bin/rm -rf /etc/dhclient.conf
199
fi
200

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

    
210
if [ ! -d /var/tmp ]; then
211
	/bin/mkdir -p /var/tmp
212
fi
213

    
214
if [ ! -d /cf/conf/backup/ ]; then
215
	/bin/mkdir -p /cf/conf/backup/ 
216
fi
217

    
218
# OpenVPN storage
219
if [ ! -d /var/etc/openvpn ]; then
220
	/bin/mkdir -p /var/etc/openvpn
221
fi
222
if [ ! -d /var/etc/openvpn-csc ]; then
223
	/bin/mkdir -p /var/etc/openvpn-csc
224
fi
225

    
226
set -T
227
trap "echo 'Reboot interrupted'; exit 1" 3
228

    
229
# Remove old nameserver resolution files
230
/bin/rm -f /var/etc/nameserver*
231

    
232
# Create uploadbar tmp directory
233
/bin/mkdir -p /tmp/uploadbar
234
/bin/chmod 0777 /tmp/uploadbar
235

    
236
# make some directories in /var
237
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
238
/bin/rm /var/log/* 2>/dev/null
239
/bin/rm -rf /var/run/*
240

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

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

    
306
# Create an initial utmp file
307
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
308

    
309
echo -n "."
310
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
311

    
312
# Make sure /etc/rc.conf doesn't exist.
313
if [ -f /etc/rc.conf ]; then
314
    /bin/rm -rf /etc/rc.conf
315
fi
316

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

    
325
# Fire up unionfs if mount points exist.
326
if [ -f /dist/uniondirs ]; then
327
	echo -n "."
328
	/etc/rc.d/unionfs start
329
fi
330

    
331
echo "done."
332

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

    
340
# Recreate capabilities DB
341
/usr/bin/cap_mkdb /etc/login.conf
342

    
343
# Run the php.ini setup file and populate
344
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
345
/etc/rc.php_ini_setup
346

    
347
# Launch external configuration loader for supported platforms
348
if [ "$PLATFORM" = "embedded" ]; then
349
	/usr/local/bin/php -q /etc/ecl.php
350
fi
351

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

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

    
362
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status
363

    
364
# let the PHP-based configuration subsystem set up the system now
365
echo -n "Launching the init system..."
366
/bin/rm -f /cf/conf/backup/backup.cache
367
/bin/rm -f /root/lighttpd*
368
/usr/bin/touch $varrunpath/booting
369
/etc/rc.bootup
370

    
371
# If a shell was selected from recovery 
372
# console then just drop to the shell now.
373
if [ -f "/tmp/donotbootup" ]; then
374
	echo "Dropping to recovery shell."
375
	exit 0
376
fi
377

    
378
echo -n "Starting CRON... "
379
cd /tmp && /usr/sbin/cron -s 2>/dev/null
380
echo "done."
381

    
382
# Start packages
383
/etc/rc.start_packages
384

    
385
/bin/rm -rf /usr/local/pkg/pf/CVS
386

    
387
# Start ping handler every 240 seconds
388
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
389

    
390
# Start account expire handler every hour
391
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
392

    
393
# Start alias url updater every 24 hours
394
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
395

    
396
/bin/chmod a+rw /tmp/.
397

    
398
echo "Bootup complete"
399
/bin/rm $varrunpath/booting
400

    
401
/usr/local/bin/beep.sh start 2>&1 >/dev/null
402

    
403
# Reset the cache.  read-only requires this.
404
/bin/rm /tmp/config.cache
405

    
406
exit 0
(31-31/101)