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
MANUFACTURER="huawei|zte"
90
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
91
if [ "$CDDEVICE" != "" ]; then
92
	cdcontrol -f /dev/"$CDDEVICE" eject
93
fi
94

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

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

    
109
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
110
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
111
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
112

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

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

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

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

    
152
if [ "$PLATFORM" = "cdrom" ] ; then
153
	echo -n "Mounting unionfs directories..."
154
	/bin/mkdir /tmp/unionfs
155
	/bin/mkdir /tmp/unionfs/usr
156
	/bin/mkdir /tmp/unionfs/root
157
	/bin/mkdir /tmp/unionfs/sbin
158
	/bin/mkdir /tmp/unionfs/bin
159
	/bin/mkdir /tmp/unionfs/boot
160
	/bin/mkdir /tmp/unionfs/confdefault
161
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
162
	/sbin/mount_unionfs /tmp/unionfs/root /root/
163
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
164
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
165
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
166
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
167
	echo "done."
168
fi
169

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

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

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

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

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

    
200
# Setup compatibility link for packages that
201
# have trouble overriding the PREFIX configure
202
# argument since we build our packages in a
203
# seperated PREFIX area
204
# Only create if symlink does not exist. 
205
if [ ! -h /tmp/tmp ]; then
206
    /bin/ln -hfs / /tmp/tmp
207
fi
208

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

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

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

    
227
if [ ! -L /etc/sasyncd.conf ]; then
228
    /bin/mkdir -p /var/etc/
229
    /usr/bin/touch /var/etc/sasyncd.conf
230
    /bin/rm -rf /etc/sasyncd.conf
231
    /bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
232
    /usr/sbin/chown root:wheel /var/etc/sasyncd.conf
233
    /bin/chmod 0600 /var/etc/sasyncd.conf
234
fi
235

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

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

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

    
252
set -T
253
trap "echo 'Reboot interrupted'; exit 1" 3
254

    
255
# Remove old nameserver resolution files
256
/bin/rm -f /var/etc/nameserver*
257

    
258
# Create uploadbar tmp directory
259
/bin/mkdir -p /tmp/uploadbar
260
/bin/chmod 0777 /tmp/uploadbar
261

    
262
# make some directories in /var
263
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
264
/bin/rm -rf /var/run/*
265
if [ "$PLATFORM" != "pfSense" ]; then
266
	/bin/rm /var/log/* 2>/dev/null
267
fi
268

    
269
echo -n "."
270
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
271
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
272
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
273
for logfile in $LOG_FILES; do
274
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
275
		/usr/bin/touch /var/log/$logfile.log
276
	else 
277
		if [ ! -f /var/log/$logfile.log ]; then
278
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
279
				# generate fifolog files
280
				/usr/sbin/fifolog_create -s 511488 /var/log/$logfile.log
281
			else 
282
				/usr/sbin/clog -i -s 512144 /var/log/$logfile.log
283
			fi
284
		fi
285
	fi 
286
done
287

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

    
291
echo -n "."
292
if [ ! "$PLATFORM" = "jail" ]; then
293
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
294
	if [ "$DEVFS" = "0" ]; then
295
		mount_devfs devfs /dev
296
	fi
297
fi
298

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

    
302
echo -n "."
303
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
304

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

    
310
if [ ! "$PLATFORM" = "jail" ]; then
311
	# Launching kbdmux(4)
312
	if [ -f "/dev/kbdmux0" ]; then
313
		echo -n "."
314
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
315
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
316
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
317
	fi
318

    
319
	# Fire up unionfs if mount points exist.
320
	if [ -f /dist/uniondirs ]; then
321
		echo -n "."
322
		/etc/rc.d/unionfs start
323
	fi
324
fi
325

    
326
echo "done."
327

    
328
# Ensure gettytab is of a sane size
329
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
330
	echo ">>> Restoring /etc/gettytab due to unusal size"
331
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
332
	/bin/cp /etc/gettytab.bak /etc/gettytab
333
fi
334

    
335
# Recreate capabilities DB
336
/usr/bin/cap_mkdb /etc/login.conf
337

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

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

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

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

    
357
if [ -f /etc/rc.custom_boot_early ]; then
358
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
359
	/etc/rc.custom_boot_early
360
	echo "Done"
361
fi
362

    
363
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
364

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

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

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

    
383
# Start packages
384
/etc/rc.start_packages
385

    
386
/bin/rm -rf /usr/local/pkg/pf/CVS
387

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

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

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

    
397
/bin/chmod a+rw /tmp/.
398

    
399
echo "Bootup complete"
400
/bin/rm $varrunpath/booting
401

    
402
/usr/local/bin/beep.sh start 2>&1 >/dev/null
403

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

    
407
exit 0
(34-34/108)