Project

General

Profile

Download (9.47 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
if [ "$PLATFORM" = "cdrom" ]; then
29
	/etc/rc.cdrom
30
fi
31

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

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

    
40
if [ "$PLATFORM" = "pfSense" ]; then
41
	mdmfs -S -M -s 4m md /var/run
42
fi
43

    
44
product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4`
45
hideplatform=`cat /etc/inc/globals.inc | grep hideplatform | wc -l`
46

    
47
if [ "$hideplatform" -gt "0" ]; then
48
	platformbanner="" # hide the platform
49
else
50
	platformbanner=" on the '${PLATFORM}' platform"
51
fi
52

    
53
echo
54
cat /etc/ascii-art/pfsense-logo-small.txt
55
echo
56
echo
57
echo "Welcome to ${product} ${version} ${platformbanner} ..."
58
echo
59

    
60
# Enable console output if its muted.
61
/sbin/conscontrol mute off >/dev/null
62

    
63
# Mount memory file system if it exists
64
echo -n "Mounting filesystems..."
65
/sbin/mount -a
66

    
67
# Mount /. If it fails run a fsck.
68
if [ ! "$PLATFORM" = "cdrom" ] ; then
69
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
70

    
71
	# If /conf is a directory, convert it to a symlink
72
	# 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
			rm -rf /conf
78
			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 -uw /cf || \
87
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
88
fi
89

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

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

    
129
echo -n "Creating symlinks..."
130
# Make sure symlink is correct on embedded
131
if [ "$PLATFORM" = "embedded" ] ; then
132
	rm /conf
133
	ln -s /cf/conf/ /conf
134
fi
135

    
136
# Make sure symlink is correct on nanobsd
137
if [ "$PLATFORM" = "nanobsd" ] ; then
138
	rm /conf
139
	ln -s /cf/conf/ /conf
140
fi
141

    
142
# Repair symlinks if they are broken
143
if [ ! -L /etc/syslog.conf ]; then
144
	rm -rf /etc/syslog.conf
145
	ln -s /var/etc/syslog.conf /etc/syslog.conf
146
fi
147

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

    
154
if [ ! -L /etc/resolv.conf ]; then
155
    rm -rf /etc/resolv.conf
156
    ln -s /var/etc/resolv.conf /etc/resolv.conf
157
fi
158

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

    
168
# Make sure our /tmp is 777 + Sticky
169
chmod 1777 /tmp
170

    
171
if [ ! "$PLATFORM" = "cdrom" ] ; then
172
	# Malloc debugging check
173
	if [ -L /etc/malloc.conf ]; then
174
	    #ln -s aj /etc/malloc.conf
175
		rm /etc/malloc.conf
176
	fi
177
fi
178

    
179
if [ ! -L /etc/dhclient.conf ]; then
180
    rm -rf /etc/dhclient.conf
181
fi
182

    
183
if [ ! -L /etc/sasyncd.conf ]; then
184
    mkdir -p /var/etc/
185
    touch /var/etc/sasyncd.conf
186
    rm -rf /etc/sasyncd.conf
187
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
188
    chown root:wheel /var/etc/sasyncd.conf
189
    chmod 0600 /var/etc/sasyncd.conf
190
fi
191

    
192
if [ ! -d /var/tmp ]; then
193
	mkdir -p /var/tmp
194
fi
195

    
196
if [ ! -d /cf/conf/backup/ ]; then
197
	mkdir -p /cf/conf/backup/ 
198
fi
199

    
200
if [ ! -f /var/db/ez-ipupdate.cache ]; then
201
	touch /var/db/ez-ipupdate.cache
202
fi
203

    
204
# OpenVPN storage
205
if [ ! -d /var/etc/openvpn ]; then
206
	mkdir -p /var/etc/openvpn
207
fi
208
if [ ! -d /var/etc/openvpn-csc ]; then
209
	mkdir -p /var/etc/openvpn-csc
210
fi
211

    
212
set -T
213
trap "echo 'Reboot interrupted'; exit 1" 3
214

    
215
# Remove old nameserver resolution files
216
rm -f /var/etc/nameserver*
217

    
218
# Create uploadbar tmp directory
219
mkdir -p /tmp/uploadbar
220
chmod 0777 /tmp/uploadbar
221

    
222
# make some directories in /var
223
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
224
rm /var/log/* 2>/dev/null
225
rm -rf /var/run/*
226

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

    
283
echo -n "."
284
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
285
if [ "$DEVFS" = "0" ]; then
286
    mount_devfs devfs /dev
287
fi
288

    
289
# Create an initial utmp file
290
cd /var/run && cp /dev/null utmp && chmod 644 utmp
291

    
292
echo -n "."
293
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
294

    
295
# Make sure /etc/rc.conf doesn't exist.
296
if [ -f /etc/rc.conf ]; then
297
    rm -rf /etc/rc.conf
298
fi
299

    
300
# Launching kbdmux(4)
301
if [ -f "/dev/kbdmux0" ]; then
302
	echo -n "."
303
	kbdcontrol -k /dev/kbdmux0 < /dev/console
304
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
305
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
306
fi
307

    
308
# Fire up unionfs if mount points exist.
309
if [ -f /dist/uniondirs ]; then
310
	echo -n "."
311
	/etc/rc.d/unionfs start
312
fi
313

    
314
echo "done."
315

    
316
# Recreate capabilities DB
317
cap_mkdb /etc/login.conf
318

    
319
# Run the php.ini setup file and populate
320
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
321
. /etc/rc.php_ini_setup
322

    
323
# let the PHP-based configuration subsystem set up the system now
324
echo -n "Launching the init system..."
325
rm -f /cf/conf/backup/backup.cache
326
rm -f /root/lighttpd*
327
/etc/rc.bootup
328

    
329
# If a shell was selected from recovery 
330
# console then just drop to the shell now.
331
if [ -f "/tmp/donotbootup" ]; then
332
	echo "Dropping to recovery shell."
333
	exit 0
334
fi
335

    
336
echo -n "Starting CRON... "
337
cd /tmp && /usr/sbin/cron -s 2>/dev/null
338
echo "done."
339

    
340
# Start packages
341
/etc/rc.start_packages
342

    
343
rm -rf /usr/local/pkg/pf/CVS
344

    
345
# Remove stale files that have already been processed by bootup
346
# scripts
347
rm -f /tmp/filter_dirty
348
rm -f /tmp/rc.linkup
349
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
350

    
351
# Start ping handler every 240 seconds
352
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
353

    
354
# Start account expire handler every hour
355
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
356

    
357
# Start alias url updater every 24 hours
358
minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
359

    
360
/bin/chmod a+rw /tmp/.
361

    
362
echo "Bootup complete"
363

    
364
/usr/local/bin/beep.sh start 2>&1 >/dev/null
365

    
366
# Reset the cache.  read-only requires this.
367
rm /tmp/config.cache
368

    
369
/etc/rc.conf_mount_ro
370

    
371
exit 0
(30-30/93)