Project

General

Profile

Download (8.42 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
# Set our operating platform
19
PLATFORM=`cat /etc/platform`
20

    
21
HOME=/
22
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
23
export HOME PATH
24

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

    
28
echo
29
cat /etc/ascii-art/pfsense-logo-small.txt
30
echo
31
echo
32
echo "Welcome to pfSense ${version} on the '${PLATFORM}' platform..."
33
echo
34

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

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

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

    
47
# Enable console output if its muted.
48
/sbin/conscontrol mute off >/dev/null
49

    
50
# Mount memory file system if it exists
51
echo -n "Mounting filesystems..."
52
/sbin/mount -a
53

    
54
# Mount /. If it fails run a fsck.
55
if [ ! "$PLATFORM" = "cdrom" ] ; then
56
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
57

    
58
	# If /conf is a directory, convert it to a symlink
59
	# to /cf/conf
60
	if [ -d "/conf" ]; then
61
		# If item is not a symlink then rm and recreate
62
		CONFPOINTSTO=`readlink /conf` 
63
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
64
			rm -rf /conf
65
			ln -s /cf/conf /conf
66
		fi
67
	fi
68
fi
69

    
70
# Check to see if a compact flash mountpoint exists
71
# If it fails to mount then run a fsck -fy
72
if grep -q cf /etc/fstab; then
73
    /sbin/mount -uw /cf || \
74
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
75
fi
76

    
77
if [ "$PLATFORM" = "cdrom" ] ; then
78
	# do nothing for cdrom platform
79
elif [ "$PLATFORM" = "embedded" ] ; then
80
    # do nothing for embedded platform
81
else
82
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
83
    /sbin/swapon -a 2>/dev/null >/dev/null
84
fi
85
echo " done."
86

    
87
if [ "$PLATFORM" = "cdrom" ] ; then
88
	mkdir /tmp/unionfs
89
	mkdir /tmp/unionfs/usr
90
	mkdir /tmp/unionfs/root
91
	echo -n "Mounting unionfs directories:"
92
	echo -n " usr"
93
	mount_unionfs /tmp/unionfs/usr /usr/
94
	echo -n " root"
95
	mount_unionfs /tmp/unionfs/root /root/	
96
	echo "... done."
97
fi
98

    
99
echo -n "Creating symlinks..."
100
# Make sure symlink is correct on embedded
101
if [ "$PLATFORM" = "embedded" ] ; then
102
	rm /conf
103
	ln -s /cf/conf/ /conf
104
fi
105

    
106
# Repair symlinks if they are broken
107
if [ ! -L /etc/syslog.conf ]; then
108
	rm -rf /etc/syslog.conf
109
	ln -s /var/etc/syslog.conf /etc/syslog.conf
110
fi
111

    
112
# Repair symlinks if they are broken
113
if [ ! -L /etc/hosts ]; then
114
	rm -rf /etc/hosts
115
	ln -s /var/etc/hosts /etc/hosts
116
fi
117

    
118
if [ ! -L /etc/resolv.conf ]; then
119
    rm -rf /etc/resolv.conf
120
    ln -s /var/etc/resolv.conf /etc/resolv.conf
121
fi
122

    
123
# Setup compatibility link for packages that
124
# have trouble overriding the PREFIX configure
125
# argument since we build our packages in a
126
# seperated PREFIX area
127
# Only create if symlink does not exist. 
128
if [ ! -h /tmp/tmp ]; then
129
    ln -hfs / /tmp/tmp
130
fi
131

    
132
# Make sure our /tmp is 777
133
chmod 1777 /tmp
134

    
135
if [ ! "$PLATFORM" = "cdrom" ] ; then
136
	# Malloc debugging check
137
	if [ -L /etc/malloc.conf ]; then
138
	    #ln -s aj /etc/malloc.conf
139
		rm /etc/malloc.conf
140
	fi
141
fi
142

    
143
if [ ! -L /etc/dhclient.conf ]; then
144
    rm -rf /etc/dhclient.conf
145
fi
146

    
147
if [ ! -L /etc/sasyncd.conf ]; then
148
    mkdir -p /var/etc/
149
    touch /var/etc/sasyncd.conf
150
    rm -rf /etc/sasyncd.conf
151
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
152
    chown root:wheel /var/etc/sasyncd.conf
153
    chmod 0600 /var/etc/sasyncd.conf
154
fi
155

    
156
if [ ! -d /var/tmp ]; then
157
	mkdir -p /var/tmp
158
fi
159

    
160
if [ ! -d /cf/conf/backup/ ]; then
161
	mkdir -p /cf/conf/backup/ 
162
fi
163

    
164
if [ ! -f /var/db/ez-ipupdate.cache ]; then
165
	touch /var/db/ez-ipupdate.cache
166
fi
167

    
168
# OpenVPN storage
169
if [ ! -d /var/etc/openvpn ]; then
170
	mkdir -p /var/etc/openvpn
171
fi
172
if [ ! -d /var/etc/openvpn-csc ]; then
173
	mkdir -p /var/etc/openvpn-csc
174
fi
175

    
176
set -T
177
trap "echo 'Reboot interrupted'; exit 1" 3
178

    
179
# Remove old nameserver resolution files
180
rm -f /var/etc/nameserver*
181

    
182
# Create uploadbar tmp directory
183
mkdir -p /tmp/uploadbar
184
chmod 777 /tmp/uploadbar
185

    
186
# make some directories in /var
187
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
188
rm /var/log/* 2>/dev/null
189
rm -rf /var/run/*
190

    
191
echo -n "."
192
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
193
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
194
	touch /var/log/system.log
195
	touch /var/log/filter.log
196
	touch /var/log/dhcpd.log
197
	touch /var/log/vpn.log
198
	touch /var/log/openvpn.log
199
	touch /var/log/portalauth.log
200
	touch /var/log/ipsec.log
201
	touch /var/log/relayd.log
202
	touch /var/log/lighttpd.log
203
	touch /var/log/ntpd.log
204
else 
205
	# generate circular logfiles
206
	clog -i -s 512144 /var/log/system.log
207
	clog -i -s 512144 /var/log/filter.log
208
	clog -i -s 65535 /var/log/dhcpd.log
209
	clog -i -s 65535 /var/log/vpn.log
210
	clog -i -s 65535 /var/log/openvpn.log
211
	clog -i -s 65535 /var/log/portalauth.log
212
	clog -i -s 65535 /var/log/ipsec.log
213
	clog -i -s 65535 /var/log/relayd.log
214
	clog -i -s 65535 /var/log/lighttpd.log
215
	clog -i -s 65535 /var/log/ntpd.log
216
fi 
217
# change permissions on newly created clog files.
218
chmod 0600 /var/log/system.log /var/log/filter.log /var/log/dhcpd.log /var/log/vpn.log /var/log/portalauth.log /var/log/relayd.log	
219

    
220
echo -n "."
221
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
222
if [ "$DEVFS" = "0" ]; then
223
    mount_devfs devfs /dev
224
fi
225

    
226
# Create an initial utmp file
227
cd /var/run && cp /dev/null utmp && chmod 644 utmp
228

    
229
echo -n "."
230
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
231

    
232
# Make sure /etc/rc.conf doesn't exist.
233
if [ -f /etc/rc.conf ]; then
234
    rm -rf /etc/rc.conf
235
fi
236

    
237
# Launching kbdmux(4)
238
if [ -f "/dev/kbdmux0" ]; then
239
	echo -n "."
240
	kbdcontrol -k /dev/kbdmux0 < /dev/console
241
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
242
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
243
fi
244

    
245
# Fire up unionfs if mount points exist.
246
if [ -f /dist/uniondirs ]; then
247
	echo -n "."
248
	/etc/rc.d/unionfs start
249
fi
250

    
251
echo "done."
252

    
253
# Recreate capabilities DB
254
cap_mkdb /etc/login.conf
255

    
256
if [ "$PLATFORM" != "cdrom" ]; then
257
	# Populate a dummy php.ini to avoid
258
	# the file being clobbered and the firewall
259
	# not being able to boot back up.
260
	cat >/usr/local/lib/php.ini <<EOF
261
# File generated from /etc/rc
262
output_buffering = "0"
263
implicit_flush = true
264
magic_quotes_gpc = Off
265
max_execution_time = 99999999
266
max_input_time = 99999999
267
register_argc_argv = On
268
file_uploads = On
269
upload_tmp_dir = /tmp
270
upload_max_filesize = 100M
271
post_max_size = 100M
272
html_errors = Off
273
zlib.output_compression = On
274
zlib.output_compression_level = 5
275
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
276
extension_dir=/usr/local/lib/php/20060613/
277

    
278
; add additional extensions below
279
; standard PHP extension
280
extension=pcre.so
281
extension=bz2.so
282
extension=bcmath.so
283
extension=ctype.so
284
extension=curl.so
285
extension=gettext.so
286
extension=mbstring.so
287
extension=mhash.so
288
;extension=openssl.so
289
extension=pcntl.so
290
extension=posix.so
291
extension=readline.so
292
extension=session.so
293
;extension=simplexml.so
294
extension=shmop.so
295
extension=sysvmsg.so
296
extension=sysvsem.so
297
extension=sysvshm.so
298
extension=tokenizer.so
299
extension=xml.so
300
extension=ldap.so
301
extension=zlib.so
302

    
303
; standard PHP extensions currently beeing unused
304
;extension=json.so
305
;extension=ncurses.so
306
;xmlreader.so
307
;xmlwriter.so
308

    
309
;[xdebug]
310
;xdebug.remote_enable = On
311
;xdebug.default_enable = On
312
;xdebug.remote_mode = On
313
;xdebug.remote_handler = dbgp
314
;xdebug.remote_host = 127.0.0.1
315
;xdebug.remote_port = 17869
316
;xdebug.idekey = devphp
317

    
318
EOF
319

    
320
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
321
export RAM
322
if [  $RAM -gt 96 ]; then
323

    
324
cat >>/usr/local/lib/php.ini <<EOF
325
extension=apc.so
326
apc.enabled="1"
327
apc.enable_cli="1"
328
apc.shm_size="25"
329

    
330
EOF
331

    
332
fi
333

    
334

    
335
fi
336

    
337
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
338

    
339
rm -f /cf/conf/backup/backup.cache
340

    
341
# let the PHP-based configuration subsystem set up the system now
342
echo -n "Launching PHP init system..."
343
/etc/rc.bootup
344

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

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

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

    
354
/usr/local/bin/php -f /etc/rc.conf_mount_ro
355

    
356
# Remove stale files that have already been processed by bootup
357
# scripts
358
rm -f /tmp/filter_dirty
359
rm -f /tmp/rc.linkup
360
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status &
361

    
362
# Start ping handler for every 240 seconds
363
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
364

    
365
chmod a+rw /tmp/.
366

    
367
echo "Bootup complete"
368

    
369
/usr/local/bin/beep.sh start 2>&1 >/dev/null
370

    
371
exit 0
(26-26/79)