Project

General

Profile

Download (10.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
# Mount memory file system if it exists
35
echo "Mounting filesystems..."
36

    
37
# Handle ZFS read-only case
38
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
	fi
45
fi
46

    
47
if [ "$PLATFORM" = "cdrom" ]; then
48
	/etc/rc.cdrom
49
fi
50

    
51
if [ "$PLATFORM" = "embedded" ]; then
52
	export PKG_TMPDIR=/root/
53
	/etc/rc.embedded
54
fi
55

    
56
if [ "$PLATFORM" = "nanobsd" ]; then
57
	export PKG_TMPDIR=/root/
58
	/etc/rc.embedded
59
fi
60

    
61
if [ "$PLATFORM" = "pfSense" ]; then
62
	/sbin/mdmfs -S -M -s 4m md /var/run
63
fi
64

    
65
# Mount /. If it fails run a fsck.
66
if [ ! "$PLATFORM" = "cdrom" ] ; then
67
	if [ "$PLATFORM" = "nanobsd" ]; then
68
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
69
	else 
70
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
71
	fi
72
	# If /conf is a directory, convert it to a symlink to /cf/conf
73
	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
			/bin/rm -rf /conf
78
			/bin/ln -s /cf/conf /conf
79
		fi
80
	fi
81
fi
82

    
83
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
84
if [ -f /etc/rc.disable_hdd_apm ]; then
85
	/etc/rc.disable_hdd_apm
86
fi
87

    
88
#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
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
fi
102

    
103
# sync pw database after mount.
104
rm -f /etc/spwd.db.tmp
105
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
106

    
107
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

    
111
if [ "$hideplatform" -gt "0" ]; then
112
	platformbanner="" # hide the platform
113
else
114
	platformbanner=" on the '${PLATFORM}' platform"
115
fi
116

    
117
echo
118
cat /etc/ascii-art/pfsense-logo-small.txt
119
echo
120
echo
121
echo "Welcome to ${product} ${version} ${platformbanner} ..."
122
echo
123

    
124
if [ ! "$PLATFORM" = "jail" ]; then
125
	# Enable console output if its muted.
126
	/sbin/conscontrol mute off >/dev/null
127
fi
128

    
129
if [ "$PLATFORM" = "cdrom" ] ; then
130
	# do nothing for cdrom platform
131
elif [ "$PLATFORM" = "embedded" ] ; then
132
    # do nothing for embedded platform
133
elif [ "$PLATFORM" = "nanobsd" ] ; then
134
	# Ensure that old-style PKG packages can be persistent across reboots
135
	/bin/mkdir -p /root/var/db/pkg
136
	/bin/rm -rf /var/db/pkg
137
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
138
	# 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
elif [ "$PLATFORM" = "jail" ]; then
143
	# do nothing for jail platform
144
else
145
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
146
	/sbin/swapon -a 2>/dev/null >/dev/null
147
	/etc/rc.savecore
148
fi
149

    
150
if [ "$PLATFORM" = "cdrom" ] ; then
151
	echo -n "Mounting unionfs directories..."
152
	/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
	echo "done."
166
fi
167

    
168
echo -n "Creating symlinks..."
169
# Make sure symlink is correct on embedded
170
if [ "$PLATFORM" = "embedded" ] ; then
171
	/bin/rm /conf
172
	/bin/ln -s /cf/conf/ /conf
173
fi
174

    
175
# Make sure symlink is correct on nanobsd
176
if [ "$PLATFORM" = "nanobsd" ] ; then
177
	/bin/rm /conf
178
	/bin/ln -s /cf/conf/ /conf
179
fi
180

    
181
# Repair symlinks if they are broken
182
if [ ! -L /etc/syslog.conf ]; then
183
	/bin/rm -rf /etc/syslog.conf
184
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
185
fi
186

    
187
# Repair symlinks if they are broken
188
if [ ! -L /etc/hosts ]; then
189
	/bin/rm -rf /etc/hosts
190
	/bin/ln -s /var/etc/hosts /etc/hosts
191
fi
192

    
193
if [ ! -L /etc/resolv.conf ]; then
194
    /bin/rm -rf /etc/resolv.conf
195
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
196
fi
197

    
198
# 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
# Only create if symlink does not exist. 
203
if [ ! -h /tmp/tmp ]; then
204
    /bin/ln -hfs / /tmp/tmp
205
fi
206

    
207
# Make sure our /tmp is 777 + Sticky
208
if [ ! "$PLATFORM" = "cdrom" ] ; then
209
	/bin/rm -rf /tmp/*
210
fi
211
/bin/chmod 1777 /tmp
212

    
213
if [ ! "$PLATFORM" = "cdrom" ] ; then
214
	# Malloc debugging check
215
	if [ -L /etc/malloc.conf ]; then
216
	    #ln -s aj /etc/malloc.conf
217
		/bin/rm /etc/malloc.conf
218
	fi
219
fi
220

    
221
if [ ! -L /etc/dhclient.conf ]; then
222
    /bin/rm -rf /etc/dhclient.conf
223
fi
224

    
225
if [ ! -L /etc/sasyncd.conf ]; then
226
    /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
fi
233

    
234
if [ ! -d /var/tmp ]; then
235
	/bin/mkdir -p /var/tmp
236
fi
237

    
238
if [ ! -d /cf/conf/backup/ ]; then
239
	/bin/mkdir -p /cf/conf/backup/ 
240
fi
241

    
242
# OpenVPN storage
243
if [ ! -d /var/etc/openvpn ]; then
244
	/bin/mkdir -p /var/etc/openvpn
245
fi
246
if [ ! -d /var/etc/openvpn-csc ]; then
247
	/bin/mkdir -p /var/etc/openvpn-csc
248
fi
249

    
250
set -T
251
trap "echo 'Reboot interrupted'; exit 1" 3
252

    
253
# Remove old nameserver resolution files
254
/bin/rm -f /var/etc/nameserver*
255

    
256
# Create uploadbar tmp directory
257
/bin/mkdir -p /tmp/uploadbar
258
/bin/chmod 0777 /tmp/uploadbar
259

    
260
# make some directories in /var
261
/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
if [ "$PLATFORM" != "pfSense" ]; then
264
	/bin/rm /var/log/* 2>/dev/null
265
fi
266

    
267
echo -n "."
268
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
269
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
270
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
271
for logfile in $LOG_FILES; do
272
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
273
		/usr/bin/touch /var/log/$logfile.log
274
	else 
275
		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
		fi
283
	fi 
284
done
285

    
286
# change permissions on newly created fifolog files.
287
/bin/chmod 0600 /var/log/*.log
288

    
289
echo -n "."
290
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
fi
296

    
297
# Create an initial utmp file
298
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
299

    
300
echo -n "."
301
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
302

    
303
# Make sure /etc/rc.conf doesn't exist.
304
if [ -f /etc/rc.conf ]; then
305
    /bin/rm -rf /etc/rc.conf
306
fi
307

    
308
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

    
317
	# 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
fi
323

    
324
echo "done."
325

    
326
# 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
	/bin/cp /etc/gettytab.bak /etc/gettytab
331
fi
332

    
333
# Recreate capabilities DB
334
/usr/bin/cap_mkdb /etc/login.conf
335

    
336
# Run the php.ini setup file and populate
337
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
338
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
339

    
340
# Launch external configuration loader for supported platforms
341
if [ "$PLATFORM" = "embedded" ]; then
342
	/usr/local/bin/php -q /etc/ecl.php
343
fi
344

    
345
# Launch external configuration loader for supported platforms
346
if [ "$PLATFORM" = "nanobsd" ]; then
347
	/usr/local/bin/php -q /etc/ecl.php
348
fi
349

    
350
# Launch external configuration loader for supported platforms
351
if [ "$PLATFORM" = "pfSense" ]; then
352
	/usr/local/bin/php -q /etc/ecl.php
353
fi
354

    
355
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
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
362

    
363
# let the PHP-based configuration subsystem set up the system now
364
echo -n "Launching the init system..."
365
/bin/rm -f /cf/conf/backup/backup.cache
366
/bin/rm -f /root/lighttpd*
367
/usr/bin/touch $varrunpath/booting
368
/etc/rc.bootup
369

    
370
# If a shell was selected from recovery 
371
# console then just drop to the shell now.
372
if [ -f "/tmp/donotbootup" ]; then
373
	echo "Dropping to recovery shell."
374
	exit 0
375
fi
376

    
377
echo -n "Starting CRON... "
378
cd /tmp && /usr/sbin/cron -s 2>/dev/null
379
echo "done."
380

    
381
# Start packages
382
/etc/rc.start_packages
383

    
384
/bin/rm -rf /usr/local/pkg/pf/CVS
385

    
386
# Start ping handler every 240 seconds
387
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
388

    
389
# Start account expire handler every hour
390
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
391

    
392
# Start alias url updater every 24 hours
393
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
394

    
395
/bin/chmod a+rw /tmp/.
396

    
397
echo "Bootup complete"
398
/bin/rm $varrunpath/booting
399

    
400
/usr/local/bin/beep.sh start 2>&1 >/dev/null
401

    
402
# Reset the cache.  read-only requires this.
403
/bin/rm -f /tmp/config.cache
404

    
405
exit 0
(34-34/107)