Project

General

Profile

Download (8.15 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/bin/sh
2
3 3b6a207d Scott Ullrich
# $Id$
4
5 e5cd29a0 Scott Ullrich
# /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 5b237745 Scott Ullrich
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
# All rights reserved.
11 d8a2ce2c Scott Ullrich
12
#/bin/stty status '^T'
13
#/bin/stty susp '^-' intr '^-' quit '^-'
14
15
#trap : 2
16
#trap : 3
17 5b237745 Scott Ullrich
18 31849b90 Scott Ullrich
# Set our operating platform
19
PLATFORM=`cat /etc/platform`
20 c0819d14 Jeb Campbell
21 5b237745 Scott Ullrich
HOME=/
22 ce823053 Scott Ullrich
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
23 5b237745 Scott Ullrich
export HOME PATH
24
25 d4556e07 Scott Ullrich
# Set our current version
26 3f38f066 Scott Ullrich
version=`cat /etc/version`
27
28 e5cd29a0 Scott Ullrich
echo
29 25d3fbd5 Scott Ullrich
cat /etc/ascii-art/pfsense-logo-small.txt
30
echo
31 d67c6097 Scott Ullrich
echo
32
echo "Welcome to pfSense ${version} on the '${PLATFORM}' platform..."
33
echo
34 e5cd29a0 Scott Ullrich
35 31540677 Colin Smith
if [ "$PLATFORM" = "cdrom" ]; then
36
	/etc/rc.cdrom
37
fi
38
39 16469df3 Scott Ullrich
if [ "$PLATFORM" = "embedded" ]; then
40 c613b74f Scott Ullrich
	/etc/rc.embedded
41
fi
42
43 c1688281 Seth Mos
if [ "$PLATFORM" = "pfSense" ]; then
44
	mdmfs -S -M -s 2m md /var/run
45
fi
46
47 d5f60dba Scott Ullrich
# Enable console output if its muted.
48
/sbin/conscontrol mute off >/dev/null
49
50 16469df3 Scott Ullrich
# Mount memory file system if it exists
51 ebe6a739 Scott Ullrich
echo -n "Mounting filesystems..."
52 16469df3 Scott Ullrich
/sbin/mount -a
53
54 3311566f Scott Ullrich
# Mount /. If it fails run a fsck.
55 625dda09 Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
56 581daddc Scott Ullrich
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
57 fac17748 Scott Ullrich
58
	# If /conf is a directory, convert it to a symlink
59
	# to /cf/conf
60
	if [ -d "/conf" ]; then
61 98ef7bf1 Scott Ullrich
		# If item is not a symlink then rm and recreate
62 15d5221d Scott Ullrich
		CONFPOINTSTO=`readlink /conf` 
63
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
64 98ef7bf1 Scott Ullrich
			rm -rf /conf
65
			ln -s /cf/conf /conf
66
		fi
67 fac17748 Scott Ullrich
	fi
68 625dda09 Scott Ullrich
fi
69 fe1936d1 Scott Ullrich
70 3311566f Scott Ullrich
# Check to see if a compact flash mountpoint exists
71 581daddc Scott Ullrich
# If it fails to mount then run a fsck -fy
72 16469df3 Scott Ullrich
if grep -q cf /etc/fstab; then
73 faaa6942 Scott Ullrich
    /sbin/mount -uw /cf || \
74 581daddc Scott Ullrich
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
75 16125d1c Scott Ullrich
fi
76
77 5621d2d5 Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
78
	# do nothing for cdrom platform
79
elif [ "$PLATFORM" = "embedded" ] ; then
80 f92e9ff3 Scott Ullrich
    # do nothing for embedded platform
81 c0819d14 Jeb Campbell
else
82 d8a2ce2c Scott Ullrich
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
83 7050e57c Scott Ullrich
    /sbin/swapon -a 2>/dev/null >/dev/null
84 98546a74 Scott Ullrich
fi
85 ebe6a739 Scott Ullrich
echo " done."
86 5621d2d5 Scott Ullrich
87 2e269da2 Scott Ullrich
echo -n "Creating symlinks..."
88 895ecb35 Scott Ullrich
# Make sure symlink is correct on embedded
89
if [ "$PLATFORM" = "embedded" ] ; then
90
	rm /conf
91 4e7b2b27 Scott Ullrich
	ln -s /cf/conf/ /conf
92 895ecb35 Scott Ullrich
fi
93
94 6bab150e Scott Ullrich
# 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 f1cc2287 Scott Ullrich
# Repair symlinks if they are broken
101
if [ ! -L /etc/hosts ]; then
102
	rm -rf /etc/hosts
103 4e7b2b27 Scott Ullrich
	ln -s /var/etc/hosts /etc/hosts
104 c8fcdb2f Scott Ullrich
fi
105 095d04db Scott Ullrich
106 f1cc2287 Scott Ullrich
if [ ! -L /etc/resolv.conf ]; then
107
    rm -rf /etc/resolv.conf
108 4e7b2b27 Scott Ullrich
    ln -s /var/etc/resolv.conf /etc/resolv.conf
109 f1cc2287 Scott Ullrich
fi
110 095d04db Scott Ullrich
111 230787e7 Scott Ullrich
# 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 eb03f14e Chris Buechler
# Only create if symlink does not exist. 
116
if [ ! -h /tmp/tmp ]; then
117
    ln -hfs / /tmp/tmp
118
fi
119 230787e7 Scott Ullrich
120 0652f3ae Seth Mos
# Make sure our /tmp is 777
121
chmod 1777 /tmp
122
123 dd64811a Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
124
	# Malloc debugging check
125
	if [ -L /etc/malloc.conf ]; then
126
	    #ln -s aj /etc/malloc.conf
127
		rm /etc/malloc.conf
128
	fi
129 cecdf31c Scott Ullrich
fi
130
131 6484bb83 Scott Ullrich
if [ ! -L /etc/dhclient.conf ]; then
132
    rm -rf /etc/dhclient.conf
133
fi
134 c8fcdb2f Scott Ullrich
135 bfe6d078 Scott Ullrich
if [ ! -L /etc/sasyncd.conf ]; then
136 b8c835d2 Scott Ullrich
    mkdir -p /var/etc/
137 bfe6d078 Scott Ullrich
    touch /var/etc/sasyncd.conf
138
    rm -rf /etc/sasyncd.conf
139
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
140 84f68d65 Scott Ullrich
    chown root:wheel /var/etc/sasyncd.conf
141 bfe6d078 Scott Ullrich
    chmod 0600 /var/etc/sasyncd.conf
142
fi
143
144 4aa70cd8 Scott Ullrich
[ ! -d /var/tmp ] || mkdir -p /var/tmp 2>/dev/null
145
146 69588d92 Scott Ullrich
[ ! -d /cf/conf/backup/ ] || mkdir -p /cf/conf/backup/ 2>/dev/null
147 d42c2e20 Scott Ullrich
148 09c2529d Scott Ullrich
[ ! -f /var/db/ez-ipupdate.cache ] || touch /var/db/ez-ipupdate.cache 2>/dev/null
149
150 9f85112d Scott Ullrich
# OpenVPN storage
151 359e3f6a Scott Ullrich
if [ ! -d /var/etc/openvpn ]; then
152
	mkdir -p /var/etc/openvpn
153
fi
154
if [ ! -d /var/etc/openvpn-csc ]; then
155
	mkdir -p /var/etc/openvpn-csc
156
fi
157 67df0c62 Scott Ullrich
158 5b237745 Scott Ullrich
set -T
159
trap "echo 'Reboot interrupted'; exit 1" 3
160
161 61f1e2ec Scott Ullrich
# Remove old nameserver resolution files
162
rm -f /var/etc/nameserver*
163
164 f3677fc5 Scott Ullrich
# Create uploadbar tmp directory
165 e15f2001 Scott Ullrich
mkdir -p /tmp/uploadbar
166 f3677fc5 Scott Ullrich
chmod 777 /tmp/uploadbar
167
168 5b237745 Scott Ullrich
# make some directories in /var
169 102d8912 Scott Ullrich
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
170 ab230731 Scott Ullrich
rm /var/log/* 2>/dev/null
171 9cb8e6f0 Scott Ullrich
rm -rf /var/run/*
172 5b237745 Scott Ullrich
173 2e269da2 Scott Ullrich
echo -n "."
174 74772f9f Scott Ullrich
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
175 dbdbd597 Scott Ullrich
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
176
	touch /var/log/system.log
177
	touch /var/log/filter.log
178
	touch /var/log/dhcpd.log
179
	touch /var/log/vpn.log
180
	touch /var/log/openvpn.log
181
	touch /var/log/portalauth.log
182
	touch /var/log/ipsec.log
183 99944dc5 Seth Mos
	touch /var/log/relayd.log
184 dbdbd597 Scott Ullrich
	touch /var/log/lighttpd.log
185
	touch /var/log/ntpd.log
186
else 
187
	# generate circular logfiles
188
	clog -i -s 512144 /var/log/system.log
189
	clog -i -s 512144 /var/log/filter.log
190
	clog -i -s 65535 /var/log/dhcpd.log
191
	clog -i -s 65535 /var/log/vpn.log
192
	clog -i -s 65535 /var/log/openvpn.log
193
	clog -i -s 65535 /var/log/portalauth.log
194
	clog -i -s 65535 /var/log/ipsec.log
195 99944dc5 Seth Mos
	clog -i -s 65535 /var/log/relayd.log
196 dbdbd597 Scott Ullrich
	clog -i -s 65535 /var/log/lighttpd.log
197
	clog -i -s 65535 /var/log/ntpd.log
198
fi 
199
# change permissions on newly created clog files.
200 99944dc5 Seth Mos
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	
201 8d418ca9 Scott Ullrich
202 2e269da2 Scott Ullrich
echo -n "."
203 f93c5384 Scott Ullrich
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
204
if [ "$DEVFS" = "0" ]; then
205
    mount_devfs devfs /dev
206
fi
207 5b237745 Scott Ullrich
208
# Create an initial utmp file
209
cd /var/run && cp /dev/null utmp && chmod 644 utmp
210
211 2e269da2 Scott Ullrich
echo -n "."
212 6fe4f291 Scott Ullrich
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
213 c268f10f Scott Ullrich
214 cdbc61b6 Scott Ullrich
# Make sure /etc/rc.conf doesn't exist.
215
if [ -f /etc/rc.conf ]; then
216
    rm -rf /etc/rc.conf
217
fi
218
219 b1ce7649 Scott Ullrich
# Launching kbdmux(4)
220
if [ -f "/dev/kbdmux0" ]; then
221 2e269da2 Scott Ullrich
	echo -n "."
222 b1ce7649 Scott Ullrich
	kbdcontrol -k /dev/kbdmux0 < /dev/console
223
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
224 4e7b2b27 Scott Ullrich
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
225
fi
226
227
# Fire up unionfs if mount points exist.
228
if [ -f /dist/uniondirs ]; then
229 2e269da2 Scott Ullrich
	echo -n "."
230 4e7b2b27 Scott Ullrich
	/etc/rc.d/unionfs start
231 b1ce7649 Scott Ullrich
fi
232 fa8f44ce Scott Ullrich
233 2e269da2 Scott Ullrich
echo "done."
234 deff30cd Scott Ullrich
235 ad0d7518 Scott Ullrich
# Recreate capabilities DB
236
cap_mkdb /etc/login.conf
237
238 469d6893 Scott Ullrich
if [ "$PLATFORM" != "cdrom" ]; then
239 90229962 Scott Ullrich
	# Populate a dummy php.ini to avoid
240
	# the file being clobbered and the firewall
241
	# not being able to boot back up.
242
	cat >/usr/local/lib/php.ini <<EOF
243 437c763a Scott Ullrich
# File generated from /etc/rc
244 469d6893 Scott Ullrich
output_buffering = "0"
245
implicit_flush = true
246
magic_quotes_gpc = Off
247
max_execution_time = 99999999
248
max_input_time = 99999999
249 90229962 Scott Ullrich
register_argc_argv = On
250 469d6893 Scott Ullrich
file_uploads = On
251
upload_tmp_dir = /tmp
252 90229962 Scott Ullrich
upload_max_filesize = 100M
253
post_max_size = 100M
254 469d6893 Scott Ullrich
html_errors = Off
255 90229962 Scott Ullrich
zlib.output_compression = On
256
zlib.output_compression_level = 5
257 469d6893 Scott Ullrich
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
258 8f45a091 Scott Ullrich
extension_dir=/usr/local/lib/php/20060613/
259 90229962 Scott Ullrich
260
; add additional extensions below
261
; standard PHP extension
262 5ac93075 Scott Ullrich
extension=pcre.so
263 90229962 Scott Ullrich
extension=bz2.so
264
extension=bcmath.so
265
extension=ctype.so
266
extension=curl.so
267
extension=gettext.so
268
extension=mbstring.so
269 a0288aa9 Scott Ullrich
extension=mhash.so
270 5285a0e3 Scott Ullrich
extension=openssl.so
271 90229962 Scott Ullrich
extension=pcntl.so
272
extension=posix.so
273
extension=readline.so
274
extension=session.so
275 2789033a Scott Ullrich
;extension=simplexml.so
276 90229962 Scott Ullrich
extension=shmop.so
277
extension=sysvmsg.so
278
extension=sysvsem.so
279
extension=sysvshm.so
280
extension=tokenizer.so
281
extension=xml.so
282 18f3482d Scott Ullrich
extension=ldap.so
283 90229962 Scott Ullrich
extension=zlib.so
284
285
; standard PHP extensions currently beeing unused
286
;extension=json.so
287
;extension=ncurses.so
288
;xmlreader.so
289
;xmlwriter.so
290
291
;[xdebug]
292
;xdebug.remote_enable = On
293
;xdebug.default_enable = On
294
;xdebug.remote_mode = On
295
;xdebug.remote_handler = dbgp
296
;xdebug.remote_host = 127.0.0.1
297
;xdebug.remote_port = 17869
298
;xdebug.idekey = devphp
299
300 ab346e30 Ermal Luçi
EOF
301
302
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
303
export RAM
304
if [  $RAM -gt 96 ]; then
305
306
cat >>/usr/local/lib/php.ini <<EOF
307
extension=apc.so
308 12706a1d Scott Ullrich
apc.enabled="1"
309 d1475c67 Scott Ullrich
apc.enable_cli="1"
310 12706a1d Scott Ullrich
apc.shm_size="25"
311 469d6893 Scott Ullrich
312
EOF
313 90229962 Scott Ullrich
314 ab346e30 Ermal Luçi
fi
315
316
317 b21dd17d Scott Ullrich
fi
318
319 2789033a Scott Ullrich
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
320 469d6893 Scott Ullrich
321 9afe0d5a Scott Ullrich
rm -f /cf/conf/backup/backup.cache
322
323 b406ae66 Scott Ullrich
# let the PHP-based configuration subsystem set up the system now
324 d0e94aaf Scott Ullrich
echo -n "Launching PHP init system..."
325 b406ae66 Scott Ullrich
/etc/rc.bootup
326
327 0c5e431d Scott Ullrich
echo -n "Starting CRON... "
328 ea83ac64 Scott Ullrich
cd /tmp && /usr/sbin/cron -s 2>/dev/null
329 0c5e431d Scott Ullrich
echo "done."
330 3e08b3c1 Scott Ullrich
331 5be5825e Scott Ullrich
# Start packages
332
/etc/rc.start_packages
333 3bd1bd72 Scott Ullrich
334 58eba990 Scott Ullrich
rm -rf /usr/local/pkg/pf/CVS
335
336 7b2ac828 Scott Ullrich
/usr/local/bin/php -f /etc/rc.conf_mount_ro
337 f92eaec2 Scott Ullrich
338 d9f8db28 Scott Ullrich
# Remove stale files that have already been processed by bootup
339
# scripts
340 db54bc25 Scott Ullrich
rm -f /tmp/filter_dirty
341 6374d041 Scott Ullrich
rm -f /tmp/rc.linkup
342 13325083 Seth Mos
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status &
343 bc086d51 Scott Ullrich
344 f2025e91 Scott Ullrich
# Start ping handler for every 240 seconds
345 7db10f15 Seth Mos
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
346 f2025e91 Scott Ullrich
347 925e23bf Scott Ullrich
chmod a+rw /tmp/.
348 b569598b Scott Ullrich
349 e393a4a8 Scott Ullrich
echo "Bootup complete"
350 1ba9533c Scott Ullrich
351 2d4be1c5 Scott Ullrich
/usr/local/bin/beep.sh start 2>&1 >/dev/null
352 e393a4a8 Scott Ullrich
353 d35cf0de Scott Ullrich
exit 0