Project

General

Profile

Download (11.6 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
else
79
	# Mount /. If it fails run a fsck.
80
	if [ "$PLATFORM" = "nanobsd" ]; then
81
		export PKG_TMPDIR=/root/
82
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
83
	else 
84
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
85
	fi
86

    
87
	# If /conf is a directory, convert it to a symlink to /cf/conf
88
	if [ -d "/conf" ]; then
89
		# If item is not a symlink then rm and recreate
90
		CONFPOINTSTO=`readlink /conf` 
91
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
92
			/bin/rm -rf /conf
93
			/bin/ln -s /cf/conf /conf
94
		fi
95
	fi
96

    
97
	if [ ! "$PLATFORM" = "jail" ]; then
98
		# Check to see if a compact flash mountpoint exists
99
		# If it fails to mount then run a fsck -fy
100
		if grep -q cf /etc/fstab; then
101
			/sbin/mount -w /cf 2>/dev/null
102
			/sbin/mount -uw /cf || \
103
				(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
104
		fi
105
	fi
106

    
107
	USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
108
	if [ "${PLATFORM}" = "nanobsd" ] || [ "${PLATFORM}" = "embedded" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
109
		/etc/rc.embedded
110
	fi
111
fi
112

    
113
/bin/rm -f /root/force_fsck
114
/bin/rm -f /root/TRIM_set
115
/bin/rm -f /root/TRIM_unset
116

    
117
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
118
if [ -f /etc/rc.disable_hdd_apm ]; then
119
	/etc/rc.disable_hdd_apm
120
fi
121

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

    
129
# sync pw database after mount.
130
rm -f /etc/spwd.db.tmp
131
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
132

    
133
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
134
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
135
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
136

    
137
if [ "$PLATFORM" = "pfSense" ]; then
138
	/sbin/mdmfs -S -M -s 4m md $varrunpath
139
fi
140

    
141
if [ "$hideplatform" -gt "0" ]; then
142
	platformbanner="" # hide the platform
143
else
144
	platformbanner=" on the '${PLATFORM}' platform"
145
fi
146

    
147
echo
148
cat /etc/ascii-art/pfsense-logo-small.txt
149
echo
150
echo
151
echo "Welcome to ${product} ${version} ${platformbanner} ..."
152
echo
153

    
154
if [ ! "$PLATFORM" = "jail" ]; then
155
	# Enable console output if its muted.
156
	/sbin/conscontrol mute off >/dev/null
157
fi
158

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

    
179
	if [ -d /root/var/db/pkg ]; then
180
		# User must have just disabled RAM disks, move these back into place.
181
		/bin/mkdir -p /var/db/pkg
182
		/bin/mv /root/var/db/pkg /var/db/pkg
183
		/bin/mkdir -p /var/db/pbi
184
		/bin/mv /root/var/db/pkg /var/db/pbi
185
	fi
186
fi
187

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

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

    
213
# Cleanup configuration files from previous instance
214
/bin/rm -rf /var/etc/*
215
/bin/rm -rf /var/tmp/*
216

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

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

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

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

    
248
if [ ! -L /etc/resolv.conf ]; then
249
    /bin/rm -rf /etc/resolv.conf
250
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
251
fi
252

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

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

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

    
276
if [ ! -L /etc/dhclient.conf ]; then
277
    /bin/rm -rf /etc/dhclient.conf
278
fi
279

    
280
if [ ! -d /var/tmp ]; then
281
	/bin/mkdir -p /var/tmp
282
fi
283

    
284
if [ ! -d /cf/conf/backup/ ]; then
285
	/bin/mkdir -p /cf/conf/backup/ 
286
fi
287

    
288
set -T
289
trap "echo 'Reboot interrupted'; exit 1" 3
290

    
291
# Remove old nameserver resolution files
292
/bin/rm -f /var/etc/nameserver*
293

    
294
# Create uploadbar tmp directory
295
/bin/mkdir -p /tmp/uploadbar
296
/bin/chmod 0777 /tmp/uploadbar
297

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

    
317
# change permissions on newly created fifolog files.
318
/bin/chmod 0600 /var/log/*.log
319

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

    
328
# Create an initial utmp file
329
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
330

    
331
echo -n "."
332
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
333

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

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

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

    
355
echo "done."
356

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

    
364
# Recreate capabilities DB
365
/usr/bin/cap_mkdb /etc/login.conf
366

    
367
# Run the php.ini setup file and populate
368
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
369
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
370

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

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

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

    
386
if [ -f /etc/rc.custom_boot_early ]; then
387
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
388
	/etc/rc.custom_boot_early
389
	echo "Done"
390
fi
391

    
392
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
393

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

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

    
408
echo -n "Starting CRON... "
409
cd /tmp && /usr/sbin/cron -s 2>/dev/null
410
echo "done."
411

    
412
# Start packages
413
/etc/rc.start_packages
414

    
415
/bin/rm -rf /usr/local/pkg/pf/CVS
416

    
417
# Start ping handler every 240 seconds
418
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
419

    
420
# Start account expire handler every hour
421
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /etc/rc.expireaccounts
422

    
423
# Start alias url updater every 24 hours
424
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /etc/rc.update_alias_url_data
425

    
426
/bin/chmod a+rw /tmp/.
427

    
428
echo "Bootup complete"
429
/bin/rm $varrunpath/booting
430

    
431
/usr/local/bin/beep.sh start 2>&1 >/dev/null
432

    
433
# Reset the cache.  read-only requires this.
434
/bin/rm -f /tmp/config.cache
435

    
436
exit 0
(34-34/109)