Projet

Général

Profil

Télécharger (11,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc @ e792ac36

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
# Mount memory file system if it exists
43
echo "Mounting filesystems..."
44

    
45
# Handle ZFS read-only case
46
if [ "$PLATFORM" = "pfSense" ]; then
47
	if [ -f /usr/bin/grep ]; then
48
		ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
49
		if [ "$ZFSROOT" != "" ]; then
50
			/sbin/zfs set readonly=off $ZFSROOT
51
		fi
52
	fi
53
fi
54

    
55
if [ "${PLATFORM}" = "cdrom" ]; then
56
	/etc/rc.cdrom
57
else
58
	# Mount /. If it fails run a fsck.
59
	if [ "$PLATFORM" = "nanobsd" ]; then
60
		export PKG_TMPDIR=/root/
61
		/sbin/mount -uw / || (/sbin/fsck -y /; /sbin/fsck -y /cf; /sbin/mount -uw /)
62
	else 
63
		/sbin/mount -a || (/sbin/fsck -y /; /sbin/mount -a)
64
	fi
65

    
66
	# If /conf is a directory, convert it to a symlink to /cf/conf
67
	if [ -d "/conf" ]; then
68
		# If item is not a symlink then rm and recreate
69
		CONFPOINTSTO=`readlink /conf` 
70
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
71
			/bin/rm -rf /conf
72
			/bin/ln -s /cf/conf /conf
73
		fi
74
	fi
75

    
76
	if [ ! "$PLATFORM" = "jail" ]; then
77
		# Check to see if a compact flash mountpoint exists
78
		# If it fails to mount then run a fsck -y
79
		if grep -q cf /etc/fstab; then
80
			/sbin/mount -w /cf 2>/dev/null
81
			/sbin/mount -uw /cf || \
82
				(/sbin/umount /cf; /sbin/fsck -y /cf; /sbin/mount -w /cf)
83
		fi
84
	fi
85

    
86
	USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
87
	if [ "${PLATFORM}" = "nanobsd" ] || [ "${PLATFORM}" = "embedded" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
88
		/etc/rc.embedded
89
	fi
90
fi
91

    
92
/bin/rm -f /root/force_fsck
93
/bin/rm -f /root/TRIM_set
94
/bin/rm -f /root/TRIM_unset
95

    
96
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
97
if [ -f /etc/rc.disable_hdd_apm ]; then
98
	/etc/rc.disable_hdd_apm
99
fi
100

    
101
#Eject CD devices on 3G modems
102
MANUFACTURER="huawei|zte"
103
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
104
if [ "$CDDEVICE" != "" ]; then
105
	cdcontrol -f /dev/"$CDDEVICE" eject
106
fi
107

    
108
# sync pw database after mount.
109
rm -f /etc/spwd.db.tmp
110
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
111

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

    
116
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
117
	/sbin/mdmfs -S -M -s 4m md $varrunpath
118
fi
119

    
120
if [ "$hideplatform" -gt "0" ]; then
121
	platformbanner="" # hide the platform
122
else
123
	platformbanner=" on the '${PLATFORM}' platform"
124
fi
125

    
126
echo
127
cat /etc/ascii-art/pfsense-logo-small.txt
128
echo
129
echo
130
echo "Welcome to ${product} ${version} ${platformbanner} ..."
131
echo
132

    
133
if [ ! "$PLATFORM" = "jail" ]; then
134
	# Enable console output if its muted.
135
	/sbin/conscontrol mute off >/dev/null
136
fi
137

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

    
158
	if [ -d /root/var/db/pkg ]; then
159
		# User must have just disabled RAM disks, move these back into place.
160
		/bin/mkdir -p /var/db/pkg
161
		/bin/mv /root/var/db/pkg /var/db/pkg
162
		/bin/mkdir -p /var/db/pbi
163
		/bin/mv /root/var/db/pkg /var/db/pbi
164
	fi
165
fi
166

    
167
if [ "$PLATFORM" = "cdrom" ] ; then
168
	echo -n "Mounting unionfs directories..."
169
	/bin/mkdir /tmp/unionfs
170
	/bin/mkdir /tmp/unionfs/usr
171
	/bin/mkdir /tmp/unionfs/root
172
	/bin/mkdir /tmp/unionfs/sbin
173
	/bin/mkdir /tmp/unionfs/bin
174
	/bin/mkdir /tmp/unionfs/boot
175
	/bin/mkdir /tmp/unionfs/confdefault
176
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
177
	/sbin/mount_unionfs /tmp/unionfs/root /root/
178
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
179
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
180
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
181
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
182
	echo "done."
183
fi
184

    
185
# make some directories in /var
186
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
187
/bin/rm -rf $varrunpath/*
188
if [ "$PLATFORM" != "pfSense" ]; then
189
	/bin/rm /var/log/* 2>/dev/null
190
fi
191

    
192
# Cleanup configuration files from previous instance
193
/bin/rm -rf /var/etc/*
194
/bin/rm -rf /var/tmp/*
195

    
196
echo -n "Creating symlinks..."
197
# Make sure symlink is correct on embedded
198
if [ "$PLATFORM" = "embedded" ] ; then
199
	/bin/rm /conf
200
	/bin/ln -s /cf/conf/ /conf
201
fi
202

    
203
# Make sure symlink is correct on nanobsd
204
if [ "$PLATFORM" = "nanobsd" ] ; then
205
	/bin/rm /conf
206
	/bin/ln -s /cf/conf/ /conf
207
fi
208

    
209
# Repair symlinks if they are broken
210
if [ -f /etc/newsyslog.conf ]; then
211
	/bin/rm -f /etc/newsyslog.conf
212
fi
213
if [ ! -L /etc/syslog.conf ]; then
214
	/bin/rm -rf /etc/syslog.conf
215
	if [ ! -f /var/etc/syslog.conf ]; then
216
		touch /var/etc/syslog.conf
217
	fi
218
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
219
fi
220

    
221
# Repair symlinks if they are broken
222
if [ ! -L /etc/hosts ]; then
223
	/bin/rm -rf /etc/hosts
224
	/bin/ln -s /var/etc/hosts /etc/hosts
225
fi
226

    
227
if [ ! -L /etc/resolv.conf ]; then
228
    /bin/rm -rf /etc/resolv.conf
229
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
230
fi
231

    
232
# Setup compatibility link for packages that
233
# have trouble overriding the PREFIX configure
234
# argument since we build our packages in a
235
# separated PREFIX area
236
# Only create if symlink does not exist. 
237
if [ ! -h /tmp/tmp ]; then
238
    /bin/ln -hfs / /tmp/tmp
239
fi
240

    
241
# Make sure our /tmp is 777 + Sticky
242
if [ ! "$PLATFORM" = "cdrom" ] ; then
243
	/bin/rm -rf /tmp/*
244
fi
245
/bin/chmod 1777 /tmp
246

    
247
if [ ! "$PLATFORM" = "cdrom" ] ; then
248
	# Malloc debugging check
249
	if [ -L /etc/malloc.conf ]; then
250
	    #ln -s aj /etc/malloc.conf
251
		/bin/rm /etc/malloc.conf
252
	fi
253
fi
254

    
255
if [ ! -L /etc/dhclient.conf ]; then
256
    /bin/rm -rf /etc/dhclient.conf
257
fi
258

    
259
if [ ! -d /var/tmp ]; then
260
	/bin/mkdir -p /var/tmp
261
fi
262

    
263
if [ ! -d /cf/conf/backup/ ]; then
264
	/bin/mkdir -p /cf/conf/backup/ 
265
fi
266

    
267
set -T
268
trap "echo 'Reboot interrupted'; exit 1" 3
269

    
270
# Remove old nameserver resolution files
271
/bin/rm -f /var/etc/nameserver*
272

    
273
# Create uploadbar tmp directory
274
/bin/mkdir -p /tmp/uploadbar
275
/bin/chmod 0777 /tmp/uploadbar
276

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

    
296
# change permissions on newly created fifolog files.
297
/bin/chmod 0600 /var/log/*.log
298

    
299
echo -n "."
300
if [ ! "$PLATFORM" = "jail" ]; then
301
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
302
	if [ "$DEVFS" = "0" ]; then
303
		mount_devfs devfs /dev
304
	fi
305
fi
306

    
307
# Create an initial utmp file
308
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
309

    
310
echo -n "."
311
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
312

    
313
# Make sure /etc/rc.conf doesn't exist.
314
if [ -f /etc/rc.conf ]; then
315
    /bin/rm -rf /etc/rc.conf
316
fi
317

    
318
if [ ! "$PLATFORM" = "jail" ]; then
319
	# Launching kbdmux(4)
320
	if [ -f "/dev/kbdmux0" ]; then
321
		echo -n "."
322
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
323
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
324
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
325
	fi
326

    
327
	# Fire up unionfs if mount points exist.
328
	if [ -f /dist/uniondirs ]; then
329
		echo -n "."
330
		/etc/rc.d/unionfs start
331
	fi
332
fi
333

    
334
echo "done."
335

    
336
# Ensure gettytab is of a sane size
337
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
338
	echo ">>> Restoring /etc/gettytab due to unusual size"
339
	echo ">>> Restoring /etc/gettytab due to unusual size" | /usr/bin/logger
340
	/bin/cp /etc/gettytab.bak /etc/gettytab
341
fi
342

    
343
# Recreate capabilities DB
344
/usr/bin/cap_mkdb /etc/login.conf
345

    
346
# Run the php.ini setup file and populate
347
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
348
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
349

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

    
355
# Launch external configuration loader for supported platforms
356
if [ "$PLATFORM" = "nanobsd" ]; then
357
	/usr/local/bin/php -q /etc/ecl.php
358
fi
359

    
360
# Launch external configuration loader for supported platforms
361
if [ "$PLATFORM" = "pfSense" ]; then
362
	/usr/local/bin/php -q /etc/ecl.php
363
fi
364

    
365
if [ -f /etc/rc.custom_boot_early ]; then
366
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
367
	/etc/rc.custom_boot_early
368
	echo "Done"
369
fi
370

    
371
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
372

    
373
# let the PHP-based configuration subsystem set up the system now
374
echo -n "Launching the init system..."
375
/bin/rm -f /cf/conf/backup/backup.cache
376
/bin/rm -f /root/lighttpd*
377
/usr/bin/touch $varrunpath/booting
378
/etc/rc.bootup
379

    
380
# /etc/rc.bootup unset $g['booting'], remove file right now to be
381
# consistent
382
/bin/rm $varrunpath/booting
383

    
384
# If a shell was selected from recovery 
385
# console then just drop to the shell now.
386
if [ -f "/tmp/donotbootup" ]; then
387
	echo "Dropping to recovery shell."
388
	exit 0
389
fi
390

    
391
echo -n "Starting CRON... "
392
cd /tmp && /usr/sbin/cron -s 2>/dev/null
393
echo "done."
394

    
395
# Start packages
396
/etc/rc.start_packages
397

    
398
/bin/rm -rf /usr/local/pkg/pf/CVS
399

    
400
# Start ping handler every 240 seconds
401
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
402

    
403
# Start account expire handler every hour
404
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /etc/rc.expireaccounts
405

    
406
# Start alias url updater every 24 hours
407
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /etc/rc.update_alias_url_data
408

    
409
/bin/chmod a+rw /tmp/.
410

    
411
echo "Bootup complete"
412

    
413
/usr/local/bin/beep.sh start 2>&1 >/dev/null
414

    
415
# Reset the cache.  read-only requires this.
416
/bin/rm -f /tmp/config.cache
417

    
418
exit 0
(35-35/110)