Project

General

Profile

Download (10.6 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 8ad39798 Scott Ullrich
# Copyright (C) 2004-2010 Scott Ullrich, All rights reserved.
8 e5cd29a0 Scott Ullrich
# 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 e8d0903d Ermal
PLATFORM=`/bin/cat /etc/platform`
24 1c44a77d Scott Ullrich
25 842878b5 Scott Ullrich
# Set our current version
26 e8d0903d Ermal
version=`/bin/cat /etc/version`
27 842878b5 Scott Ullrich
28 e5323cca jim-p
# Setup dumpdev/ddb/savecore"
29
echo "Configuring crash dumps..."
30
if [ "$PLATFORM" = "pfSense" ]; then
31
	/etc/rc.dumpon
32
fi
33
34 c4995e62 Chris Buechler
# Mount memory file system if it exists
35 8022e257 Scott Ullrich
echo "Mounting filesystems..."
36 842878b5 Scott Ullrich
37 87db1017 Scott Ullrich
# Handle ZFS read-only case
38 6bc46900 Scott Ullrich
if [ "$PLATFORM" = "pfSense" ]; then
39
	if [ -f /usr/bin/grep ]; then
40
		WHEREISROOT=`/sbin/mount | /usr/bin/grep " / " | /usr/bin/grep "tank" | /usr/bin/cut -d' ' -f1`
41
		if [ "$WHEREISROOT" != "" ]; then
42
			/sbin/zfs set readonly=off $WHEREISROOT
43
		fi
44 8a8f51b7 Scott Ullrich
	fi
45 87db1017 Scott Ullrich
fi
46
47 842878b5 Scott Ullrich
if [ "$PLATFORM" = "cdrom" ]; then
48
	/etc/rc.cdrom
49
fi
50
51
if [ "$PLATFORM" = "embedded" ]; then
52 6c67a28d jim-p
	export PKG_TMPDIR=/root/
53 842878b5 Scott Ullrich
	/etc/rc.embedded
54
fi
55
56
if [ "$PLATFORM" = "nanobsd" ]; then
57 6c67a28d jim-p
	export PKG_TMPDIR=/root/
58 842878b5 Scott Ullrich
	/etc/rc.embedded
59
fi
60
61
if [ "$PLATFORM" = "pfSense" ]; then
62 e8d0903d Ermal
	/sbin/mdmfs -S -M -s 4m md /var/run
63 842878b5 Scott Ullrich
fi
64 c4995e62 Chris Buechler
65
# Mount /. If it fails run a fsck.
66
if [ ! "$PLATFORM" = "cdrom" ] ; then
67 ce8efd06 Scott Ullrich
	if [ "$PLATFORM" = "nanobsd" ]; then
68 842878b5 Scott Ullrich
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
69 ce8efd06 Scott Ullrich
	else 
70
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
71
	fi
72 842878b5 Scott Ullrich
	# If /conf is a directory, convert it to a symlink to /cf/conf
73 c4995e62 Chris Buechler
	if [ -d "/conf" ]; then
74
		# If item is not a symlink then rm and recreate
75
		CONFPOINTSTO=`readlink /conf` 
76
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
77 e8d0903d Ermal
			/bin/rm -rf /conf
78
			/bin/ln -s /cf/conf /conf
79 c4995e62 Chris Buechler
		fi
80
	fi
81
fi
82
83 92ac3b3d jim-p
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
84 06fd1952 Ermal
if [ -f /etc/rc.disable_hdd_apm ]; then
85
	/etc/rc.disable_hdd_apm
86
fi
87 92ac3b3d jim-p
88 793d3c96 smos
#Eject CD devices on 3G modems
89
MANUFATURER="huawei|zte"
90
CDDEVICE=`dmesg |egrep -ei "($MANUFACTURER)" | awk '/cd/ {print $1}'`
91
cdcontrol -f /dev/"$CDDEVICE" eject
92
93 7734aea6 Andrew Thompson
if [ ! "$PLATFORM" = "jail" ]; then
94
	# Check to see if a compact flash mountpoint exists
95
	# If it fails to mount then run a fsck -fy
96
	if grep -q cf /etc/fstab; then
97
		/sbin/mount -w /cf 2>/dev/null
98
		/sbin/mount -uw /cf || \
99
			(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
100
	fi
101 c4995e62 Chris Buechler
fi
102
103 ca3537ba jim-p
# sync pw database after mount.
104 01656166 jim-p
rm -f /etc/spwd.db.tmp
105
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
106 ca3537ba jim-p
107 e8d0903d Ermal
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
108
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
109
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
110 3d7639eb Scott Ullrich
111 6fafc69f Scott Ullrich
if [ "$hideplatform" -gt "0" ]; then
112 3d7639eb Scott Ullrich
	platformbanner="" # hide the platform
113
else
114
	platformbanner=" on the '${PLATFORM}' platform"
115
fi
116 1c44a77d Scott Ullrich
117
echo
118
cat /etc/ascii-art/pfsense-logo-small.txt
119
echo
120
echo
121 ba2cbed4 Scott Ullrich
echo "Welcome to ${product} ${version} ${platformbanner} ..."
122 1c44a77d Scott Ullrich
echo
123
124 7734aea6 Andrew Thompson
if [ ! "$PLATFORM" = "jail" ]; then
125
	# Enable console output if its muted.
126
	/sbin/conscontrol mute off >/dev/null
127
fi
128 d5f60dba Scott Ullrich
129 5621d2d5 Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
130
	# do nothing for cdrom platform
131
elif [ "$PLATFORM" = "embedded" ] ; then
132 f92e9ff3 Scott Ullrich
    # do nothing for embedded platform
133 803c0401 Scott Ullrich
elif [ "$PLATFORM" = "nanobsd" ] ; then
134 152c18f0 Phil Davis
	# Ensure that old-style PKG packages can be persistent across reboots
135 cd465e06 Scott Ullrich
	/bin/mkdir -p /root/var/db/pkg
136 e8d0903d Ermal
	/bin/rm -rf /var/db/pkg
137
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
138 152c18f0 Phil Davis
	# Ensure that PBI packages can be persistent across reboots
139
	/bin/mkdir -p /root/var/db/pbi
140
	/bin/rm -rf /var/db/pbi
141
	/bin/ln -s /root/var/db/pbi/ /var/db/pbi
142 7734aea6 Andrew Thompson
elif [ "$PLATFORM" = "jail" ]; then
143
	# do nothing for jail platform
144 c0819d14 Jeb Campbell
else
145 3b39d0ac jim-p
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
146
	/sbin/swapon -a 2>/dev/null >/dev/null
147 e5323cca jim-p
	/etc/rc.savecore
148 98546a74 Scott Ullrich
fi
149 5621d2d5 Scott Ullrich
150 12bf92ca Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
151 df40aa86 Scott Ullrich
	echo -n "Mounting unionfs directories..."
152 e8d0903d Ermal
	/bin/mkdir /tmp/unionfs
153
	/bin/mkdir /tmp/unionfs/usr
154
	/bin/mkdir /tmp/unionfs/root
155
	/bin/mkdir /tmp/unionfs/sbin
156
	/bin/mkdir /tmp/unionfs/bin
157
	/bin/mkdir /tmp/unionfs/boot
158
	/bin/mkdir /tmp/unionfs/confdefault
159
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
160
	/sbin/mount_unionfs /tmp/unionfs/root /root/
161
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
162
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
163
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
164
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
165 df40aa86 Scott Ullrich
	echo "done."
166 12bf92ca Scott Ullrich
fi
167
168 2e269da2 Scott Ullrich
echo -n "Creating symlinks..."
169 895ecb35 Scott Ullrich
# Make sure symlink is correct on embedded
170
if [ "$PLATFORM" = "embedded" ] ; then
171 e8d0903d Ermal
	/bin/rm /conf
172
	/bin/ln -s /cf/conf/ /conf
173 895ecb35 Scott Ullrich
fi
174
175 803c0401 Scott Ullrich
# Make sure symlink is correct on nanobsd
176
if [ "$PLATFORM" = "nanobsd" ] ; then
177 e8d0903d Ermal
	/bin/rm /conf
178
	/bin/ln -s /cf/conf/ /conf
179 803c0401 Scott Ullrich
fi
180
181 6bab150e Scott Ullrich
# Repair symlinks if they are broken
182
if [ ! -L /etc/syslog.conf ]; then
183 e8d0903d Ermal
	/bin/rm -rf /etc/syslog.conf
184
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
185 6bab150e Scott Ullrich
fi
186
187 f1cc2287 Scott Ullrich
# Repair symlinks if they are broken
188
if [ ! -L /etc/hosts ]; then
189 e8d0903d Ermal
	/bin/rm -rf /etc/hosts
190
	/bin/ln -s /var/etc/hosts /etc/hosts
191 c8fcdb2f Scott Ullrich
fi
192 095d04db Scott Ullrich
193 f1cc2287 Scott Ullrich
if [ ! -L /etc/resolv.conf ]; then
194 e8d0903d Ermal
    /bin/rm -rf /etc/resolv.conf
195
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
196 f1cc2287 Scott Ullrich
fi
197 095d04db Scott Ullrich
198 230787e7 Scott Ullrich
# Setup compatibility link for packages that
199
# have trouble overriding the PREFIX configure
200
# argument since we build our packages in a
201
# seperated PREFIX area
202 eb03f14e Chris Buechler
# Only create if symlink does not exist. 
203
if [ ! -h /tmp/tmp ]; then
204 e8d0903d Ermal
    /bin/ln -hfs / /tmp/tmp
205 eb03f14e Chris Buechler
fi
206 230787e7 Scott Ullrich
207 4be3f6cf Seth Mos
# Make sure our /tmp is 777 + Sticky
208 3fb8caf2 Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
209 e8d0903d Ermal
	/bin/rm -rf /tmp/*
210 3fb8caf2 Scott Ullrich
fi
211 e8d0903d Ermal
/bin/chmod 1777 /tmp
212 0652f3ae Seth Mos
213 dd64811a Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
214
	# Malloc debugging check
215
	if [ -L /etc/malloc.conf ]; then
216
	    #ln -s aj /etc/malloc.conf
217 e8d0903d Ermal
		/bin/rm /etc/malloc.conf
218 dd64811a Scott Ullrich
	fi
219 cecdf31c Scott Ullrich
fi
220
221 6484bb83 Scott Ullrich
if [ ! -L /etc/dhclient.conf ]; then
222 e8d0903d Ermal
    /bin/rm -rf /etc/dhclient.conf
223 6484bb83 Scott Ullrich
fi
224 c8fcdb2f Scott Ullrich
225 bfe6d078 Scott Ullrich
if [ ! -L /etc/sasyncd.conf ]; then
226 e8d0903d Ermal
    /bin/mkdir -p /var/etc/
227
    /usr/bin/touch /var/etc/sasyncd.conf
228
    /bin/rm -rf /etc/sasyncd.conf
229
    /bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
230
    /usr/sbin/chown root:wheel /var/etc/sasyncd.conf
231
    /bin/chmod 0600 /var/etc/sasyncd.conf
232 bfe6d078 Scott Ullrich
fi
233
234 544156a7 Scott Ullrich
if [ ! -d /var/tmp ]; then
235 e8d0903d Ermal
	/bin/mkdir -p /var/tmp
236 544156a7 Scott Ullrich
fi
237 4aa70cd8 Scott Ullrich
238 544156a7 Scott Ullrich
if [ ! -d /cf/conf/backup/ ]; then
239 e8d0903d Ermal
	/bin/mkdir -p /cf/conf/backup/ 
240 544156a7 Scott Ullrich
fi
241 d42c2e20 Scott Ullrich
242 9f85112d Scott Ullrich
# OpenVPN storage
243 359e3f6a Scott Ullrich
if [ ! -d /var/etc/openvpn ]; then
244 e8d0903d Ermal
	/bin/mkdir -p /var/etc/openvpn
245 359e3f6a Scott Ullrich
fi
246
if [ ! -d /var/etc/openvpn-csc ]; then
247 e8d0903d Ermal
	/bin/mkdir -p /var/etc/openvpn-csc
248 359e3f6a Scott Ullrich
fi
249 67df0c62 Scott Ullrich
250 5b237745 Scott Ullrich
set -T
251
trap "echo 'Reboot interrupted'; exit 1" 3
252
253 61f1e2ec Scott Ullrich
# Remove old nameserver resolution files
254 e8d0903d Ermal
/bin/rm -f /var/etc/nameserver*
255 61f1e2ec Scott Ullrich
256 f3677fc5 Scott Ullrich
# Create uploadbar tmp directory
257 e8d0903d Ermal
/bin/mkdir -p /tmp/uploadbar
258
/bin/chmod 0777 /tmp/uploadbar
259 f3677fc5 Scott Ullrich
260 5b237745 Scott Ullrich
# make some directories in /var
261 e8d0903d Ermal
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
262
/bin/rm -rf /var/run/*
263 e8197e56 Ermal
if [ "$PLATFORM" != "pfSense" ]; then
264
	/bin/rm /var/log/* 2>/dev/null
265
fi
266 5b237745 Scott Ullrich
267 2e269da2 Scott Ullrich
echo -n "."
268 71bdd226 Warren Baker
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
269
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
270 e0c45357 jim-p
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
271 973b2663 Ermal
for logfile in $LOG_FILES; do
272
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
273
		/usr/bin/touch /var/log/$logfile.log
274 8274afc7 Scott Ullrich
	else 
275 973b2663 Ermal
		if [ ! -f /var/log/$logfile.log ]; then
276
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
277
				# generate fifolog files
278
				/usr/sbin/fifolog_create -s 511488 /var/log/$logfile.log
279
			else 
280
				/usr/sbin/clog -i -s 512144 /var/log/$logfile.log
281
			fi
282 e8197e56 Ermal
		fi
283 973b2663 Ermal
	fi 
284
done
285
286 57ecd9b6 Scott Ullrich
# change permissions on newly created fifolog files.
287 e8d0903d Ermal
/bin/chmod 0600 /var/log/*.log
288 8d418ca9 Scott Ullrich
289 2e269da2 Scott Ullrich
echo -n "."
290 7734aea6 Andrew Thompson
if [ ! "$PLATFORM" = "jail" ]; then
291
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
292
	if [ "$DEVFS" = "0" ]; then
293
		mount_devfs devfs /dev
294
	fi
295 f93c5384 Scott Ullrich
fi
296 5b237745 Scott Ullrich
297
# Create an initial utmp file
298 e8d0903d Ermal
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
299 5b237745 Scott Ullrich
300 2e269da2 Scott Ullrich
echo -n "."
301 6fe4f291 Scott Ullrich
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
302 c268f10f Scott Ullrich
303 cdbc61b6 Scott Ullrich
# Make sure /etc/rc.conf doesn't exist.
304
if [ -f /etc/rc.conf ]; then
305 e8d0903d Ermal
    /bin/rm -rf /etc/rc.conf
306 cdbc61b6 Scott Ullrich
fi
307
308 7734aea6 Andrew Thompson
if [ ! "$PLATFORM" = "jail" ]; then
309
	# Launching kbdmux(4)
310
	if [ -f "/dev/kbdmux0" ]; then
311
		echo -n "."
312
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
313
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
314
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
315
	fi
316 4e7b2b27 Scott Ullrich
317 7734aea6 Andrew Thompson
	# Fire up unionfs if mount points exist.
318
	if [ -f /dist/uniondirs ]; then
319
		echo -n "."
320
		/etc/rc.d/unionfs start
321
	fi
322 b1ce7649 Scott Ullrich
fi
323 fa8f44ce Scott Ullrich
324 2e269da2 Scott Ullrich
echo "done."
325 deff30cd Scott Ullrich
326 64183253 Scott Ullrich
# Ensure gettytab is of a sane size
327
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
328
	echo ">>> Restoring /etc/gettytab due to unusal size"
329
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
330 416e6432 Ermal
	/bin/cp /etc/gettytab.bak /etc/gettytab
331 64183253 Scott Ullrich
fi
332
333 ad0d7518 Scott Ullrich
# Recreate capabilities DB
334 416e6432 Ermal
/usr/bin/cap_mkdb /etc/login.conf
335 ad0d7518 Scott Ullrich
336 40e46009 Scott Ullrich
# Run the php.ini setup file and populate
337
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
338 aa840cf9 Scott Ullrich
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
339 0cf5aa69 Scott Ullrich
340 206f684d Scott Ullrich
# Launch external configuration loader for supported platforms
341
if [ "$PLATFORM" = "embedded" ]; then
342 fb2e53da jim-p
	/usr/local/bin/php -q /etc/ecl.php
343 206f684d Scott Ullrich
fi
344
345
# Launch external configuration loader for supported platforms
346
if [ "$PLATFORM" = "nanobsd" ]; then
347 fb2e53da jim-p
	/usr/local/bin/php -q /etc/ecl.php
348 206f684d Scott Ullrich
fi
349
350
# Launch external configuration loader for supported platforms
351
if [ "$PLATFORM" = "pfSense" ]; then
352 690d24af Scott Ullrich
	/usr/local/bin/php -q /etc/ecl.php
353 206f684d Scott Ullrich
fi
354
355 490615d3 Scott Ullrich
if [ -f /etc/rc.custom_boot_early ]; then
356
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
357
	/etc/rc.custom_boot_early
358
	echo "Done"
359
fi
360
361 01599e5e Ermal
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
362 e8d0903d Ermal
363 b406ae66 Scott Ullrich
# let the PHP-based configuration subsystem set up the system now
364 8e2eb65e Scott Ullrich
echo -n "Launching the init system..."
365 e8d0903d Ermal
/bin/rm -f /cf/conf/backup/backup.cache
366
/bin/rm -f /root/lighttpd*
367
/usr/bin/touch $varrunpath/booting
368 b406ae66 Scott Ullrich
/etc/rc.bootup
369
370 c1da5030 Scott Ullrich
# If a shell was selected from recovery 
371
# console then just drop to the shell now.
372
if [ -f "/tmp/donotbootup" ]; then
373 b1d04497 Scott Ullrich
	echo "Dropping to recovery shell."
374 c1da5030 Scott Ullrich
	exit 0
375
fi
376
377 0c5e431d Scott Ullrich
echo -n "Starting CRON... "
378 ea83ac64 Scott Ullrich
cd /tmp && /usr/sbin/cron -s 2>/dev/null
379 0c5e431d Scott Ullrich
echo "done."
380 3e08b3c1 Scott Ullrich
381 5be5825e Scott Ullrich
# Start packages
382
/etc/rc.start_packages
383 3bd1bd72 Scott Ullrich
384 e8d0903d Ermal
/bin/rm -rf /usr/local/pkg/pf/CVS
385 bc086d51 Scott Ullrich
386 0092b3bd mgrooms
# Start ping handler every 240 seconds
387 e8d0903d Ermal
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
388 f2025e91 Scott Ullrich
389 0092b3bd mgrooms
# Start account expire handler every hour
390 41fb483a Ermal
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
391 0092b3bd mgrooms
392 f6ba4bd1 Scott Ullrich
# Start alias url updater every 24 hours
393 e8d0903d Ermal
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
394 f6ba4bd1 Scott Ullrich
395 c432da9c Scott Ullrich
/bin/chmod a+rw /tmp/.
396 b569598b Scott Ullrich
397 e393a4a8 Scott Ullrich
echo "Bootup complete"
398 416e6432 Ermal
/bin/rm $varrunpath/booting
399 1ba9533c Scott Ullrich
400 2d4be1c5 Scott Ullrich
/usr/local/bin/beep.sh start 2>&1 >/dev/null
401 e393a4a8 Scott Ullrich
402 4171fa68 Scott Ullrich
# Reset the cache.  read-only requires this.
403 7734aea6 Andrew Thompson
/bin/rm -f /tmp/config.cache
404 4171fa68 Scott Ullrich
405 d35cf0de Scott Ullrich
exit 0