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 [ "${PLATFORM}" = "nanobsd" ]; then
|
43
|
kldstat -qm zfs
|
44
|
if [ $? = 0 ]; then
|
45
|
kldunload zfs
|
46
|
fi
|
47
|
fi
|
48
|
|
49
|
# Mount memory file system if it exists
|
50
|
echo "Mounting filesystems..."
|
51
|
|
52
|
kldstat -qm zfs
|
53
|
# Handle ZFS read-only case
|
54
|
if [ "$PLATFORM" = "pfSense" ]; then
|
55
|
kldstat -qm zfs
|
56
|
if [ $? = 0 ]; then
|
57
|
ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
|
58
|
if [ $ZFSAVAILABLE -eq 0 ]; then
|
59
|
kldunload zfs
|
60
|
elif [ -f /usr/bin/grep ]; then
|
61
|
ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
|
62
|
if [ "$ZFSROOT" != "" ]; then
|
63
|
/sbin/zfs set readonly=off $ZFSROOT
|
64
|
fi
|
65
|
fi
|
66
|
fi
|
67
|
fi
|
68
|
|
69
|
if [ "${PLATFORM}" = "cdrom" ]; then
|
70
|
/etc/rc.cdrom
|
71
|
else
|
72
|
# Mount /. If it fails run a fsck.
|
73
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
74
|
export PKG_TMPDIR=/root/
|
75
|
/sbin/mount -uw / 2>/dev/null
|
76
|
mount_rc=$?
|
77
|
attempts=0
|
78
|
while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
|
79
|
/sbin/fsck -y /
|
80
|
/sbin/fsck -y /cf
|
81
|
/sbin/mount -uw / 2>/dev/null
|
82
|
mount_rc=$?
|
83
|
attempts=$((attempts+1))
|
84
|
done
|
85
|
else
|
86
|
/sbin/mount -a 2>/dev/null
|
87
|
mount_rc=$?
|
88
|
attempts=0
|
89
|
while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
|
90
|
/sbin/fsck -y /
|
91
|
/sbin/mount -a 2>/dev/null
|
92
|
mount_rc=$?
|
93
|
attempts=$((attempts+1))
|
94
|
done
|
95
|
fi
|
96
|
|
97
|
# If /conf is a directory, convert it to a symlink to /cf/conf
|
98
|
if [ -d "/conf" ]; then
|
99
|
# If item is not a symlink then rm and recreate
|
100
|
CONFPOINTSTO=`readlink /conf`
|
101
|
if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
|
102
|
/bin/rm -rf /conf
|
103
|
/bin/ln -s /cf/conf /conf
|
104
|
fi
|
105
|
fi
|
106
|
|
107
|
if [ ! "$PLATFORM" = "jail" ]; then
|
108
|
# Check to see if a compact flash mountpoint exists
|
109
|
# If it fails to mount then run a fsck -y
|
110
|
if grep -q cf /etc/fstab; then
|
111
|
/sbin/mount -w /cf 2>/dev/null
|
112
|
/sbin/mount -uw /cf 2>/dev/null
|
113
|
mount_rc=$?
|
114
|
attempts=0
|
115
|
while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
|
116
|
/sbin/umount /cf
|
117
|
/sbin/fsck -y /cf
|
118
|
/sbin/mount -w /cf 2>/dev/null
|
119
|
mount_rc=$?
|
120
|
attempts=$((attempts+1))
|
121
|
done
|
122
|
fi
|
123
|
fi
|
124
|
|
125
|
USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
|
126
|
if [ "${PLATFORM}" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
|
127
|
/etc/rc.embedded
|
128
|
fi
|
129
|
fi
|
130
|
|
131
|
/bin/rm -f /root/force_fsck
|
132
|
/bin/rm -f /root/TRIM_set
|
133
|
/bin/rm -f /root/TRIM_unset
|
134
|
|
135
|
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
|
136
|
if [ -f /etc/rc.disable_hdd_apm ]; then
|
137
|
/etc/rc.disable_hdd_apm
|
138
|
fi
|
139
|
|
140
|
#Eject CD devices on 3G modems
|
141
|
MANUFACTURER="huawei|zte"
|
142
|
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
|
143
|
if [ "$CDDEVICE" != "" ]; then
|
144
|
cdcontrol -f /dev/"$CDDEVICE" eject
|
145
|
fi
|
146
|
|
147
|
# sync pw database after mount.
|
148
|
rm -f /etc/spwd.db.tmp
|
149
|
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
|
150
|
|
151
|
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
|
152
|
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
|
153
|
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
|
154
|
|
155
|
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
|
156
|
/sbin/mdmfs -S -M -s 4m md $varrunpath
|
157
|
fi
|
158
|
|
159
|
if [ "$hideplatform" -gt "0" ]; then
|
160
|
platformbanner="" # hide the platform
|
161
|
else
|
162
|
platformbanner=" on the '${PLATFORM}' platform"
|
163
|
fi
|
164
|
|
165
|
echo
|
166
|
cat /etc/ascii-art/pfsense-logo-small.txt
|
167
|
echo
|
168
|
echo
|
169
|
echo "Welcome to ${product} ${version} ${platformbanner} ..."
|
170
|
echo
|
171
|
|
172
|
if [ ! "$PLATFORM" = "jail" ]; then
|
173
|
# Enable console output if its muted.
|
174
|
/sbin/conscontrol mute off >/dev/null
|
175
|
fi
|
176
|
|
177
|
if [ "$PLATFORM" = "cdrom" ] ; then
|
178
|
# do nothing for cdrom platform
|
179
|
elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
|
180
|
# Ensure that old-style PKG packages can be persistent across reboots
|
181
|
/bin/mkdir -p /root/var/db/pkg
|
182
|
/bin/rm -rf /var/db/pkg
|
183
|
/bin/ln -s /root/var/db/pkg/ /var/db/pkg
|
184
|
# Ensure that PBI packages can be persistent across reboots
|
185
|
/bin/mkdir -p /root/var/db/pbi
|
186
|
/bin/rm -rf /var/db/pbi
|
187
|
/bin/ln -s /root/var/db/pbi/ /var/db/pbi
|
188
|
elif [ "$PLATFORM" = "jail" ]; then
|
189
|
# do nothing for jail platform
|
190
|
else
|
191
|
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
|
192
|
/sbin/swapon -a 2>/dev/null >/dev/null
|
193
|
/etc/rc.savecore
|
194
|
|
195
|
if [ -d /root/var/db/pkg ]; then
|
196
|
# User must have just disabled RAM disks, move these back into place.
|
197
|
/bin/mkdir -p /var/db/pkg
|
198
|
/bin/mv /root/var/db/pkg /var/db/pkg
|
199
|
/bin/mkdir -p /var/db/pbi
|
200
|
/bin/mv /root/var/db/pbi /var/db/pbi
|
201
|
fi
|
202
|
fi
|
203
|
|
204
|
# Copy PBI keys
|
205
|
if ls /usr/local/share/pbi-keys/*.ssl >/dev/null 2>&1; then
|
206
|
if [ ! -d "/var/db/pbi/keys" ]; then
|
207
|
mkdir -p /var/db/pbi/keys
|
208
|
fi
|
209
|
cp -f /usr/local/share/pbi-keys/*.ssl /var/db/pbi/keys
|
210
|
fi
|
211
|
|
212
|
if [ "$PLATFORM" = "cdrom" ] ; then
|
213
|
echo -n "Mounting unionfs directories..."
|
214
|
/bin/mkdir /tmp/unionfs
|
215
|
/bin/mkdir /tmp/unionfs/usr
|
216
|
/bin/mkdir /tmp/unionfs/root
|
217
|
/bin/mkdir /tmp/unionfs/sbin
|
218
|
/bin/mkdir /tmp/unionfs/bin
|
219
|
/bin/mkdir /tmp/unionfs/boot
|
220
|
/bin/mkdir /tmp/unionfs/confdefault
|
221
|
/sbin/mount_unionfs /tmp/unionfs/usr /usr/
|
222
|
/sbin/mount_unionfs /tmp/unionfs/root /root/
|
223
|
/sbin/mount_unionfs /tmp/unionfs/bin /bin/
|
224
|
/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
|
225
|
/sbin/mount_unionfs /tmp/unionfs/boot /boot/
|
226
|
/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
|
227
|
echo "done."
|
228
|
fi
|
229
|
|
230
|
# make some directories in /var
|
231
|
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
|
232
|
/bin/rm -rf $varrunpath/*
|
233
|
if [ "$PLATFORM" != "pfSense" ]; then
|
234
|
/bin/rm /var/log/* 2>/dev/null
|
235
|
fi
|
236
|
|
237
|
# Cleanup configuration files from previous instance
|
238
|
/bin/rm -rf /var/etc/*
|
239
|
/bin/rm -rf /var/tmp/*
|
240
|
|
241
|
echo -n "Creating symlinks..."
|
242
|
# Make sure symlink is correct on nanobsd
|
243
|
if [ "$PLATFORM" = "nanobsd" ] ; then
|
244
|
/bin/rm /conf
|
245
|
/bin/ln -s /cf/conf/ /conf
|
246
|
fi
|
247
|
|
248
|
# Repair symlinks if they are broken
|
249
|
if [ -f /etc/newsyslog.conf ]; then
|
250
|
/bin/rm -f /etc/newsyslog.conf
|
251
|
fi
|
252
|
if [ ! -L /etc/syslog.conf ]; then
|
253
|
/bin/rm -rf /etc/syslog.conf
|
254
|
if [ ! -f /var/etc/syslog.conf ]; then
|
255
|
touch /var/etc/syslog.conf
|
256
|
fi
|
257
|
/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
|
258
|
fi
|
259
|
|
260
|
# Repair symlinks if they are broken
|
261
|
if [ ! -L /etc/hosts ]; then
|
262
|
/bin/rm -rf /etc/hosts
|
263
|
/bin/ln -s /var/etc/hosts /etc/hosts
|
264
|
fi
|
265
|
|
266
|
if [ ! -L /etc/resolv.conf ]; then
|
267
|
/bin/rm -rf /etc/resolv.conf
|
268
|
/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
|
269
|
fi
|
270
|
|
271
|
# Setup compatibility link for packages that
|
272
|
# have trouble overriding the PREFIX configure
|
273
|
# argument since we build our packages in a
|
274
|
# separated PREFIX area
|
275
|
# Only create if symlink does not exist.
|
276
|
if [ ! -h /tmp/tmp ]; then
|
277
|
/bin/ln -hfs / /tmp/tmp
|
278
|
fi
|
279
|
|
280
|
# Make sure our /tmp is 777 + Sticky
|
281
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
282
|
/bin/rm -rf /tmp/*
|
283
|
fi
|
284
|
/bin/chmod 1777 /tmp
|
285
|
|
286
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
287
|
# Malloc debugging check
|
288
|
if [ -L /etc/malloc.conf ]; then
|
289
|
#ln -s aj /etc/malloc.conf
|
290
|
/bin/rm /etc/malloc.conf
|
291
|
fi
|
292
|
fi
|
293
|
|
294
|
if [ ! -L /etc/dhclient.conf ]; then
|
295
|
/bin/rm -rf /etc/dhclient.conf
|
296
|
fi
|
297
|
|
298
|
if [ ! -d /var/tmp ]; then
|
299
|
/bin/mkdir -p /var/tmp
|
300
|
fi
|
301
|
|
302
|
if [ ! -d /cf/conf/backup/ ]; then
|
303
|
/bin/mkdir -p /cf/conf/backup/
|
304
|
fi
|
305
|
|
306
|
set -T
|
307
|
trap "echo 'Reboot interrupted'; exit 1" 3
|
308
|
|
309
|
# Remove old nameserver resolution files
|
310
|
/bin/rm -f /var/etc/nameserver*
|
311
|
|
312
|
# Create uploadbar tmp directory
|
313
|
/bin/mkdir -p /tmp/uploadbar
|
314
|
/bin/chmod 0777 /tmp/uploadbar
|
315
|
|
316
|
echo -n "."
|
317
|
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
|
318
|
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
|
319
|
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
|
320
|
|
321
|
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
|
322
|
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
|
323
|
DEFAULT_LOG_FILE_SIZE=511488
|
324
|
fi
|
325
|
|
326
|
for logfile in $LOG_FILES; do
|
327
|
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then
|
328
|
/usr/bin/touch /var/log/$logfile.log
|
329
|
else
|
330
|
if [ ! -f /var/log/$logfile.log ]; then
|
331
|
if [ "$ENABLEFIFOLOG" -gt "0" ]; then
|
332
|
# generate fifolog files
|
333
|
/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
|
334
|
else
|
335
|
/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
|
336
|
fi
|
337
|
fi
|
338
|
fi
|
339
|
done
|
340
|
|
341
|
# change permissions on newly created fifolog files.
|
342
|
/bin/chmod 0600 /var/log/*.log
|
343
|
|
344
|
echo -n "."
|
345
|
if [ ! "$PLATFORM" = "jail" ]; then
|
346
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
347
|
if [ "$DEVFS" = "0" ]; then
|
348
|
mount_devfs devfs /dev
|
349
|
fi
|
350
|
fi
|
351
|
|
352
|
# Create an initial utmp file
|
353
|
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
|
354
|
|
355
|
echo -n "."
|
356
|
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
|
357
|
/etc/rc.d/ldconfig start 2>/dev/null
|
358
|
|
359
|
# Make sure /etc/rc.conf doesn't exist.
|
360
|
if [ -f /etc/rc.conf ]; then
|
361
|
/bin/rm -rf /etc/rc.conf
|
362
|
fi
|
363
|
|
364
|
if [ ! "$PLATFORM" = "jail" ]; then
|
365
|
# Launching kbdmux(4)
|
366
|
if [ -f "/dev/kbdmux0" ]; then
|
367
|
echo -n "."
|
368
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
369
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
370
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
371
|
fi
|
372
|
|
373
|
# Fire up unionfs if mount points exist.
|
374
|
if [ -f /dist/uniondirs ]; then
|
375
|
echo -n "."
|
376
|
/etc/rc.d/unionfs start
|
377
|
fi
|
378
|
fi
|
379
|
|
380
|
echo "done."
|
381
|
|
382
|
# Recreate capabilities DB
|
383
|
/usr/bin/cap_mkdb /etc/login.conf
|
384
|
|
385
|
# Run the php.ini setup file and populate
|
386
|
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
|
387
|
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
|
388
|
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
|
389
|
|
390
|
# Launch external configuration loader for supported platforms
|
391
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
392
|
/usr/local/sbin/fcgicli -f /etc/ecl.php
|
393
|
fi
|
394
|
|
395
|
# Launch external configuration loader for supported platforms
|
396
|
if [ "$PLATFORM" = "pfSense" ]; then
|
397
|
/usr/local/sbin/fcgicli -f /etc/ecl.php
|
398
|
fi
|
399
|
|
400
|
if [ -f /etc/rc.custom_boot_early ]; then
|
401
|
/bin/echo -n "Launching /etc/rc.custom_boot_early...";
|
402
|
/etc/rc.custom_boot_early
|
403
|
echo "Done"
|
404
|
fi
|
405
|
|
406
|
export fcgipath=/var/run/php-fpm.socket
|
407
|
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
408
|
|
409
|
# let the PHP-based configuration subsystem set up the system now
|
410
|
echo -n "Launching the init system..."
|
411
|
/bin/rm -f /cf/conf/backup/backup.cache
|
412
|
/bin/rm -f /root/lighttpd*
|
413
|
/usr/bin/touch $varrunpath/booting
|
414
|
/etc/rc.bootup
|
415
|
|
416
|
# /etc/rc.bootup unset $g['booting'], remove file right now to be
|
417
|
# consistent
|
418
|
/bin/rm $varrunpath/booting
|
419
|
|
420
|
# If a shell was selected from recovery
|
421
|
# console then just drop to the shell now.
|
422
|
if [ -f "/tmp/donotbootup" ]; then
|
423
|
echo "Dropping to recovery shell."
|
424
|
exit 0
|
425
|
fi
|
426
|
|
427
|
echo -n "Starting CRON... "
|
428
|
cd /tmp && /usr/sbin/cron -s 2>/dev/null
|
429
|
echo "done."
|
430
|
|
431
|
# Start packages
|
432
|
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
|
433
|
|
434
|
/bin/rm -rf /usr/local/pkg/pf/CVS
|
435
|
|
436
|
# Start ping handler every 240 seconds
|
437
|
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
|
438
|
|
439
|
# Start account expire handler every hour
|
440
|
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid '/usr/local/sbin/fcgicli -f /etc/rc.expireaccounts'
|
441
|
|
442
|
# Start alias url updater every 24 hours
|
443
|
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid '/usr/local/sbin/fcgicli -f /etc/rc.update_alias_url_data'
|
444
|
|
445
|
/bin/chmod a+rw /tmp/.
|
446
|
|
447
|
# Check for GEOM mirrors
|
448
|
GMIRROR_STATUS=`/sbin/gmirror status`
|
449
|
if [ "${GMIRROR_STATUS}" != "" ]; then
|
450
|
# Using a flag file at bootup saves an expensive exec/check on each page load.
|
451
|
/usr/bin/touch /var/run/gmirror_active
|
452
|
# Setup monitoring/notifications
|
453
|
/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
|
454
|
fi
|
455
|
|
456
|
# Log product version to syslog
|
457
|
BUILDTIME=`cat /etc/version.buildtime`
|
458
|
ARCH=`uname -m`
|
459
|
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
|
460
|
|
461
|
echo "Bootup complete"
|
462
|
|
463
|
/usr/local/bin/beep.sh start 2>&1 >/dev/null
|
464
|
|
465
|
# Reset the cache. read-only requires this.
|
466
|
/bin/rm -f /tmp/config.cache
|
467
|
|
468
|
exit 0
|