Project

General

Profile

Download (8.85 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
product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4`
28

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

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

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

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

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

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

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

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

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

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

    
88
if [ "$PLATFORM" = "cdrom" ] ; then
89
	mkdir /tmp/unionfs
90
	mkdir /tmp/unionfs/usr
91
	mkdir /tmp/unionfs/root
92
	mkdir /tmp/unionfs/sbin
93
	mkdir /tmp/unionfs/bin
94
	mkdir /tmp/unionfs/boot
95
	mkdir /tmp/unionfs/confdefault
96
	echo -n "Mounting unionfs directories:"
97
	echo -n " usr"
98
	mount_unionfs /tmp/unionfs/usr /usr/
99
	echo -n " root"
100
	mount_unionfs /tmp/unionfs/root /root/
101
	echo -n " bin"
102
	mount_unionfs /tmp/unionfs/bin /bin/		
103
	echo -n " sbin"
104
	mount_unionfs /tmp/unionfs/sbin /sbin/	
105
	echo -n " boot"
106
	mount_unionfs /tmp/unionfs/boot /boot/
107
	echo -n " conf.default"
108
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
109
	echo "... done."
110
fi
111

    
112
echo -n "Creating symlinks..."
113
# Make sure symlink is correct on embedded
114
if [ "$PLATFORM" = "embedded" ] ; then
115
	rm /conf
116
	ln -s /cf/conf/ /conf
117
fi
118

    
119
# Repair symlinks if they are broken
120
if [ ! -L /etc/syslog.conf ]; then
121
	rm -rf /etc/syslog.conf
122
	ln -s /var/etc/syslog.conf /etc/syslog.conf
123
fi
124

    
125
# Repair symlinks if they are broken
126
if [ ! -L /etc/hosts ]; then
127
	rm -rf /etc/hosts
128
	ln -s /var/etc/hosts /etc/hosts
129
fi
130

    
131
if [ ! -L /etc/resolv.conf ]; then
132
    rm -rf /etc/resolv.conf
133
    ln -s /var/etc/resolv.conf /etc/resolv.conf
134
fi
135

    
136
# Setup compatibility link for packages that
137
# have trouble overriding the PREFIX configure
138
# argument since we build our packages in a
139
# seperated PREFIX area
140
# Only create if symlink does not exist. 
141
if [ ! -h /tmp/tmp ]; then
142
    ln -hfs / /tmp/tmp
143
fi
144

    
145
# Make sure our /tmp is 777 + Sticky
146
chmod 1777 /tmp
147

    
148
if [ ! "$PLATFORM" = "cdrom" ] ; then
149
	# Malloc debugging check
150
	if [ -L /etc/malloc.conf ]; then
151
	    #ln -s aj /etc/malloc.conf
152
		rm /etc/malloc.conf
153
	fi
154
fi
155

    
156
if [ ! -L /etc/dhclient.conf ]; then
157
    rm -rf /etc/dhclient.conf
158
fi
159

    
160
if [ ! -L /etc/sasyncd.conf ]; then
161
    mkdir -p /var/etc/
162
    touch /var/etc/sasyncd.conf
163
    rm -rf /etc/sasyncd.conf
164
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
165
    chown root:wheel /var/etc/sasyncd.conf
166
    chmod 0600 /var/etc/sasyncd.conf
167
fi
168

    
169
if [ ! -d /var/tmp ]; then
170
	mkdir -p /var/tmp
171
fi
172

    
173
if [ ! -d /cf/conf/backup/ ]; then
174
	mkdir -p /cf/conf/backup/ 
175
fi
176

    
177
if [ ! -f /var/db/ez-ipupdate.cache ]; then
178
	touch /var/db/ez-ipupdate.cache
179
fi
180

    
181
# OpenVPN storage
182
if [ ! -d /var/etc/openvpn ]; then
183
	mkdir -p /var/etc/openvpn
184
fi
185
if [ ! -d /var/etc/openvpn-csc ]; then
186
	mkdir -p /var/etc/openvpn-csc
187
fi
188

    
189
set -T
190
trap "echo 'Reboot interrupted'; exit 1" 3
191

    
192
# Remove old nameserver resolution files
193
rm -f /var/etc/nameserver*
194

    
195
# Create uploadbar tmp directory
196
mkdir -p /tmp/uploadbar
197
chmod 0777 /tmp/uploadbar
198

    
199
# make some directories in /var
200
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
201
rm /var/log/* 2>/dev/null
202
rm -rf /var/run/*
203

    
204
echo -n "."
205
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
206
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
207
	touch /var/log/system.log
208
	touch /var/log/filter.log
209
	touch /var/log/dhcpd.log
210
	touch /var/log/vpn.log
211
	touch /var/log/openvpn.log
212
	touch /var/log/portalauth.log
213
	touch /var/log/ipsec.log
214
	touch /var/log/relayd.log
215
	touch /var/log/lighttpd.log
216
	touch /var/log/ntpd.log
217
else 
218
	# generate circular logfiles
219
	clog -i -s 512144 /var/log/system.log
220
	clog -i -s 512144 /var/log/filter.log
221
	clog -i -s 65535 /var/log/dhcpd.log
222
	clog -i -s 65535 /var/log/vpn.log
223
	clog -i -s 65535 /var/log/openvpn.log
224
	clog -i -s 65535 /var/log/portalauth.log
225
	clog -i -s 65535 /var/log/ipsec.log
226
	clog -i -s 65535 /var/log/relayd.log
227
	clog -i -s 65535 /var/log/lighttpd.log
228
	clog -i -s 65535 /var/log/ntpd.log
229
fi 
230
# change permissions on newly created clog files.
231
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	
232

    
233
echo -n "."
234
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
235
if [ "$DEVFS" = "0" ]; then
236
    mount_devfs devfs /dev
237
fi
238

    
239
# Create an initial utmp file
240
cd /var/run && cp /dev/null utmp && chmod 644 utmp
241

    
242
echo -n "."
243
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
244

    
245
# Make sure /etc/rc.conf doesn't exist.
246
if [ -f /etc/rc.conf ]; then
247
    rm -rf /etc/rc.conf
248
fi
249

    
250
# Launching kbdmux(4)
251
if [ -f "/dev/kbdmux0" ]; then
252
	echo -n "."
253
	kbdcontrol -k /dev/kbdmux0 < /dev/console
254
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
255
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
256
fi
257

    
258
# Fire up unionfs if mount points exist.
259
if [ -f /dist/uniondirs ]; then
260
	echo -n "."
261
	/etc/rc.d/unionfs start
262
fi
263

    
264
echo "done."
265

    
266
# Recreate capabilities DB
267
cap_mkdb /etc/login.conf
268

    
269
if [ "$PLATFORM" != "cdrom" ]; then
270
	# Populate a dummy php.ini to avoid
271
	# the file being clobbered and the firewall
272
	# not being able to boot back up.
273
	cat >/usr/local/lib/php.ini <<EOF
274
# File generated from /etc/rc
275
output_buffering = "0"
276
implicit_flush = true
277
magic_quotes_gpc = Off
278
max_execution_time = 99999999
279
max_input_time = 99999999
280
register_argc_argv = On
281
file_uploads = On
282
upload_tmp_dir = /tmp
283
upload_max_filesize = 100M
284
post_max_size = 100M
285
html_errors = Off
286
zlib.output_compression = On
287
zlib.output_compression_level = 5
288
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
289
extension_dir=/usr/local/lib/php/20060613/
290

    
291
; add additional extensions below
292
; standard PHP extension
293
extension=pcre.so
294
extension=bz2.so
295
extension=bcmath.so
296
extension=ctype.so
297
extension=curl.so
298
extension=gettext.so
299
extension=mbstring.so
300
extension=mhash.so
301
;extension=openssl.so
302
extension=pcntl.so
303
extension=posix.so
304
extension=readline.so
305
extension=session.so
306
;extension=simplexml.so
307
extension=shmop.so
308
extension=sysvmsg.so
309
extension=sysvsem.so
310
extension=sysvshm.so
311
extension=tokenizer.so
312
extension=xml.so
313
extension=ldap.so
314
extension=zlib.so
315

    
316
; standard PHP extensions currently beeing unused
317
;extension=json.so
318
;extension=ncurses.so
319
;xmlreader.so
320
;xmlwriter.so
321

    
322
;[xdebug]
323
;xdebug.remote_enable = On
324
;xdebug.default_enable = On
325
;xdebug.remote_mode = On
326
;xdebug.remote_handler = dbgp
327
;xdebug.remote_host = 127.0.0.1
328
;xdebug.remote_port = 17869
329
;xdebug.idekey = devphp
330

    
331
EOF
332

    
333
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
334
export RAM
335
if [  $RAM -gt 96 ]; then
336

    
337
cat >>/usr/local/lib/php.ini <<EOF
338
extension=apc.so
339
apc.enabled="1"
340
apc.enable_cli="1"
341
apc.shm_size="25"
342

    
343
EOF
344

    
345
fi
346

    
347

    
348
fi
349

    
350
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
351

    
352
rm -f /cf/conf/backup/backup.cache
353

    
354
# let the PHP-based configuration subsystem set up the system now
355
echo -n "Launching PHP init system..."
356
/etc/rc.bootup
357

    
358
echo -n "Starting CRON... "
359
cd /tmp && /usr/sbin/cron -s 2>/dev/null
360
echo "done."
361

    
362
# Start packages
363
/etc/rc.start_packages
364

    
365
rm -rf /usr/local/pkg/pf/CVS
366

    
367
/usr/local/bin/php -f /etc/rc.conf_mount_ro
368

    
369
# Remove stale files that have already been processed by bootup
370
# scripts
371
rm -f /tmp/filter_dirty
372
rm -f /tmp/rc.linkup
373
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status &
374

    
375
# Start ping handler for every 240 seconds
376
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
377

    
378
chmod a+rw /tmp/.
379

    
380
echo "Bootup complete"
381

    
382
/usr/local/bin/beep.sh start 2>&1 >/dev/null
383

    
384
exit 0
(30-30/83)