Project

General

Profile

Download (7.61 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
echo -n "Creating symlinks..."
88
# Make sure symlink is correct on embedded
89
if [ "$PLATFORM" = "embedded" ] ; then
90
	rm /conf
91
	ln -s /cf/conf/ /conf
92
fi
93

    
94
# Repair symlinks if they are broken
95
if [ ! -L /etc/syslog.conf ]; then
96
	rm -rf /etc/syslog.conf
97
	ln -s /var/etc/syslog.conf /etc/syslog.conf
98
fi
99

    
100
# Repair symlinks if they are broken
101
if [ ! -L /etc/hosts ]; then
102
	rm -rf /etc/hosts
103
	ln -s /var/etc/hosts /etc/hosts
104
fi
105

    
106
if [ ! -L /etc/resolv.conf ]; then
107
    rm -rf /etc/resolv.conf
108
    ln -s /var/etc/resolv.conf /etc/resolv.conf
109
fi
110

    
111
# Setup compatibility link for packages that
112
# have trouble overriding the PREFIX configure
113
# argument since we build our packages in a
114
# seperated PREFIX area
115
# Only create if symlink does not exist. 
116
if [ ! -h /tmp/tmp ]; then
117
    ln -hfs / /tmp/tmp
118
fi
119

    
120
# Malloc debugging check
121
if [ ! -L /etc/malloc.conf ]; then
122
    ln -s aj /etc/malloc.conf
123
fi
124

    
125
if [ ! -L /etc/dhclient.conf ]; then
126
    rm -rf /etc/dhclient.conf
127
fi
128

    
129
if [ ! -L /etc/sasyncd.conf ]; then
130
    mkdir -p /var/etc/
131
    touch /var/etc/sasyncd.conf
132
    rm -rf /etc/sasyncd.conf
133
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
134
    chown root:wheel /var/etc/sasyncd.conf
135
    chmod 0600 /var/etc/sasyncd.conf
136
fi
137

    
138
[ ! -d /var/tmp ] || mkdir -p /var/tmp 2>/dev/null
139

    
140
[ ! -d /cf/conf/backup/ ] || mkdir -p /cf/conf/backup/ 2>/dev/null
141

    
142
[ ! -f /var/db/ez-ipupdate.cache ] || touch /var/db/ez-ipupdate.cache 2>/dev/null
143

    
144
set -T
145
trap "echo 'Reboot interrupted'; exit 1" 3
146

    
147
# Remove old nameserver resolution files
148
rm -f /var/etc/nameserver*
149

    
150
# Create uploadbar tmp directory
151
mkdir -p /tmp/uploadbar
152
chmod 777 /tmp/uploadbar
153

    
154
# make some directories in /var
155
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
156
rm /var/log/* 2>/dev/null
157
rm -rf /var/run/*
158

    
159
echo -n "."
160
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
161
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
162
	touch /var/log/system.log
163
	touch /var/log/filter.log
164
	touch /var/log/dhcpd.log
165
	touch /var/log/vpn.log
166
	touch /var/log/openvpn.log
167
	touch /var/log/portalauth.log
168
	touch /var/log/ipsec.log
169
	touch /var/log/slbd.log
170
	touch /var/log/lighttpd.log
171
	touch /var/log/ntpd.log
172
else 
173
	# generate circular logfiles
174
	clog -i -s 512144 /var/log/system.log
175
	clog -i -s 512144 /var/log/filter.log
176
	clog -i -s 65535 /var/log/dhcpd.log
177
	clog -i -s 65535 /var/log/vpn.log
178
	clog -i -s 65535 /var/log/openvpn.log
179
	clog -i -s 65535 /var/log/portalauth.log
180
	clog -i -s 65535 /var/log/ipsec.log
181
	clog -i -s 65535 /var/log/slbd.log
182
	clog -i -s 65535 /var/log/lighttpd.log
183
	clog -i -s 65535 /var/log/ntpd.log
184
fi 
185
# change permissions on newly created clog files.
186
chmod 0600 /var/log/system.log /var/log/filter.log /var/log/dhcpd.log /var/log/vpn.log /var/log/portalauth.log /var/log/slbd.log	
187

    
188
echo -n "."
189
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
190
if [ "$DEVFS" = "0" ]; then
191
    mount_devfs devfs /dev
192
fi
193

    
194
# Create an initial utmp file
195
cd /var/run && cp /dev/null utmp && chmod 644 utmp
196

    
197
echo -n "."
198
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
199

    
200
# Make sure /etc/rc.conf doesn't exist.
201
if [ -f /etc/rc.conf ]; then
202
    rm -rf /etc/rc.conf
203
fi
204

    
205
# Launching kbdmux(4)
206
if [ -f "/dev/kbdmux0" ]; then
207
	echo -n "."
208
	kbdcontrol -k /dev/kbdmux0 < /dev/console
209
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
210
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
211
fi
212

    
213
# Fire up unionfs if mount points exist.
214
if [ -f /dist/uniondirs ]; then
215
	echo -n "."
216
	/etc/rc.d/unionfs start
217
fi
218

    
219
echo "done."
220

    
221
# Recreate capabilities DB
222
cap_mkdb /etc/login.conf
223

    
224
if [ "$PLATFORM" != "cdrom" ]; then
225
	# Populate a dummy php.ini to avoid
226
	# the file being clobbered and the firewall
227
	# not being able to boot back up.
228
	cat >/usr/local/lib/php.ini <<EOF
229
# File generated from /etc/rc
230
output_buffering = "0"
231
implicit_flush = true
232
magic_quotes_gpc = Off
233
max_execution_time = 99999999
234
max_input_time = 99999999
235
register_argc_argv = On
236
file_uploads = On
237
upload_tmp_dir = /tmp
238
upload_max_filesize = 100M
239
post_max_size = 100M
240
html_errors = Off
241
zlib.output_compression = On
242
zlib.output_compression_level = 5
243
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
244

    
245
; add additional extensions below
246
; standard PHP extension
247
extension=apc.so
248
extension=pcre.so
249
extension=bz2.so
250
extension=bcmath.so
251
extension=ctype.so
252
extension=curl.so
253
extension=gettext.so
254
extension=mbstring.so
255
extension=pcntl.so
256
extension=posix.so
257
extension=readline.so
258
extension=session.so
259
extension=shmop.so
260
extension=sysvmsg.so
261
extension=sysvsem.so
262
extension=sysvshm.so
263
extension=tokenizer.so
264
extension=xml.so
265
extension=ldap.so
266
extension=zlib.so
267

    
268
; standard PHP extensions currently beeing unused
269
;extension=json.so
270
;extension=ncurses.so
271
;xmlreader.so
272
;xmlwriter.so
273

    
274
;[xdebug]
275
;xdebug.remote_enable = On
276
;xdebug.default_enable = On
277
;xdebug.remote_mode = On
278
;xdebug.remote_handler = dbgp
279
;xdebug.remote_host = 127.0.0.1
280
;xdebug.remote_port = 17869
281
;xdebug.idekey = devphp
282

    
283
apc.enabled="1"
284
apc.enable_cli="1"
285
apc.shm_size="25"
286

    
287
EOF
288

    
289
fi
290

    
291
cp /usr/local/lib/php.ini /usr/local/etc/
292

    
293
rm -f /cf/conf/backup/backup.cache
294

    
295
# let the PHP-based configuration subsystem set up the system now
296
echo -n "Launching PHP init system..."
297
/etc/rc.bootup
298

    
299
echo -n "Starting CRON... "
300
cd /tmp && /usr/sbin/cron -s 2>/dev/null
301
echo "done."
302

    
303
# Start packages
304
/etc/rc.start_packages
305

    
306
rm -rf /usr/local/pkg/pf/CVS
307

    
308
/usr/local/bin/php -f /etc/rc.conf_mount_ro
309

    
310
# Remove stale files that have already been processed by bootup
311
# scripts
312
rm -f /tmp/filter_dirty
313
rm -f /tmp/rc.linkup
314
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status &
315

    
316
# Start ping handler for every 240 seconds
317
minicron 240 /var/run/ping_hosts.pid /etc/ping_hosts.sh
318

    
319
chmod a+rw /tmp/.
320

    
321
echo "Bootup complete"
322

    
323
/usr/local/bin/beep.sh start 2>&1 >/dev/null
324

    
325
exit 0
(25-25/79)