Project

General

Profile

Download (9.86 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
HOME=/
19 ce823053 Scott Ullrich
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
20 5b237745 Scott Ullrich
export HOME PATH
21
22 1c44a77d Scott Ullrich
# Set our operating platform
23
PLATFORM=`cat /etc/platform`
24
25 842878b5 Scott Ullrich
# Set our current version
26
version=`cat /etc/version`
27
28 c4995e62 Chris Buechler
# Mount memory file system if it exists
29 8022e257 Scott Ullrich
echo "Mounting filesystems..."
30 842878b5 Scott Ullrich
31
if [ "$PLATFORM" = "cdrom" ]; then
32
	/etc/rc.cdrom
33
fi
34
35
if [ "$PLATFORM" = "embedded" ]; then
36
	/etc/rc.embedded
37
fi
38
39
if [ "$PLATFORM" = "nanobsd" ]; then
40
	/etc/rc.embedded
41
fi
42
43
if [ "$PLATFORM" = "pfSense" ]; then
44
	mdmfs -S -M -s 4m md /var/run
45
fi
46 c4995e62 Chris Buechler
47
# Mount /. If it fails run a fsck.
48
if [ ! "$PLATFORM" = "cdrom" ] ; then
49 ce8efd06 Scott Ullrich
	if [ "$PLATFORM" = "nanobsd" ]; then
50 842878b5 Scott Ullrich
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
51 ce8efd06 Scott Ullrich
	else 
52
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
53
	fi
54 842878b5 Scott Ullrich
	# If /conf is a directory, convert it to a symlink to /cf/conf
55 c4995e62 Chris Buechler
	if [ -d "/conf" ]; then
56
		# If item is not a symlink then rm and recreate
57
		CONFPOINTSTO=`readlink /conf` 
58
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
59
			rm -rf /conf
60
			ln -s /cf/conf /conf
61
		fi
62
	fi
63
fi
64
65
# Check to see if a compact flash mountpoint exists
66
# If it fails to mount then run a fsck -fy
67
if grep -q cf /etc/fstab; then
68 8022e257 Scott Ullrich
	/sbin/mount -w /cf 2>/dev/null
69 c4995e62 Chris Buechler
    /sbin/mount -uw /cf || \
70
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
71
fi
72
73
product=`grep product_name /etc/inc/globals.inc | cut -d'"' -f4`
74
hideplatform=`grep hideplatform /etc/inc/globals.inc | wc -l`
75
varrunpath=`grep varrun_path /etc/inc/globals.inc | cut -d'"' -f4`
76 3d7639eb Scott Ullrich
77 6fafc69f Scott Ullrich
if [ "$hideplatform" -gt "0" ]; then
78 3d7639eb Scott Ullrich
	platformbanner="" # hide the platform
79
else
80
	platformbanner=" on the '${PLATFORM}' platform"
81
fi
82 1c44a77d Scott Ullrich
83
echo
84
cat /etc/ascii-art/pfsense-logo-small.txt
85
echo
86
echo
87 ba2cbed4 Scott Ullrich
echo "Welcome to ${product} ${version} ${platformbanner} ..."
88 1c44a77d Scott Ullrich
echo
89
90 d5f60dba Scott Ullrich
# Enable console output if its muted.
91
/sbin/conscontrol mute off >/dev/null
92
93 5621d2d5 Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
94
	# do nothing for cdrom platform
95
elif [ "$PLATFORM" = "embedded" ] ; then
96 f92e9ff3 Scott Ullrich
    # do nothing for embedded platform
97 803c0401 Scott Ullrich
elif [ "$PLATFORM" = "nanobsd" ] ; then
98 99b8b304 Scott Ullrich
	# Ensure that packages can be persistent across reboots
99 cd465e06 Scott Ullrich
	/bin/mkdir -p /root/var/db/pkg
100 eb071c7d Scott Ullrich
	rm -rf /var/db/pkg
101 95399b72 Scott Ullrich
	ln -s /root/var/db/pkg/ /var/db/pkg
102 c0819d14 Jeb Campbell
else
103 d8a2ce2c Scott Ullrich
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
104 7050e57c Scott Ullrich
    /sbin/swapon -a 2>/dev/null >/dev/null
105 98546a74 Scott Ullrich
fi
106 5621d2d5 Scott Ullrich
107 12bf92ca Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
108
	mkdir /tmp/unionfs
109
	mkdir /tmp/unionfs/usr
110
	mkdir /tmp/unionfs/root
111 d948c0d4 Scott Ullrich
	mkdir /tmp/unionfs/sbin
112
	mkdir /tmp/unionfs/bin
113
	mkdir /tmp/unionfs/boot
114 4f54dd23 Scott Ullrich
	mkdir /tmp/unionfs/confdefault
115 8b3a495b Scott Ullrich
	mkdir /tmp/unionfs/PCBSD
116 ab1a08b2 Scott Ullrich
	echo -n "Mounting unionfs directories:"
117
	echo -n " usr"
118 12bf92ca Scott Ullrich
	mount_unionfs /tmp/unionfs/usr /usr/
119
	echo -n " root"
120 d948c0d4 Scott Ullrich
	mount_unionfs /tmp/unionfs/root /root/
121
	echo -n " bin"
122
	mount_unionfs /tmp/unionfs/bin /bin/		
123
	echo -n " sbin"
124
	mount_unionfs /tmp/unionfs/sbin /sbin/	
125
	echo -n " boot"
126
	mount_unionfs /tmp/unionfs/boot /boot/
127 4f54dd23 Scott Ullrich
	echo -n " conf.default"
128
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
129 8b3a495b Scott Ullrich
	echo -n " installer"
130
	mount_unionfs /tmp/unionfs/PCBSD /PCBSD/
131 ab1a08b2 Scott Ullrich
	echo "... done."
132 12bf92ca Scott Ullrich
fi
133
134 2e269da2 Scott Ullrich
echo -n "Creating symlinks..."
135 895ecb35 Scott Ullrich
# Make sure symlink is correct on embedded
136
if [ "$PLATFORM" = "embedded" ] ; then
137
	rm /conf
138 4e7b2b27 Scott Ullrich
	ln -s /cf/conf/ /conf
139 895ecb35 Scott Ullrich
fi
140
141 803c0401 Scott Ullrich
# Make sure symlink is correct on nanobsd
142
if [ "$PLATFORM" = "nanobsd" ] ; then
143
	rm /conf
144
	ln -s /cf/conf/ /conf
145
fi
146
147 6bab150e Scott Ullrich
# Repair symlinks if they are broken
148
if [ ! -L /etc/syslog.conf ]; then
149
	rm -rf /etc/syslog.conf
150
	ln -s /var/etc/syslog.conf /etc/syslog.conf
151
fi
152
153 f1cc2287 Scott Ullrich
# Repair symlinks if they are broken
154
if [ ! -L /etc/hosts ]; then
155
	rm -rf /etc/hosts
156 4e7b2b27 Scott Ullrich
	ln -s /var/etc/hosts /etc/hosts
157 c8fcdb2f Scott Ullrich
fi
158 095d04db Scott Ullrich
159 f1cc2287 Scott Ullrich
if [ ! -L /etc/resolv.conf ]; then
160
    rm -rf /etc/resolv.conf
161 4e7b2b27 Scott Ullrich
    ln -s /var/etc/resolv.conf /etc/resolv.conf
162 f1cc2287 Scott Ullrich
fi
163 095d04db Scott Ullrich
164 230787e7 Scott Ullrich
# Setup compatibility link for packages that
165
# have trouble overriding the PREFIX configure
166
# argument since we build our packages in a
167
# seperated PREFIX area
168 eb03f14e Chris Buechler
# Only create if symlink does not exist. 
169
if [ ! -h /tmp/tmp ]; then
170
    ln -hfs / /tmp/tmp
171
fi
172 230787e7 Scott Ullrich
173 4be3f6cf Seth Mos
# Make sure our /tmp is 777 + Sticky
174 3fb8caf2 Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
175
	rm -rf /tmp/*
176
fi
177 0652f3ae Seth Mos
chmod 1777 /tmp
178
179 dd64811a Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
180
	# Malloc debugging check
181
	if [ -L /etc/malloc.conf ]; then
182
	    #ln -s aj /etc/malloc.conf
183
		rm /etc/malloc.conf
184
	fi
185 cecdf31c Scott Ullrich
fi
186
187 6484bb83 Scott Ullrich
if [ ! -L /etc/dhclient.conf ]; then
188
    rm -rf /etc/dhclient.conf
189
fi
190 c8fcdb2f Scott Ullrich
191 bfe6d078 Scott Ullrich
if [ ! -L /etc/sasyncd.conf ]; then
192 b8c835d2 Scott Ullrich
    mkdir -p /var/etc/
193 bfe6d078 Scott Ullrich
    touch /var/etc/sasyncd.conf
194
    rm -rf /etc/sasyncd.conf
195
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
196 84f68d65 Scott Ullrich
    chown root:wheel /var/etc/sasyncd.conf
197 bfe6d078 Scott Ullrich
    chmod 0600 /var/etc/sasyncd.conf
198
fi
199
200 544156a7 Scott Ullrich
if [ ! -d /var/tmp ]; then
201
	mkdir -p /var/tmp
202
fi
203 4aa70cd8 Scott Ullrich
204 544156a7 Scott Ullrich
if [ ! -d /cf/conf/backup/ ]; then
205
	mkdir -p /cf/conf/backup/ 
206
fi
207 d42c2e20 Scott Ullrich
208 9f85112d Scott Ullrich
# OpenVPN storage
209 359e3f6a Scott Ullrich
if [ ! -d /var/etc/openvpn ]; then
210
	mkdir -p /var/etc/openvpn
211
fi
212
if [ ! -d /var/etc/openvpn-csc ]; then
213
	mkdir -p /var/etc/openvpn-csc
214
fi
215 67df0c62 Scott Ullrich
216 5b237745 Scott Ullrich
set -T
217
trap "echo 'Reboot interrupted'; exit 1" 3
218
219 61f1e2ec Scott Ullrich
# Remove old nameserver resolution files
220
rm -f /var/etc/nameserver*
221
222 f3677fc5 Scott Ullrich
# Create uploadbar tmp directory
223 e15f2001 Scott Ullrich
mkdir -p /tmp/uploadbar
224 4be3f6cf Seth Mos
chmod 0777 /tmp/uploadbar
225 f3677fc5 Scott Ullrich
226 5b237745 Scott Ullrich
# make some directories in /var
227 102d8912 Scott Ullrich
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
228 ab230731 Scott Ullrich
rm /var/log/* 2>/dev/null
229 9cb8e6f0 Scott Ullrich
rm -rf /var/run/*
230 5b237745 Scott Ullrich
231 2e269da2 Scott Ullrich
echo -n "."
232 74772f9f Scott Ullrich
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
233 dbdbd597 Scott Ullrich
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
234
	touch /var/log/system.log
235
	touch /var/log/filter.log
236
	touch /var/log/dhcpd.log
237
	touch /var/log/vpn.log
238 328efaba Ermal
	touch /var/log/pptp.log
239
	touch /var/log/pppoe.log
240
	touch /var/log/l2tp.log
241 dbdbd597 Scott Ullrich
	touch /var/log/openvpn.log
242
	touch /var/log/portalauth.log
243
	touch /var/log/ipsec.log
244 295e19dd Scott Ullrich
	touch /var/log/ppp.log
245 99944dc5 Seth Mos
	touch /var/log/relayd.log
246 dbdbd597 Scott Ullrich
	touch /var/log/lighttpd.log
247
	touch /var/log/ntpd.log
248 b1f4d7d4 Chris Buechler
	touch /var/log/apinger.log
249 dbdbd597 Scott Ullrich
else 
250 8274afc7 Scott Ullrich
	ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
251
	if [ "$ENABLEFIFOLOG" -gt "0" ]; then
252
		# generate fifolog files
253
		/usr/sbin/fifolog_create -s 511488 /var/log/system.log
254
		/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
255
		/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
256
		/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
257 328efaba Ermal
		/usr/sbin/fifolog_create -s 50688 /var/log/pptp.log
258
		/usr/sbin/fifolog_create -s 50688 /var/log/pppoe.log
259 3da49dc3 Ermal
		/usr/sbin/fifolog_create -s 50688 /var/log/l2tp.log
260 8274afc7 Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
261
		/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
262
		/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
263 295e19dd Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/ppp.log
264 8274afc7 Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
265
		/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
266
		/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
267 b1f4d7d4 Chris Buechler
		/usr/sbin/fifolog_create -s 50688 /var/log/apinger.log
268 8274afc7 Scott Ullrich
	else 
269
		/usr/sbin/clog -i -s 512144 /var/log/system.log
270
		/usr/sbin/clog -i -s 512144 /var/log/filter.log
271
		/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
272
		/usr/sbin/clog -i -s 65535 /var/log/vpn.log
273 328efaba Ermal
		/usr/sbin/clog -i -s 50688 /var/log/pptp.log
274
		/usr/sbin/clog -i -s 50688 /var/log/pppoe.log
275 3da49dc3 Ermal
		/usr/sbin/clog -i -s 50688 /var/log/l2tp.log
276 8274afc7 Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
277
		/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
278
		/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
279 295e19dd Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/ppp.log
280 8274afc7 Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/slbd.log
281
		/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
282
		/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
283 b1f4d7d4 Chris Buechler
		/usr/sbin/clog -i -s 65535 /var/log/relayd.log	
284
		/usr/sbin/clog -i -s 65535 /var/log/apinger.log	
285 8274afc7 Scott Ullrich
	fi
286 dbdbd597 Scott Ullrich
fi 
287 57ecd9b6 Scott Ullrich
# change permissions on newly created fifolog files.
288 d6cb86d1 Scott Ullrich
chmod 0600 /var/log/*.log
289 8d418ca9 Scott Ullrich
290 2e269da2 Scott Ullrich
echo -n "."
291 f93c5384 Scott Ullrich
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
292
if [ "$DEVFS" = "0" ]; then
293
    mount_devfs devfs /dev
294
fi
295 5b237745 Scott Ullrich
296
# Create an initial utmp file
297
cd /var/run && cp /dev/null utmp && chmod 644 utmp
298
299 2e269da2 Scott Ullrich
echo -n "."
300 6fe4f291 Scott Ullrich
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
301 c268f10f Scott Ullrich
302 cdbc61b6 Scott Ullrich
# Make sure /etc/rc.conf doesn't exist.
303
if [ -f /etc/rc.conf ]; then
304
    rm -rf /etc/rc.conf
305
fi
306
307 b1ce7649 Scott Ullrich
# Launching kbdmux(4)
308
if [ -f "/dev/kbdmux0" ]; then
309 2e269da2 Scott Ullrich
	echo -n "."
310 b1ce7649 Scott Ullrich
	kbdcontrol -k /dev/kbdmux0 < /dev/console
311
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
312 4e7b2b27 Scott Ullrich
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
313
fi
314
315
# Fire up unionfs if mount points exist.
316
if [ -f /dist/uniondirs ]; then
317 2e269da2 Scott Ullrich
	echo -n "."
318 4e7b2b27 Scott Ullrich
	/etc/rc.d/unionfs start
319 b1ce7649 Scott Ullrich
fi
320 fa8f44ce Scott Ullrich
321 2e269da2 Scott Ullrich
echo "done."
322 deff30cd Scott Ullrich
323 ad0d7518 Scott Ullrich
# Recreate capabilities DB
324
cap_mkdb /etc/login.conf
325
326 40e46009 Scott Ullrich
# Run the php.ini setup file and populate
327
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
328
. /etc/rc.php_ini_setup
329 0cf5aa69 Scott Ullrich
330 b406ae66 Scott Ullrich
# let the PHP-based configuration subsystem set up the system now
331 8e2eb65e Scott Ullrich
echo -n "Launching the init system..."
332 40e46009 Scott Ullrich
rm -f /cf/conf/backup/backup.cache
333
rm -f /root/lighttpd*
334 1f0f301c jim-p
touch $varrunpath/booting
335 b406ae66 Scott Ullrich
/etc/rc.bootup
336
337 c1da5030 Scott Ullrich
# If a shell was selected from recovery 
338
# console then just drop to the shell now.
339
if [ -f "/tmp/donotbootup" ]; then
340 b1d04497 Scott Ullrich
	echo "Dropping to recovery shell."
341 c1da5030 Scott Ullrich
	exit 0
342
fi
343
344 0c5e431d Scott Ullrich
echo -n "Starting CRON... "
345 ea83ac64 Scott Ullrich
cd /tmp && /usr/sbin/cron -s 2>/dev/null
346 0c5e431d Scott Ullrich
echo "done."
347 3e08b3c1 Scott Ullrich
348 5be5825e Scott Ullrich
# Start packages
349
/etc/rc.start_packages
350 3bd1bd72 Scott Ullrich
351 58eba990 Scott Ullrich
rm -rf /usr/local/pkg/pf/CVS
352
353 d9f8db28 Scott Ullrich
# Remove stale files that have already been processed by bootup
354
# scripts
355 db54bc25 Scott Ullrich
rm -f /tmp/filter_dirty
356 6374d041 Scott Ullrich
rm -f /tmp/rc.linkup
357 0e0e044a Scott Ullrich
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
358 bc086d51 Scott Ullrich
359 0092b3bd mgrooms
# Start ping handler every 240 seconds
360 7db10f15 Seth Mos
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
361 f2025e91 Scott Ullrich
362 0092b3bd mgrooms
# Start account expire handler every hour
363 6c8a7393 Ermal Lu?i
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
364 0092b3bd mgrooms
365 f6ba4bd1 Scott Ullrich
# Start alias url updater every 24 hours
366
minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
367
368 c432da9c Scott Ullrich
/bin/chmod a+rw /tmp/.
369 b569598b Scott Ullrich
370 e393a4a8 Scott Ullrich
echo "Bootup complete"
371 1f0f301c jim-p
rm $varrunpath/booting
372 1ba9533c Scott Ullrich
373 2d4be1c5 Scott Ullrich
/usr/local/bin/beep.sh start 2>&1 >/dev/null
374 e393a4a8 Scott Ullrich
375 4171fa68 Scott Ullrich
# Reset the cache.  read-only requires this.
376
rm /tmp/config.cache
377
378 0eb1fdbc Scott Ullrich
/etc/rc.conf_mount_ro
379
380 d35cf0de Scott Ullrich
exit 0