Project

General

Profile

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

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

    
28
# Mount memory file system if it exists
29
echo "Mounting filesystems..."
30

    
31
if [ "$PLATFORM" = "cdrom" ]; then
32
	/etc/rc.cdrom
33
fi
34

    
35
if [ "$PLATFORM" = "embedded" ]; then
36
	/etc/rc.embedded
37
fi
38

    
39
if [ "$PLATFORM" = "nanobsd" ]; then
40
	/etc/rc.embedded
41
fi
42

    
43
if [ "$PLATFORM" = "pfSense" ]; then
44
	mdmfs -S -M -s 4m md /var/run
45
fi
46

    
47
# Mount /. If it fails run a fsck.
48
if [ ! "$PLATFORM" = "cdrom" ] ; then
49
	if [ "$PLATFORM" = "nanobsd" ]; then
50
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
51
	else 
52
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
53
	fi
54
	# If /conf is a directory, convert it to a symlink to /cf/conf
55
	if [ -d "/conf" ]; then
56
		# If item is not a symlink then rm and recreate
57
		CONFPOINTSTO=`readlink /conf` 
58
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
59
			rm -rf /conf
60
			ln -s /cf/conf /conf
61
		fi
62
	fi
63
fi
64

    
65
# Check to see if a compact flash mountpoint exists
66
# If it fails to mount then run a fsck -fy
67
if grep -q cf /etc/fstab; then
68
	/sbin/mount -w /cf 2>/dev/null
69
    /sbin/mount -uw /cf || \
70
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
71
fi
72

    
73
product=`grep product_name /etc/inc/globals.inc | cut -d'"' -f4`
74
hideplatform=`grep hideplatform /etc/inc/globals.inc | wc -l`
75
varrunpath=`grep varrun_path /etc/inc/globals.inc | cut -d'"' -f4`
76

    
77
if [ "$hideplatform" -gt "0" ]; then
78
	platformbanner="" # hide the platform
79
else
80
	platformbanner=" on the '${PLATFORM}' platform"
81
fi
82

    
83
echo
84
cat /etc/ascii-art/pfsense-logo-small.txt
85
echo
86
echo
87
echo "Welcome to ${product} ${version} ${platformbanner} ..."
88
echo
89

    
90
# Enable console output if its muted.
91
/sbin/conscontrol mute off >/dev/null
92

    
93
if [ "$PLATFORM" = "cdrom" ] ; then
94
	# do nothing for cdrom platform
95
elif [ "$PLATFORM" = "embedded" ] ; then
96
    # do nothing for embedded platform
97
elif [ "$PLATFORM" = "nanobsd" ] ; then
98
	# Ensure that packages can be persistent across reboots
99
	/bin/mkdir -p /root/var/db/pkg
100
	rm -rf /var/db/pkg
101
	ln -s /root/var/db/pkg/ /var/db/pkg
102
else
103
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
104
    /sbin/swapon -a 2>/dev/null >/dev/null
105
fi
106

    
107
if [ "$PLATFORM" = "cdrom" ] ; then
108
	mkdir /tmp/unionfs
109
	mkdir /tmp/unionfs/usr
110
	mkdir /tmp/unionfs/root
111
	mkdir /tmp/unionfs/sbin
112
	mkdir /tmp/unionfs/bin
113
	mkdir /tmp/unionfs/boot
114
	mkdir /tmp/unionfs/confdefault
115
	mkdir /tmp/unionfs/PCBSD
116
	echo -n "Mounting unionfs directories:"
117
	echo -n " usr"
118
	mount_unionfs /tmp/unionfs/usr /usr/
119
	echo -n " root"
120
	mount_unionfs /tmp/unionfs/root /root/
121
	echo -n " bin"
122
	mount_unionfs /tmp/unionfs/bin /bin/		
123
	echo -n " sbin"
124
	mount_unionfs /tmp/unionfs/sbin /sbin/	
125
	echo -n " boot"
126
	mount_unionfs /tmp/unionfs/boot /boot/
127
	echo -n " conf.default"
128
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
129
	echo -n " installer"
130
	mount_unionfs /tmp/unionfs/PCBSD /PCBSD/
131
	echo "... done."
132
fi
133

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
321
echo "done."
322

    
323
# Recreate capabilities DB
324
cap_mkdb /etc/login.conf
325

    
326
# Run the php.ini setup file and populate
327
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
328
. /etc/rc.php_ini_setup
329

    
330
# let the PHP-based configuration subsystem set up the system now
331
echo -n "Launching the init system..."
332
rm -f /cf/conf/backup/backup.cache
333
rm -f /root/lighttpd*
334
touch $varrunpath/booting
335
/etc/rc.bootup
336

    
337
# If a shell was selected from recovery 
338
# console then just drop to the shell now.
339
if [ -f "/tmp/donotbootup" ]; then
340
	echo "Dropping to recovery shell."
341
	exit 0
342
fi
343

    
344
echo -n "Starting CRON... "
345
cd /tmp && /usr/sbin/cron -s 2>/dev/null
346
echo "done."
347

    
348
# Start packages
349
/etc/rc.start_packages
350

    
351
rm -rf /usr/local/pkg/pf/CVS
352

    
353
# Remove stale files that have already been processed by bootup
354
# scripts
355
rm -f /tmp/filter_dirty
356
rm -f /tmp/rc.linkup
357
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
358

    
359
# Start ping handler every 240 seconds
360
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
361

    
362
# Start account expire handler every hour
363
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
364

    
365
# Start alias url updater every 24 hours
366
minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
367

    
368
/bin/chmod a+rw /tmp/.
369

    
370
echo "Bootup complete"
371
rm $varrunpath/booting
372

    
373
/usr/local/bin/beep.sh start 2>&1 >/dev/null
374

    
375
# Reset the cache.  read-only requires this.
376
rm /tmp/config.cache
377

    
378
/etc/rc.conf_mount_ro
379

    
380
exit 0
(30-30/94)