Project

General

Profile

Download (11.3 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-2010 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
HOME=/
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
20
export HOME PATH
21

    
22
# Set our operating platform
23
PLATFORM=`/bin/cat /etc/platform`
24

    
25
# Set our current version
26
version=`/bin/cat /etc/version`
27

    
28
# Setup dumpdev/ddb/savecore"
29
echo "Configuring crash dumps..."
30
if [ "$PLATFORM" = "pfSense" ]; then
31
	/etc/rc.dumpon
32
fi
33

    
34
if [ -e /root/force_fsck ]; then
35
	echo "Forcing filesystem check..."
36
	/sbin/fsck -fy -t ufs /
37
	if [ "$PLATFORM" = "nanobsd" ]; then
38
		/sbin/fsck -fy -t ufs /cf
39
	fi
40
fi
41

    
42
TUNEFS_STATUS=`/sbin/tunefs -p / 2>&1 | /usr/bin/grep trim: | /usr/bin/awk '{print $4;}'`
43
if [ -e /root/TRIM_set ] && [ "${TUNEFS_STATUS}" = "disabled" ]; then
44
	echo "Enabling TRIM support"
45
	/sbin/tunefs -t enable /
46
	if [ "$PLATFORM" = "nanobsd" ]; then
47
		/sbin/tunefs -t enable /cf
48
	fi
49
	echo "Rebooting in 5 seconds after enabling TRIM..."
50
	sleep 5
51
	/sbin/reboot
52
elif [ -e /root/TRIM_unset ] && [ "${TUNEFS_STATUS}" = "enabled" ]; then
53
	echo "Disabling TRIM support"
54
	/sbin/tunefs -t disable /
55
	if [ "$PLATFORM" = "nanobsd" ]; then
56
		/sbin/tunefs -t disable /cf
57
	fi
58
	echo "Rebooting in 5 seconds after disabling TRIM..."
59
	sleep 5
60
	/sbin/reboot
61
fi
62

    
63
# Mount memory file system if it exists
64
echo "Mounting filesystems..."
65

    
66
# Handle ZFS read-only case
67
if [ "$PLATFORM" = "pfSense" ]; then
68
	if [ -f /usr/bin/grep ]; then
69
		WHEREISROOT=`/sbin/mount | /usr/bin/grep " / " | /usr/bin/grep "tank" | /usr/bin/cut -d' ' -f1`
70
		if [ "$WHEREISROOT" != "" ]; then
71
			/sbin/zfs set readonly=off $WHEREISROOT
72
		fi
73
	fi
74
fi
75

    
76
if [ "$PLATFORM" = "cdrom" ]; then
77
	/etc/rc.cdrom
78
fi
79

    
80
if [ "$PLATFORM" = "embedded" ]; then
81
	export PKG_TMPDIR=/root/
82
	/etc/rc.embedded
83
fi
84

    
85
if [ "$PLATFORM" = "nanobsd" ]; then
86
	export PKG_TMPDIR=/root/
87
	/etc/rc.embedded
88
fi
89

    
90
# Mount /. If it fails run a fsck.
91
if [ ! "$PLATFORM" = "cdrom" ] ; then
92
	if [ "$PLATFORM" = "nanobsd" ]; then
93
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
94
	else 
95
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
96
	fi
97
	# If /conf is a directory, convert it to a symlink to /cf/conf
98
	if [ -d "/conf" ]; then
99
		# If item is not a symlink then rm and recreate
100
		CONFPOINTSTO=`readlink /conf` 
101
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
102
			/bin/rm -rf /conf
103
			/bin/ln -s /cf/conf /conf
104
		fi
105
	fi
106
fi
107

    
108
/bin/rm -f /root/force_fsck
109
/bin/rm -f /root/TRIM_set
110
/bin/rm -f /root/TRIM_unset
111

    
112
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
113
if [ -f /etc/rc.disable_hdd_apm ]; then
114
	/etc/rc.disable_hdd_apm
115
fi
116

    
117
#Eject CD devices on 3G modems
118
MANUFACTURER="huawei|zte"
119
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
120
if [ "$CDDEVICE" != "" ]; then
121
	cdcontrol -f /dev/"$CDDEVICE" eject
122
fi
123

    
124
if [ ! "$PLATFORM" = "jail" ]; then
125
	# Check to see if a compact flash mountpoint exists
126
	# If it fails to mount then run a fsck -fy
127
	if grep -q cf /etc/fstab; then
128
		/sbin/mount -w /cf 2>/dev/null
129
		/sbin/mount -uw /cf || \
130
			(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
131
	fi
132
fi
133

    
134
# sync pw database after mount.
135
rm -f /etc/spwd.db.tmp
136
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
137

    
138
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
139
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
140
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
141

    
142
if [ "$PLATFORM" = "pfSense" ]; then
143
	/sbin/mdmfs -S -M -s 4m md $varrunpath
144
fi
145

    
146
if [ "$hideplatform" -gt "0" ]; then
147
	platformbanner="" # hide the platform
148
else
149
	platformbanner=" on the '${PLATFORM}' platform"
150
fi
151

    
152
echo
153
cat /etc/ascii-art/pfsense-logo-small.txt
154
echo
155
echo
156
echo "Welcome to ${product} ${version} ${platformbanner} ..."
157
echo
158

    
159
if [ ! "$PLATFORM" = "jail" ]; then
160
	# Enable console output if its muted.
161
	/sbin/conscontrol mute off >/dev/null
162
fi
163

    
164
if [ "$PLATFORM" = "cdrom" ] ; then
165
	# do nothing for cdrom platform
166
elif [ "$PLATFORM" = "embedded" ] ; then
167
    # do nothing for embedded platform
168
elif [ "$PLATFORM" = "nanobsd" ] ; then
169
	# Ensure that old-style PKG packages can be persistent across reboots
170
	/bin/mkdir -p /root/var/db/pkg
171
	/bin/rm -rf /var/db/pkg
172
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
173
	# Ensure that PBI packages can be persistent across reboots
174
	/bin/mkdir -p /root/var/db/pbi
175
	/bin/rm -rf /var/db/pbi
176
	/bin/ln -s /root/var/db/pbi/ /var/db/pbi
177
elif [ "$PLATFORM" = "jail" ]; then
178
	# do nothing for jail platform
179
else
180
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
181
	/sbin/swapon -a 2>/dev/null >/dev/null
182
	/etc/rc.savecore
183
fi
184

    
185
if [ "$PLATFORM" = "cdrom" ] ; then
186
	echo -n "Mounting unionfs directories..."
187
	/bin/mkdir /tmp/unionfs
188
	/bin/mkdir /tmp/unionfs/usr
189
	/bin/mkdir /tmp/unionfs/root
190
	/bin/mkdir /tmp/unionfs/sbin
191
	/bin/mkdir /tmp/unionfs/bin
192
	/bin/mkdir /tmp/unionfs/boot
193
	/bin/mkdir /tmp/unionfs/confdefault
194
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
195
	/sbin/mount_unionfs /tmp/unionfs/root /root/
196
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
197
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
198
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
199
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
200
	echo "done."
201
fi
202

    
203
# make some directories in /var
204
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
205
/bin/rm -rf $varrunpath/*
206
if [ "$PLATFORM" != "pfSense" ]; then
207
	/bin/rm /var/log/* 2>/dev/null
208
fi
209

    
210
# Cleanup configuration files from previous instance
211
/bin/rm -rf /var/etc/*
212
/bin/rm -rf /var/tmp/*
213

    
214
echo -n "Creating symlinks..."
215
# Make sure symlink is correct on embedded
216
if [ "$PLATFORM" = "embedded" ] ; then
217
	/bin/rm /conf
218
	/bin/ln -s /cf/conf/ /conf
219
fi
220

    
221
# Make sure symlink is correct on nanobsd
222
if [ "$PLATFORM" = "nanobsd" ] ; then
223
	/bin/rm /conf
224
	/bin/ln -s /cf/conf/ /conf
225
fi
226

    
227
# Repair symlinks if they are broken
228
if [ -f /etc/newsyslog.conf ]; then
229
	/bin/rm -f /etc/newsyslog.conf
230
fi
231
if [ ! -L /etc/syslog.conf ]; then
232
	/bin/rm -rf /etc/syslog.conf
233
	if [ ! -f /var/etc/syslog.conf ]; then
234
		touch /var/etc/syslog.conf
235
	fi
236
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
237
fi
238

    
239
# Repair symlinks if they are broken
240
if [ ! -L /etc/hosts ]; then
241
	/bin/rm -rf /etc/hosts
242
	/bin/ln -s /var/etc/hosts /etc/hosts
243
fi
244

    
245
if [ ! -L /etc/resolv.conf ]; then
246
    /bin/rm -rf /etc/resolv.conf
247
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
248
fi
249

    
250
# Setup compatibility link for packages that
251
# have trouble overriding the PREFIX configure
252
# argument since we build our packages in a
253
# seperated PREFIX area
254
# Only create if symlink does not exist. 
255
if [ ! -h /tmp/tmp ]; then
256
    /bin/ln -hfs / /tmp/tmp
257
fi
258

    
259
# Make sure our /tmp is 777 + Sticky
260
if [ ! "$PLATFORM" = "cdrom" ] ; then
261
	/bin/rm -rf /tmp/*
262
fi
263
/bin/chmod 1777 /tmp
264

    
265
if [ ! "$PLATFORM" = "cdrom" ] ; then
266
	# Malloc debugging check
267
	if [ -L /etc/malloc.conf ]; then
268
	    #ln -s aj /etc/malloc.conf
269
		/bin/rm /etc/malloc.conf
270
	fi
271
fi
272

    
273
if [ ! -L /etc/dhclient.conf ]; then
274
    /bin/rm -rf /etc/dhclient.conf
275
fi
276

    
277
if [ ! -d /var/tmp ]; then
278
	/bin/mkdir -p /var/tmp
279
fi
280

    
281
if [ ! -d /cf/conf/backup/ ]; then
282
	/bin/mkdir -p /cf/conf/backup/ 
283
fi
284

    
285
set -T
286
trap "echo 'Reboot interrupted'; exit 1" 3
287

    
288
# Remove old nameserver resolution files
289
/bin/rm -f /var/etc/nameserver*
290

    
291
# Create uploadbar tmp directory
292
/bin/mkdir -p /tmp/uploadbar
293
/bin/chmod 0777 /tmp/uploadbar
294

    
295
echo -n "."
296
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
297
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
298
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
299
for logfile in $LOG_FILES; do
300
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
301
		/usr/bin/touch /var/log/$logfile.log
302
	else 
303
		if [ ! -f /var/log/$logfile.log ]; then
304
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
305
				# generate fifolog files
306
				/usr/sbin/fifolog_create -s 511488 /var/log/$logfile.log
307
			else 
308
				/usr/sbin/clog -i -s 512144 /var/log/$logfile.log
309
			fi
310
		fi
311
	fi 
312
done
313

    
314
# change permissions on newly created fifolog files.
315
/bin/chmod 0600 /var/log/*.log
316

    
317
echo -n "."
318
if [ ! "$PLATFORM" = "jail" ]; then
319
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
320
	if [ "$DEVFS" = "0" ]; then
321
		mount_devfs devfs /dev
322
	fi
323
fi
324

    
325
# Create an initial utmp file
326
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
327

    
328
echo -n "."
329
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
330

    
331
# Make sure /etc/rc.conf doesn't exist.
332
if [ -f /etc/rc.conf ]; then
333
    /bin/rm -rf /etc/rc.conf
334
fi
335

    
336
if [ ! "$PLATFORM" = "jail" ]; then
337
	# Launching kbdmux(4)
338
	if [ -f "/dev/kbdmux0" ]; then
339
		echo -n "."
340
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
341
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
342
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
343
	fi
344

    
345
	# Fire up unionfs if mount points exist.
346
	if [ -f /dist/uniondirs ]; then
347
		echo -n "."
348
		/etc/rc.d/unionfs start
349
	fi
350
fi
351

    
352
echo "done."
353

    
354
# Ensure gettytab is of a sane size
355
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
356
	echo ">>> Restoring /etc/gettytab due to unusal size"
357
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
358
	/bin/cp /etc/gettytab.bak /etc/gettytab
359
fi
360

    
361
# Recreate capabilities DB
362
/usr/bin/cap_mkdb /etc/login.conf
363

    
364
# Run the php.ini setup file and populate
365
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
366
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
367

    
368
# Launch external configuration loader for supported platforms
369
if [ "$PLATFORM" = "embedded" ]; then
370
	/usr/local/bin/php -q /etc/ecl.php
371
fi
372

    
373
# Launch external configuration loader for supported platforms
374
if [ "$PLATFORM" = "nanobsd" ]; then
375
	/usr/local/bin/php -q /etc/ecl.php
376
fi
377

    
378
# Launch external configuration loader for supported platforms
379
if [ "$PLATFORM" = "pfSense" ]; then
380
	/usr/local/bin/php -q /etc/ecl.php
381
fi
382

    
383
if [ -f /etc/rc.custom_boot_early ]; then
384
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
385
	/etc/rc.custom_boot_early
386
	echo "Done"
387
fi
388

    
389
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
390

    
391
# let the PHP-based configuration subsystem set up the system now
392
echo -n "Launching the init system..."
393
/bin/rm -f /cf/conf/backup/backup.cache
394
/bin/rm -f /root/lighttpd*
395
/usr/bin/touch $varrunpath/booting
396
/etc/rc.bootup
397

    
398
# If a shell was selected from recovery 
399
# console then just drop to the shell now.
400
if [ -f "/tmp/donotbootup" ]; then
401
	echo "Dropping to recovery shell."
402
	exit 0
403
fi
404

    
405
echo -n "Starting CRON... "
406
cd /tmp && /usr/sbin/cron -s 2>/dev/null
407
echo "done."
408

    
409
# Start packages
410
/etc/rc.start_packages
411

    
412
/bin/rm -rf /usr/local/pkg/pf/CVS
413

    
414
# Start ping handler every 240 seconds
415
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
416

    
417
# Start account expire handler every hour
418
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /etc/rc.expireaccounts
419

    
420
# Start alias url updater every 24 hours
421
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /etc/rc.update_alias_url_data
422

    
423
/bin/chmod a+rw /tmp/.
424

    
425
echo "Bootup complete"
426
/bin/rm $varrunpath/booting
427

    
428
/usr/local/bin/beep.sh start 2>&1 >/dev/null
429

    
430
# Reset the cache.  read-only requires this.
431
/bin/rm -f /tmp/config.cache
432

    
433
exit 0
(34-34/108)