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
|
/bin/rm -rf /var/tmp/*
|
180
|
|
181
|
echo -n "Creating symlinks..."
|
182
|
# Make sure symlink is correct on embedded
|
183
|
if [ "$PLATFORM" = "embedded" ] ; then
|
184
|
/bin/rm /conf
|
185
|
/bin/ln -s /cf/conf/ /conf
|
186
|
fi
|
187
|
|
188
|
# Make sure symlink is correct on nanobsd
|
189
|
if [ "$PLATFORM" = "nanobsd" ] ; then
|
190
|
/bin/rm /conf
|
191
|
/bin/ln -s /cf/conf/ /conf
|
192
|
fi
|
193
|
|
194
|
# Repair symlinks if they are broken
|
195
|
if [ -f /etc/newsyslog.conf ]; then
|
196
|
/bin/rm -f /etc/newsyslog.conf
|
197
|
fi
|
198
|
if [ ! -L /etc/syslog.conf ]; then
|
199
|
/bin/rm -rf /etc/syslog.conf
|
200
|
if [ ! -f /var/etc/syslog.conf ]; then
|
201
|
touch /var/etc/syslog.conf
|
202
|
fi
|
203
|
/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
|
204
|
fi
|
205
|
|
206
|
# Repair symlinks if they are broken
|
207
|
if [ ! -L /etc/hosts ]; then
|
208
|
/bin/rm -rf /etc/hosts
|
209
|
/bin/ln -s /var/etc/hosts /etc/hosts
|
210
|
fi
|
211
|
|
212
|
if [ ! -L /etc/resolv.conf ]; then
|
213
|
/bin/rm -rf /etc/resolv.conf
|
214
|
/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
|
215
|
fi
|
216
|
|
217
|
# Setup compatibility link for packages that
|
218
|
# have trouble overriding the PREFIX configure
|
219
|
# argument since we build our packages in a
|
220
|
# seperated PREFIX area
|
221
|
# Only create if symlink does not exist.
|
222
|
if [ ! -h /tmp/tmp ]; then
|
223
|
/bin/ln -hfs / /tmp/tmp
|
224
|
fi
|
225
|
|
226
|
# Make sure our /tmp is 777 + Sticky
|
227
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
228
|
/bin/rm -rf /tmp/*
|
229
|
fi
|
230
|
/bin/chmod 1777 /tmp
|
231
|
|
232
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
233
|
# Malloc debugging check
|
234
|
if [ -L /etc/malloc.conf ]; then
|
235
|
#ln -s aj /etc/malloc.conf
|
236
|
/bin/rm /etc/malloc.conf
|
237
|
fi
|
238
|
fi
|
239
|
|
240
|
if [ ! -L /etc/dhclient.conf ]; then
|
241
|
/bin/rm -rf /etc/dhclient.conf
|
242
|
fi
|
243
|
|
244
|
if [ ! -d /var/tmp ]; then
|
245
|
/bin/mkdir -p /var/tmp
|
246
|
fi
|
247
|
|
248
|
if [ ! -d /cf/conf/backup/ ]; then
|
249
|
/bin/mkdir -p /cf/conf/backup/
|
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
|
echo -n "."
|
263
|
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
|
264
|
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
|
265
|
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
|
266
|
for logfile in $LOG_FILES; do
|
267
|
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then
|
268
|
/usr/bin/touch /var/log/$logfile.log
|
269
|
else
|
270
|
if [ ! -f /var/log/$logfile.log ]; then
|
271
|
if [ "$ENABLEFIFOLOG" -gt "0" ]; then
|
272
|
# generate fifolog files
|
273
|
/usr/sbin/fifolog_create -s 511488 /var/log/$logfile.log
|
274
|
else
|
275
|
/usr/sbin/clog -i -s 512144 /var/log/$logfile.log
|
276
|
fi
|
277
|
fi
|
278
|
fi
|
279
|
done
|
280
|
|
281
|
# change permissions on newly created fifolog files.
|
282
|
/bin/chmod 0600 /var/log/*.log
|
283
|
|
284
|
echo -n "."
|
285
|
if [ ! "$PLATFORM" = "jail" ]; then
|
286
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
287
|
if [ "$DEVFS" = "0" ]; then
|
288
|
mount_devfs devfs /dev
|
289
|
fi
|
290
|
fi
|
291
|
|
292
|
# Create an initial utmp file
|
293
|
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
|
294
|
|
295
|
echo -n "."
|
296
|
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
|
297
|
|
298
|
# Make sure /etc/rc.conf doesn't exist.
|
299
|
if [ -f /etc/rc.conf ]; then
|
300
|
/bin/rm -rf /etc/rc.conf
|
301
|
fi
|
302
|
|
303
|
if [ ! "$PLATFORM" = "jail" ]; then
|
304
|
# Launching kbdmux(4)
|
305
|
if [ -f "/dev/kbdmux0" ]; then
|
306
|
echo -n "."
|
307
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
308
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
309
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
310
|
fi
|
311
|
|
312
|
# Fire up unionfs if mount points exist.
|
313
|
if [ -f /dist/uniondirs ]; then
|
314
|
echo -n "."
|
315
|
/etc/rc.d/unionfs start
|
316
|
fi
|
317
|
fi
|
318
|
|
319
|
echo "done."
|
320
|
|
321
|
# Ensure gettytab is of a sane size
|
322
|
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
|
323
|
echo ">>> Restoring /etc/gettytab due to unusal size"
|
324
|
echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
|
325
|
/bin/cp /etc/gettytab.bak /etc/gettytab
|
326
|
fi
|
327
|
|
328
|
# Recreate capabilities DB
|
329
|
/usr/bin/cap_mkdb /etc/login.conf
|
330
|
|
331
|
# Run the php.ini setup file and populate
|
332
|
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
|
333
|
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
|
334
|
|
335
|
# Launch external configuration loader for supported platforms
|
336
|
if [ "$PLATFORM" = "embedded" ]; then
|
337
|
/usr/local/bin/php -q /etc/ecl.php
|
338
|
fi
|
339
|
|
340
|
# Launch external configuration loader for supported platforms
|
341
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
342
|
/usr/local/bin/php -q /etc/ecl.php
|
343
|
fi
|
344
|
|
345
|
# Launch external configuration loader for supported platforms
|
346
|
if [ "$PLATFORM" = "pfSense" ]; then
|
347
|
/usr/local/bin/php -q /etc/ecl.php
|
348
|
fi
|
349
|
|
350
|
if [ -f /etc/rc.custom_boot_early ]; then
|
351
|
/bin/echo -n "Launching /etc/rc.custom_boot_early...";
|
352
|
/etc/rc.custom_boot_early
|
353
|
echo "Done"
|
354
|
fi
|
355
|
|
356
|
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
357
|
|
358
|
# let the PHP-based configuration subsystem set up the system now
|
359
|
echo -n "Launching the init system..."
|
360
|
/bin/rm -f /cf/conf/backup/backup.cache
|
361
|
/bin/rm -f /root/lighttpd*
|
362
|
/usr/bin/touch $varrunpath/booting
|
363
|
/etc/rc.bootup
|
364
|
|
365
|
# If a shell was selected from recovery
|
366
|
# console then just drop to the shell now.
|
367
|
if [ -f "/tmp/donotbootup" ]; then
|
368
|
echo "Dropping to recovery shell."
|
369
|
exit 0
|
370
|
fi
|
371
|
|
372
|
echo -n "Starting CRON... "
|
373
|
cd /tmp && /usr/sbin/cron -s 2>/dev/null
|
374
|
echo "done."
|
375
|
|
376
|
# Start packages
|
377
|
/etc/rc.start_packages
|
378
|
|
379
|
/bin/rm -rf /usr/local/pkg/pf/CVS
|
380
|
|
381
|
# Start ping handler every 240 seconds
|
382
|
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
|
383
|
|
384
|
# Start account expire handler every hour
|
385
|
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /etc/rc.expireaccounts
|
386
|
|
387
|
# Start alias url updater every 24 hours
|
388
|
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /etc/rc.update_alias_url_data
|
389
|
|
390
|
/bin/chmod a+rw /tmp/.
|
391
|
|
392
|
echo "Bootup complete"
|
393
|
/bin/rm $varrunpath/booting
|
394
|
|
395
|
/usr/local/bin/beep.sh start 2>&1 >/dev/null
|
396
|
|
397
|
# Reset the cache. read-only requires this.
|
398
|
/bin/rm -f /tmp/config.cache
|
399
|
|
400
|
exit 0
|