Project

General

Profile

Download (12.2 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 -y -t ufs /
37
	if [ "$PLATFORM" = "nanobsd" ]; then
38
		/sbin/fsck -y -t ufs /cf
39
	fi
40
fi
41

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

    
65
# Mount memory file system if it exists
66
echo "Mounting filesystems..."
67

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

    
78
if [ "${PLATFORM}" = "cdrom" ]; then
79
	/etc/rc.cdrom
80
else
81
	# Mount /. If it fails run a fsck.
82
	if [ "$PLATFORM" = "nanobsd" ]; then
83
		export PKG_TMPDIR=/root/
84
		/sbin/mount -uw / || (/sbin/fsck -y /; /sbin/fsck -y /cf; /sbin/mount -uw /)
85
	else 
86
		/sbin/mount -a || (/sbin/fsck -y /; /sbin/mount -a)
87
	fi
88

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

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

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

    
115
/bin/rm -f /root/force_fsck
116
/bin/rm -f /root/TRIM_set
117
/bin/rm -f /root/TRIM_unset
118

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

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

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

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

    
139
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
140
	/sbin/mdmfs -S -M -s 4m md $varrunpath
141
fi
142

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
290
set -T
291
trap "echo 'Reboot interrupted'; exit 1" 3
292

    
293
# Remove old nameserver resolution files
294
/bin/rm -f /var/etc/nameserver*
295

    
296
# Create uploadbar tmp directory
297
/bin/mkdir -p /tmp/uploadbar
298
/bin/chmod 0777 /tmp/uploadbar
299

    
300
echo -n "."
301
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
302
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
303
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
304

    
305
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
306
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
307
	DEFAULT_LOG_FILE_SIZE=511488
308
fi
309

    
310
for logfile in $LOG_FILES; do
311
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
312
		/usr/bin/touch /var/log/$logfile.log
313
	else 
314
		if [ ! -f /var/log/$logfile.log ]; then
315
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
316
				# generate fifolog files
317
				/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
318
			else 
319
				/usr/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
320
			fi
321
		fi
322
	fi 
323
done
324

    
325
# change permissions on newly created fifolog files.
326
/bin/chmod 0600 /var/log/*.log
327

    
328
echo -n "."
329
if [ ! "$PLATFORM" = "jail" ]; then
330
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
331
	if [ "$DEVFS" = "0" ]; then
332
		mount_devfs devfs /dev
333
	fi
334
fi
335

    
336
# Create an initial utmp file
337
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
338

    
339
echo -n "."
340
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
341

    
342
# Make sure /etc/rc.conf doesn't exist.
343
if [ -f /etc/rc.conf ]; then
344
    /bin/rm -rf /etc/rc.conf
345
fi
346

    
347
if [ ! "$PLATFORM" = "jail" ]; then
348
	# Launching kbdmux(4)
349
	if [ -f "/dev/kbdmux0" ]; then
350
		echo -n "."
351
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
352
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
353
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
354
	fi
355

    
356
	# Fire up unionfs if mount points exist.
357
	if [ -f /dist/uniondirs ]; then
358
		echo -n "."
359
		/etc/rc.d/unionfs start
360
	fi
361
fi
362

    
363
echo "done."
364

    
365
# Ensure gettytab is of a sane size
366
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
367
	echo ">>> Restoring /etc/gettytab due to unusal size"
368
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
369
	/bin/cp /etc/gettytab.bak /etc/gettytab
370
fi
371

    
372
# Recreate capabilities DB
373
/usr/bin/cap_mkdb /etc/login.conf
374

    
375
# Run the php.ini setup file and populate
376
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
377
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
378
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
379

    
380
# Launch external configuration loader for supported platforms
381
if [ "$PLATFORM" = "embedded" ]; then
382
	/usr/local/sbin/fcgicli -f /etc/ecl.php
383
fi
384

    
385
# Launch external configuration loader for supported platforms
386
if [ "$PLATFORM" = "nanobsd" ]; then
387
	/usr/local/sbin/fcgicli -f /etc/ecl.php
388
fi
389

    
390
# Launch external configuration loader for supported platforms
391
if [ "$PLATFORM" = "pfSense" ]; then
392
	/usr/local/sbin/fcgicli -f /etc/ecl.php
393
fi
394

    
395
if [ -f /etc/rc.custom_boot_early ]; then
396
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
397
	/etc/rc.custom_boot_early
398
	echo "Done"
399
fi
400

    
401
export fcgipath=/var/run/php-fpm.socket
402
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
403

    
404
# let the PHP-based configuration subsystem set up the system now
405
echo -n "Launching the init system..."
406
/bin/rm -f /cf/conf/backup/backup.cache
407
/bin/rm -f /root/lighttpd*
408
/usr/bin/touch $varrunpath/booting
409
/etc/rc.bootup
410

    
411
# /etc/rc.bootup unset $g['booting'], remove file right now to be
412
# consistent
413
/bin/rm $varrunpath/booting
414

    
415
# If a shell was selected from recovery 
416
# console then just drop to the shell now.
417
if [ -f "/tmp/donotbootup" ]; then
418
	echo "Dropping to recovery shell."
419
	exit 0
420
fi
421

    
422
echo -n "Starting CRON... "
423
cd /tmp && /usr/sbin/cron -s 2>/dev/null
424
echo "done."
425

    
426
# Start packages
427
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
428

    
429
/bin/rm -rf /usr/local/pkg/pf/CVS
430

    
431
# Start ping handler every 240 seconds
432
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
433

    
434
# Start account expire handler every hour
435
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid '/usr/local/sbin/fcgicli -f /etc/rc.expireaccounts'
436

    
437
# Start alias url updater every 24 hours
438
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid '/usr/local/sbin/fcgicli -f /etc/rc.update_alias_url_data'
439

    
440
/bin/chmod a+rw /tmp/.
441

    
442
echo "Bootup complete"
443

    
444
/usr/local/bin/beep.sh start 2>&1 >/dev/null
445

    
446
# Reset the cache.  read-only requires this.
447
/bin/rm -f /tmp/config.cache
448

    
449
exit 0
(35-35/111)