Project

General

Profile

Download (8.76 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
    # do nothing for nanobsd platform
96
else
97
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
98
    /sbin/swapon -a 2>/dev/null >/dev/null
99
fi
100
echo " done."
101

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

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

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

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

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

    
151
if [ ! -L /etc/resolv.conf ]; then
152
    rm -rf /etc/resolv.conf
153
    ln -s /var/etc/resolv.conf /etc/resolv.conf
154
fi
155

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

    
165
# Make sure our /tmp is 777 + Sticky
166
chmod 1777 /tmp
167

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

    
176
if [ ! -L /etc/dhclient.conf ]; then
177
    rm -rf /etc/dhclient.conf
178
fi
179

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

    
189
if [ ! -d /var/tmp ]; then
190
	mkdir -p /var/tmp
191
fi
192

    
193
if [ ! -d /cf/conf/backup/ ]; then
194
	mkdir -p /cf/conf/backup/ 
195
fi
196

    
197
if [ ! -f /var/db/ez-ipupdate.cache ]; then
198
	touch /var/db/ez-ipupdate.cache
199
fi
200

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

    
209
set -T
210
trap "echo 'Reboot interrupted'; exit 1" 3
211

    
212
# Remove old nameserver resolution files
213
rm -f /var/etc/nameserver*
214

    
215
# Create uploadbar tmp directory
216
mkdir -p /tmp/uploadbar
217
chmod 0777 /tmp/uploadbar
218

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

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

    
268
echo -n "."
269
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
270
if [ "$DEVFS" = "0" ]; then
271
    mount_devfs devfs /dev
272
fi
273

    
274
# Create an initial utmp file
275
cd /var/run && cp /dev/null utmp && chmod 644 utmp
276

    
277
echo -n "."
278
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
279

    
280
# Make sure /etc/rc.conf doesn't exist.
281
if [ -f /etc/rc.conf ]; then
282
    rm -rf /etc/rc.conf
283
fi
284

    
285
# Launching kbdmux(4)
286
if [ -f "/dev/kbdmux0" ]; then
287
	echo -n "."
288
	kbdcontrol -k /dev/kbdmux0 < /dev/console
289
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
290
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
291
fi
292

    
293
# Fire up unionfs if mount points exist.
294
if [ -f /dist/uniondirs ]; then
295
	echo -n "."
296
	/etc/rc.d/unionfs start
297
fi
298

    
299
echo "done."
300

    
301
# Recreate capabilities DB
302
cap_mkdb /etc/login.conf
303

    
304
# Run the php.ini setup file and populate
305
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
306
. /etc/rc.php_ini_setup
307

    
308
# let the PHP-based configuration subsystem set up the system now
309
echo -n "Launching the init system..."
310
rm -f /cf/conf/backup/backup.cache
311
rm -f /root/lighttpd*
312
/etc/rc.bootup
313

    
314
# If a shell was selected from recovery 
315
# console then just drop to the shell now.
316
if [ -f "/tmp/donotbootup" ]; then
317
	echo "Dropping to recovery shell."
318
	exit 0
319
fi
320

    
321
echo -n "Starting CRON... "
322
cd /tmp && /usr/sbin/cron -s 2>/dev/null
323
echo "done."
324

    
325
# Start packages
326
/etc/rc.start_packages
327

    
328
rm -rf /usr/local/pkg/pf/CVS
329

    
330
# Remove stale files that have already been processed by bootup
331
# scripts
332
rm -f /tmp/filter_dirty
333
rm -f /tmp/rc.linkup
334
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
335

    
336
# Start ping handler every 240 seconds
337
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
338

    
339
# Start account expire handler every hour
340
minicron 3600 /var/run/expire_accounts.pid /etc/inc/rc.exipireaccounts
341

    
342
/bin/chmod a+rw /tmp/.
343

    
344
echo "Bootup complete"
345

    
346
/usr/local/bin/beep.sh start 2>&1 >/dev/null
347

    
348
# Reset the cache.  read-only requires this.
349
rm /tmp/config.cache
350

    
351
/etc/rc.conf_mount_ro
352

    
353
exit 0
(30-30/87)