Project

General

Profile

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

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

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

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

    
49
if [ "$PLATFORM" = "nanobsd" ]; then
50
	/etc/rc.embedded
51
fi
52

    
53
if [ "$PLATFORM" = "pfSense" ]; then
54
	/sbin/mdmfs -S -M -s 4m md /var/run
55
fi
56

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

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

    
83
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
84
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
85
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
86

    
87
if [ "$hideplatform" -gt "0" ]; then
88
	platformbanner="" # hide the platform
89
else
90
	platformbanner=" on the '${PLATFORM}' platform"
91
fi
92

    
93
echo
94
cat /etc/ascii-art/pfsense-logo-small.txt
95
echo
96
echo
97
echo "Welcome to ${product} ${version} ${platformbanner} ..."
98
echo
99

    
100
# Enable console output if its muted.
101
/sbin/conscontrol mute off >/dev/null
102

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

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

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

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

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

    
154
# Repair symlinks if they are broken
155
if [ ! -L /etc/hosts ]; then
156
	/bin/rm -rf /etc/hosts
157
	/bin/ln -s /var/etc/hosts /etc/hosts
158
fi
159

    
160
if [ ! -L /etc/resolv.conf ]; then
161
    /bin/rm -rf /etc/resolv.conf
162
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
163
fi
164

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

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

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

    
188
if [ ! -L /etc/dhclient.conf ]; then
189
    /bin/rm -rf /etc/dhclient.conf
190
fi
191

    
192
if [ ! -L /etc/sasyncd.conf ]; then
193
    /bin/mkdir -p /var/etc/
194
    /usr/bin/touch /var/etc/sasyncd.conf
195
    /bin/rm -rf /etc/sasyncd.conf
196
    /bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
197
    /usr/sbin/chown root:wheel /var/etc/sasyncd.conf
198
    /bin/chmod 0600 /var/etc/sasyncd.conf
199
fi
200

    
201
if [ ! -d /var/tmp ]; then
202
	/bin/mkdir -p /var/tmp
203
fi
204

    
205
if [ ! -d /cf/conf/backup/ ]; then
206
	/bin/mkdir -p /cf/conf/backup/ 
207
fi
208

    
209
# OpenVPN storage
210
if [ ! -d /var/etc/openvpn ]; then
211
	/bin/mkdir -p /var/etc/openvpn
212
fi
213
if [ ! -d /var/etc/openvpn-csc ]; then
214
	/bin/mkdir -p /var/etc/openvpn-csc
215
fi
216

    
217
set -T
218
trap "echo 'Reboot interrupted'; exit 1" 3
219

    
220
# Remove old nameserver resolution files
221
/bin/rm -f /var/etc/nameserver*
222

    
223
# Create uploadbar tmp directory
224
/bin/mkdir -p /tmp/uploadbar
225
/bin/chmod 0777 /tmp/uploadbar
226

    
227
# make some directories in /var
228
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
229
/bin/rm /var/log/* 2>/dev/null
230
/bin/rm -rf /var/run/*
231

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

    
291
echo -n "."
292
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
293
if [ "$DEVFS" = "0" ]; then
294
    mount_devfs devfs /dev
295
fi
296

    
297
# Create an initial utmp file
298
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
299

    
300
echo -n "."
301
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
302

    
303
# Make sure /etc/rc.conf doesn't exist.
304
if [ -f /etc/rc.conf ]; then
305
    /bin/rm -rf /etc/rc.conf
306
fi
307

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

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

    
322
echo "done."
323

    
324
# Ensure gettytab is of a sane size
325
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
326
	echo ">>> Restoring /etc/gettytab due to unusal size"
327
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
328
	/bin/cp /etc/gettytab.bak /etc/gettytab
329
fi
330

    
331
# Recreate capabilities DB
332
/usr/bin/cap_mkdb /etc/login.conf
333

    
334
# Run the php.ini setup file and populate
335
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
336
/etc/rc.php_ini_setup
337

    
338
# Launch external configuration loader for supported platforms
339
if [ "$PLATFORM" = "embedded" ]; then
340
	/usr/local/bin/php -q /etc/ecl.php
341
fi
342

    
343
# Launch external configuration loader for supported platforms
344
if [ "$PLATFORM" = "nanobsd" ]; then
345
	/usr/local/bin/php -q /etc/ecl.php
346
fi
347

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

    
353
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status
354

    
355
# let the PHP-based configuration subsystem set up the system now
356
echo -n "Launching the init system..."
357
/bin/rm -f /cf/conf/backup/backup.cache
358
/bin/rm -f /root/lighttpd*
359
/usr/bin/touch $varrunpath/booting
360
/etc/rc.bootup
361

    
362
# If a shell was selected from recovery 
363
# console then just drop to the shell now.
364
if [ -f "/tmp/donotbootup" ]; then
365
	echo "Dropping to recovery shell."
366
	exit 0
367
fi
368

    
369
echo -n "Starting CRON... "
370
cd /tmp && /usr/sbin/cron -s 2>/dev/null
371
echo "done."
372

    
373
# Start packages
374
/etc/rc.start_packages
375

    
376
/bin/rm -rf /usr/local/pkg/pf/CVS
377

    
378
# Start ping handler every 240 seconds
379
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
380

    
381
# Start account expire handler every hour
382
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
383

    
384
# Start alias url updater every 24 hours
385
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
386

    
387
/bin/chmod a+rw /tmp/.
388

    
389
echo "Bootup complete"
390
/bin/rm $varrunpath/booting
391

    
392
/usr/local/bin/beep.sh start 2>&1 >/dev/null
393

    
394
# Reset the cache.  read-only requires this.
395
/bin/rm /tmp/config.cache
396

    
397
/etc/rc.conf_mount_ro
398

    
399
exit 0
(31-31/99)