Project

General

Profile

Download (10.4 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
# Mount /. If it fails run a fsck.
62
if [ ! "$PLATFORM" = "cdrom" ] ; then
63
	if [ "$PLATFORM" = "nanobsd" ]; then
64
		/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
65
	else 
66
		/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
67
	fi
68
	# If /conf is a directory, convert it to a symlink to /cf/conf
69
	if [ -d "/conf" ]; then
70
		# If item is not a symlink then rm and recreate
71
		CONFPOINTSTO=`readlink /conf` 
72
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
73
			/bin/rm -rf /conf
74
			/bin/ln -s /cf/conf /conf
75
		fi
76
	fi
77
fi
78

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

    
84
#Eject CD devices on 3G modems
85
MANUFACTURER="huawei|zte"
86
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
87
if [ "$CDDEVICE" != "" ]; then
88
	cdcontrol -f /dev/"$CDDEVICE" eject
89
fi
90

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

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

    
105
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
106
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
107
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
108

    
109
if [ "$PLATFORM" = "pfSense" ]; then
110
	/sbin/mdmfs -S -M -s 4m md $varrunpath
111
fi
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
# make some directories in /var
171
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
172
/bin/rm -rf $varrunpath/*
173
if [ "$PLATFORM" != "pfSense" ]; then
174
	/bin/rm /var/log/* 2>/dev/null
175
fi
176

    
177
# Cleanup configuration files from previous instance
178
/bin/rm -rf /var/etc/*
179

    
180
echo -n "Creating symlinks..."
181
# Make sure symlink is correct on embedded
182
if [ "$PLATFORM" = "embedded" ] ; then
183
	/bin/rm /conf
184
	/bin/ln -s /cf/conf/ /conf
185
fi
186

    
187
# Make sure symlink is correct on nanobsd
188
if [ "$PLATFORM" = "nanobsd" ] ; then
189
	/bin/rm /conf
190
	/bin/ln -s /cf/conf/ /conf
191
fi
192

    
193
# Repair symlinks if they are broken
194
if [ -f /etc/newsyslog.conf ]; then
195
	/bin/rm -f /etc/newsyslog.conf
196
fi
197
if [ ! -L /etc/syslog.conf ]; then
198
	/bin/rm -rf /etc/syslog.conf
199
	if [ ! -f /var/etc/syslog.conf ]; then
200
		touch /var/etc/syslog.conf
201
	fi
202
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
203
fi
204

    
205
# Repair symlinks if they are broken
206
if [ ! -L /etc/hosts ]; then
207
	/bin/rm -rf /etc/hosts
208
	/bin/ln -s /var/etc/hosts /etc/hosts
209
fi
210

    
211
if [ ! -L /etc/resolv.conf ]; then
212
    /bin/rm -rf /etc/resolv.conf
213
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
214
fi
215

    
216
# Setup compatibility link for packages that
217
# have trouble overriding the PREFIX configure
218
# argument since we build our packages in a
219
# seperated PREFIX area
220
# Only create if symlink does not exist. 
221
if [ ! -h /tmp/tmp ]; then
222
    /bin/ln -hfs / /tmp/tmp
223
fi
224

    
225
# Make sure our /tmp is 777 + Sticky
226
if [ ! "$PLATFORM" = "cdrom" ] ; then
227
	/bin/rm -rf /tmp/*
228
fi
229
/bin/chmod 1777 /tmp
230

    
231
if [ ! "$PLATFORM" = "cdrom" ] ; then
232
	# Malloc debugging check
233
	if [ -L /etc/malloc.conf ]; then
234
	    #ln -s aj /etc/malloc.conf
235
		/bin/rm /etc/malloc.conf
236
	fi
237
fi
238

    
239
if [ ! -L /etc/dhclient.conf ]; then
240
    /bin/rm -rf /etc/dhclient.conf
241
fi
242

    
243
if [ ! -d /var/tmp ]; then
244
	/bin/mkdir -p /var/tmp
245
fi
246

    
247
if [ ! -d /cf/conf/backup/ ]; then
248
	/bin/mkdir -p /cf/conf/backup/ 
249
fi
250

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

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

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

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

    
280
# change permissions on newly created fifolog files.
281
/bin/chmod 0600 /var/log/*.log
282

    
283
echo -n "."
284
if [ ! "$PLATFORM" = "jail" ]; then
285
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
286
	if [ "$DEVFS" = "0" ]; then
287
		mount_devfs devfs /dev
288
	fi
289
fi
290

    
291
# Create an initial utmp file
292
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
293

    
294
echo -n "."
295
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
296

    
297
# Make sure /etc/rc.conf doesn't exist.
298
if [ -f /etc/rc.conf ]; then
299
    /bin/rm -rf /etc/rc.conf
300
fi
301

    
302
if [ ! "$PLATFORM" = "jail" ]; then
303
	# Launching kbdmux(4)
304
	if [ -f "/dev/kbdmux0" ]; then
305
		echo -n "."
306
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
307
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
308
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
309
	fi
310

    
311
	# Fire up unionfs if mount points exist.
312
	if [ -f /dist/uniondirs ]; then
313
		echo -n "."
314
		/etc/rc.d/unionfs start
315
	fi
316
fi
317

    
318
echo "done."
319

    
320
# Ensure gettytab is of a sane size
321
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
322
	echo ">>> Restoring /etc/gettytab due to unusal size"
323
	echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
324
	/bin/cp /etc/gettytab.bak /etc/gettytab
325
fi
326

    
327
# Recreate capabilities DB
328
/usr/bin/cap_mkdb /etc/login.conf
329

    
330
# Run the php.ini setup file and populate
331
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
332
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
333

    
334
# Launch external configuration loader for supported platforms
335
if [ "$PLATFORM" = "embedded" ]; then
336
	/usr/local/bin/php -q /etc/ecl.php
337
fi
338

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

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

    
349
if [ -f /etc/rc.custom_boot_early ]; then
350
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
351
	/etc/rc.custom_boot_early
352
	echo "Done"
353
fi
354

    
355
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
356

    
357
# let the PHP-based configuration subsystem set up the system now
358
echo -n "Launching the init system..."
359
/bin/rm -f /cf/conf/backup/backup.cache
360
/bin/rm -f /root/lighttpd*
361
/usr/bin/touch $varrunpath/booting
362
/etc/rc.bootup
363

    
364
# If a shell was selected from recovery 
365
# console then just drop to the shell now.
366
if [ -f "/tmp/donotbootup" ]; then
367
	echo "Dropping to recovery shell."
368
	exit 0
369
fi
370

    
371
echo -n "Starting CRON... "
372
cd /tmp && /usr/sbin/cron -s 2>/dev/null
373
echo "done."
374

    
375
# Start packages
376
/etc/rc.start_packages
377

    
378
/bin/rm -rf /usr/local/pkg/pf/CVS
379

    
380
# Start ping handler every 240 seconds
381
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
382

    
383
# Start account expire handler every hour
384
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /etc/rc.expireaccounts
385

    
386
# Start alias url updater every 24 hours
387
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /etc/rc.update_alias_url_data
388

    
389
/bin/chmod a+rw /tmp/.
390

    
391
echo "Bootup complete"
392
/bin/rm $varrunpath/booting
393

    
394
/usr/local/bin/beep.sh start 2>&1 >/dev/null
395

    
396
# Reset the cache.  read-only requires this.
397
/bin/rm -f /tmp/config.cache
398

    
399
exit 0
(34-34/108)