Project

General

Profile

Download (9.73 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
else 
249 8274afc7 Scott Ullrich
	ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
250
	if [ "$ENABLEFIFOLOG" -gt "0" ]; then
251
		# generate fifolog files
252
		/usr/sbin/fifolog_create -s 511488 /var/log/system.log
253
		/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
254
		/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
255
		/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
256 328efaba Ermal
		/usr/sbin/fifolog_create -s 50688 /var/log/pptp.log
257
		/usr/sbin/fifolog_create -s 50688 /var/log/pppoe.log
258 3da49dc3 Ermal
		/usr/sbin/fifolog_create -s 50688 /var/log/l2tp.log
259 8274afc7 Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
260
		/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
261
		/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
262 295e19dd Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/ppp.log
263 8274afc7 Scott Ullrich
		/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
264
		/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
265
		/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
266
	else 
267
		/usr/sbin/clog -i -s 512144 /var/log/system.log
268
		/usr/sbin/clog -i -s 512144 /var/log/filter.log
269
		/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
270
		/usr/sbin/clog -i -s 65535 /var/log/vpn.log
271 328efaba Ermal
		/usr/sbin/clog -i -s 50688 /var/log/pptp.log
272
		/usr/sbin/clog -i -s 50688 /var/log/pppoe.log
273 3da49dc3 Ermal
		/usr/sbin/clog -i -s 50688 /var/log/l2tp.log
274 8274afc7 Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
275
		/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
276
		/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
277 295e19dd Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/ppp.log
278 8274afc7 Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/slbd.log
279
		/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
280
		/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
281 d846bbfc Scott Ullrich
		/usr/sbin/clog -i -s 65535 /var/log/relayd.log		
282 8274afc7 Scott Ullrich
	fi
283 dbdbd597 Scott Ullrich
fi 
284 57ecd9b6 Scott Ullrich
# change permissions on newly created fifolog files.
285 d6cb86d1 Scott Ullrich
chmod 0600 /var/log/*.log
286 8d418ca9 Scott Ullrich
287 2e269da2 Scott Ullrich
echo -n "."
288 f93c5384 Scott Ullrich
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
289
if [ "$DEVFS" = "0" ]; then
290
    mount_devfs devfs /dev
291
fi
292 5b237745 Scott Ullrich
293
# Create an initial utmp file
294
cd /var/run && cp /dev/null utmp && chmod 644 utmp
295
296 2e269da2 Scott Ullrich
echo -n "."
297 6fe4f291 Scott Ullrich
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
298 c268f10f Scott Ullrich
299 cdbc61b6 Scott Ullrich
# Make sure /etc/rc.conf doesn't exist.
300
if [ -f /etc/rc.conf ]; then
301
    rm -rf /etc/rc.conf
302
fi
303
304 b1ce7649 Scott Ullrich
# Launching kbdmux(4)
305
if [ -f "/dev/kbdmux0" ]; then
306 2e269da2 Scott Ullrich
	echo -n "."
307 b1ce7649 Scott Ullrich
	kbdcontrol -k /dev/kbdmux0 < /dev/console
308
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
309 4e7b2b27 Scott Ullrich
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
310
fi
311
312
# Fire up unionfs if mount points exist.
313
if [ -f /dist/uniondirs ]; then
314 2e269da2 Scott Ullrich
	echo -n "."
315 4e7b2b27 Scott Ullrich
	/etc/rc.d/unionfs start
316 b1ce7649 Scott Ullrich
fi
317 fa8f44ce Scott Ullrich
318 2e269da2 Scott Ullrich
echo "done."
319 deff30cd Scott Ullrich
320 ad0d7518 Scott Ullrich
# Recreate capabilities DB
321
cap_mkdb /etc/login.conf
322
323 40e46009 Scott Ullrich
# Run the php.ini setup file and populate
324
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
325
. /etc/rc.php_ini_setup
326 0cf5aa69 Scott Ullrich
327 b406ae66 Scott Ullrich
# let the PHP-based configuration subsystem set up the system now
328 8e2eb65e Scott Ullrich
echo -n "Launching the init system..."
329 40e46009 Scott Ullrich
rm -f /cf/conf/backup/backup.cache
330
rm -f /root/lighttpd*
331 1f0f301c jim-p
touch $varrunpath/booting
332 b406ae66 Scott Ullrich
/etc/rc.bootup
333
334 c1da5030 Scott Ullrich
# If a shell was selected from recovery 
335
# console then just drop to the shell now.
336
if [ -f "/tmp/donotbootup" ]; then
337 b1d04497 Scott Ullrich
	echo "Dropping to recovery shell."
338 c1da5030 Scott Ullrich
	exit 0
339
fi
340
341 0c5e431d Scott Ullrich
echo -n "Starting CRON... "
342 ea83ac64 Scott Ullrich
cd /tmp && /usr/sbin/cron -s 2>/dev/null
343 0c5e431d Scott Ullrich
echo "done."
344 3e08b3c1 Scott Ullrich
345 5be5825e Scott Ullrich
# Start packages
346
/etc/rc.start_packages
347 3bd1bd72 Scott Ullrich
348 58eba990 Scott Ullrich
rm -rf /usr/local/pkg/pf/CVS
349
350 d9f8db28 Scott Ullrich
# Remove stale files that have already been processed by bootup
351
# scripts
352 db54bc25 Scott Ullrich
rm -f /tmp/filter_dirty
353 6374d041 Scott Ullrich
rm -f /tmp/rc.linkup
354 0e0e044a Scott Ullrich
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
355 bc086d51 Scott Ullrich
356 0092b3bd mgrooms
# Start ping handler every 240 seconds
357 7db10f15 Seth Mos
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
358 f2025e91 Scott Ullrich
359 0092b3bd mgrooms
# Start account expire handler every hour
360 6c8a7393 Ermal Lu?i
minicron 3600 /var/run/expire_accounts.pid /etc/rc.exipireaccounts
361 0092b3bd mgrooms
362 f6ba4bd1 Scott Ullrich
# Start alias url updater every 24 hours
363
minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
364
365 c432da9c Scott Ullrich
/bin/chmod a+rw /tmp/.
366 b569598b Scott Ullrich
367 e393a4a8 Scott Ullrich
echo "Bootup complete"
368 1f0f301c jim-p
rm $varrunpath/booting
369 1ba9533c Scott Ullrich
370 2d4be1c5 Scott Ullrich
/usr/local/bin/beep.sh start 2>&1 >/dev/null
371 e393a4a8 Scott Ullrich
372 4171fa68 Scott Ullrich
# Reset the cache.  read-only requires this.
373
rm /tmp/config.cache
374
375 0eb1fdbc Scott Ullrich
/etc/rc.conf_mount_ro
376
377 d35cf0de Scott Ullrich
exit 0