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
|
# Mount memory file system if it exists
|
29
|
echo "Mounting filesystems..."
|
30
|
|
31
|
# Handle ZFS read-only case
|
32
|
if [ "$PLATFORM" = "pfSense" ]; then
|
33
|
if [ -f /usr/bin/grep ]; then
|
34
|
WHEREISROOT=`/sbin/mount | /usr/bin/grep " / " | /usr/bin/grep "tank" | /usr/bin/cut -d' ' -f1`
|
35
|
if [ "$WHEREISROOT" != "" ]; then
|
36
|
/sbin/zfs set readonly=off $WHEREISROOT
|
37
|
fi
|
38
|
fi
|
39
|
fi
|
40
|
|
41
|
if [ "$PLATFORM" = "cdrom" ]; then
|
42
|
/etc/rc.cdrom
|
43
|
fi
|
44
|
|
45
|
if [ "$PLATFORM" = "embedded" ]; then
|
46
|
/etc/rc.embedded
|
47
|
fi
|
48
|
|
49
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
50
|
/etc/rc.embedded
|
51
|
fi
|
52
|
|
53
|
if [ "$PLATFORM" = "pfSense" ]; then
|
54
|
/sbin/mdmfs -S -M -s 4m md /var/run
|
55
|
fi
|
56
|
|
57
|
# Mount /. If it fails run a fsck.
|
58
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
59
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
60
|
/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
|
61
|
else
|
62
|
/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
|
63
|
fi
|
64
|
# If /conf is a directory, convert it to a symlink to /cf/conf
|
65
|
if [ -d "/conf" ]; then
|
66
|
# If item is not a symlink then rm and recreate
|
67
|
CONFPOINTSTO=`readlink /conf`
|
68
|
if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
|
69
|
/bin/rm -rf /conf
|
70
|
/bin/ln -s /cf/conf /conf
|
71
|
fi
|
72
|
fi
|
73
|
fi
|
74
|
|
75
|
# Check to see if a compact flash mountpoint exists
|
76
|
# If it fails to mount then run a fsck -fy
|
77
|
if grep -q cf /etc/fstab; then
|
78
|
/sbin/mount -w /cf 2>/dev/null
|
79
|
/sbin/mount -uw /cf || \
|
80
|
(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
|
81
|
fi
|
82
|
|
83
|
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
|
84
|
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
|
85
|
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
|
86
|
|
87
|
if [ "$hideplatform" -gt "0" ]; then
|
88
|
platformbanner="" # hide the platform
|
89
|
else
|
90
|
platformbanner=" on the '${PLATFORM}' platform"
|
91
|
fi
|
92
|
|
93
|
echo
|
94
|
cat /etc/ascii-art/pfsense-logo-small.txt
|
95
|
echo
|
96
|
echo
|
97
|
echo "Welcome to ${product} ${version} ${platformbanner} ..."
|
98
|
echo
|
99
|
|
100
|
# Enable console output if its muted.
|
101
|
/sbin/conscontrol mute off >/dev/null
|
102
|
|
103
|
if [ "$PLATFORM" = "cdrom" ] ; then
|
104
|
# do nothing for cdrom platform
|
105
|
elif [ "$PLATFORM" = "embedded" ] ; then
|
106
|
# do nothing for embedded platform
|
107
|
elif [ "$PLATFORM" = "nanobsd" ] ; then
|
108
|
# Ensure that packages can be persistent across reboots
|
109
|
/bin/mkdir -p /root/var/db/pkg
|
110
|
/bin/rm -rf /var/db/pkg
|
111
|
/bin/ln -s /root/var/db/pkg/ /var/db/pkg
|
112
|
else
|
113
|
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
|
114
|
/sbin/swapon -a 2>/dev/null >/dev/null
|
115
|
fi
|
116
|
|
117
|
if [ "$PLATFORM" = "cdrom" ] ; then
|
118
|
/bin/mkdir /tmp/unionfs
|
119
|
/bin/mkdir /tmp/unionfs/usr
|
120
|
/bin/mkdir /tmp/unionfs/root
|
121
|
/bin/mkdir /tmp/unionfs/sbin
|
122
|
/bin/mkdir /tmp/unionfs/bin
|
123
|
/bin/mkdir /tmp/unionfs/boot
|
124
|
/bin/mkdir /tmp/unionfs/confdefault
|
125
|
echo -n "Mounting unionfs directories:"
|
126
|
echo -n " usr"
|
127
|
/sbin/mount_unionfs /tmp/unionfs/usr /usr/
|
128
|
echo -n " root"
|
129
|
/sbin/mount_unionfs /tmp/unionfs/root /root/
|
130
|
echo -n " bin"
|
131
|
/sbin/mount_unionfs /tmp/unionfs/bin /bin/
|
132
|
echo -n " sbin"
|
133
|
/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
|
134
|
echo -n " boot"
|
135
|
/sbin/mount_unionfs /tmp/unionfs/boot /boot/
|
136
|
echo -n " conf.default"
|
137
|
/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
|
138
|
echo -n " installer"
|
139
|
echo "... done."
|
140
|
fi
|
141
|
|
142
|
echo -n "Creating symlinks..."
|
143
|
# Make sure symlink is correct on embedded
|
144
|
if [ "$PLATFORM" = "embedded" ] ; then
|
145
|
/bin/rm /conf
|
146
|
/bin/ln -s /cf/conf/ /conf
|
147
|
fi
|
148
|
|
149
|
# Make sure symlink is correct on nanobsd
|
150
|
if [ "$PLATFORM" = "nanobsd" ] ; then
|
151
|
/bin/rm /conf
|
152
|
/bin/ln -s /cf/conf/ /conf
|
153
|
fi
|
154
|
|
155
|
# Repair symlinks if they are broken
|
156
|
if [ ! -L /etc/syslog.conf ]; then
|
157
|
/bin/rm -rf /etc/syslog.conf
|
158
|
/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
|
159
|
fi
|
160
|
|
161
|
# Repair symlinks if they are broken
|
162
|
if [ ! -L /etc/hosts ]; then
|
163
|
/bin/rm -rf /etc/hosts
|
164
|
/bin/ln -s /var/etc/hosts /etc/hosts
|
165
|
fi
|
166
|
|
167
|
if [ ! -L /etc/resolv.conf ]; then
|
168
|
/bin/rm -rf /etc/resolv.conf
|
169
|
/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
|
170
|
fi
|
171
|
|
172
|
# Setup compatibility link for packages that
|
173
|
# have trouble overriding the PREFIX configure
|
174
|
# argument since we build our packages in a
|
175
|
# seperated PREFIX area
|
176
|
# Only create if symlink does not exist.
|
177
|
if [ ! -h /tmp/tmp ]; then
|
178
|
/bin/ln -hfs / /tmp/tmp
|
179
|
fi
|
180
|
|
181
|
# Make sure our /tmp is 777 + Sticky
|
182
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
183
|
/bin/rm -rf /tmp/*
|
184
|
fi
|
185
|
/bin/chmod 1777 /tmp
|
186
|
|
187
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
188
|
# Malloc debugging check
|
189
|
if [ -L /etc/malloc.conf ]; then
|
190
|
#ln -s aj /etc/malloc.conf
|
191
|
/bin/rm /etc/malloc.conf
|
192
|
fi
|
193
|
fi
|
194
|
|
195
|
if [ ! -L /etc/dhclient.conf ]; then
|
196
|
/bin/rm -rf /etc/dhclient.conf
|
197
|
fi
|
198
|
|
199
|
if [ ! -L /etc/sasyncd.conf ]; then
|
200
|
/bin/mkdir -p /var/etc/
|
201
|
/usr/bin/touch /var/etc/sasyncd.conf
|
202
|
/bin/rm -rf /etc/sasyncd.conf
|
203
|
/bin/ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
|
204
|
/usr/sbin/chown root:wheel /var/etc/sasyncd.conf
|
205
|
/bin/chmod 0600 /var/etc/sasyncd.conf
|
206
|
fi
|
207
|
|
208
|
if [ ! -d /var/tmp ]; then
|
209
|
/bin/mkdir -p /var/tmp
|
210
|
fi
|
211
|
|
212
|
if [ ! -d /cf/conf/backup/ ]; then
|
213
|
/bin/mkdir -p /cf/conf/backup/
|
214
|
fi
|
215
|
|
216
|
# OpenVPN storage
|
217
|
if [ ! -d /var/etc/openvpn ]; then
|
218
|
/bin/mkdir -p /var/etc/openvpn
|
219
|
fi
|
220
|
if [ ! -d /var/etc/openvpn-csc ]; then
|
221
|
/bin/mkdir -p /var/etc/openvpn-csc
|
222
|
fi
|
223
|
|
224
|
set -T
|
225
|
trap "echo 'Reboot interrupted'; exit 1" 3
|
226
|
|
227
|
# Remove old nameserver resolution files
|
228
|
/bin/rm -f /var/etc/nameserver*
|
229
|
|
230
|
# Create uploadbar tmp directory
|
231
|
/bin/mkdir -p /tmp/uploadbar
|
232
|
/bin/chmod 0777 /tmp/uploadbar
|
233
|
|
234
|
# make some directories in /var
|
235
|
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
|
236
|
/bin/rm /var/log/* 2>/dev/null
|
237
|
/bin/rm -rf /var/run/*
|
238
|
|
239
|
echo -n "."
|
240
|
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
|
241
|
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then
|
242
|
/usr/bin/touch /var/log/system.log
|
243
|
/usr/bin/touch /var/log/filter.log
|
244
|
/usr/bin/touch /var/log/dhcpd.log
|
245
|
/usr/bin/touch /var/log/vpn.log
|
246
|
/usr/bin/touch /var/log/pptps.log
|
247
|
/usr/bin/touch /var/log/poes.log
|
248
|
/usr/bin/touch /var/log/l2tps.log
|
249
|
/usr/bin/touch /var/log/openvpn.log
|
250
|
/usr/bin/touch /var/log/portalauth.log
|
251
|
/usr/bin/touch /var/log/ipsec.log
|
252
|
/usr/bin/touch /var/log/ppp.log
|
253
|
/usr/bin/touch /var/log/relayd.log
|
254
|
/usr/bin/touch /var/log/lighttpd.log
|
255
|
/usr/bin/touch /var/log/ntpd.log
|
256
|
/usr/bin/touch /var/log/apinger.log
|
257
|
else
|
258
|
ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
|
259
|
if [ "$ENABLEFIFOLOG" -gt "0" ]; then
|
260
|
# generate fifolog files
|
261
|
/usr/sbin/fifolog_create -s 511488 /var/log/system.log
|
262
|
/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
|
263
|
/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
|
264
|
/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
|
265
|
/usr/sbin/fifolog_create -s 50688 /var/log/pptps.log
|
266
|
/usr/sbin/fifolog_create -s 50688 /var/log/poes.log
|
267
|
/usr/sbin/fifolog_create -s 50688 /var/log/l2tps.log
|
268
|
/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
|
269
|
/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
|
270
|
/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
|
271
|
/usr/sbin/fifolog_create -s 50688 /var/log/ppp.log
|
272
|
/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
|
273
|
/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
|
274
|
/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
|
275
|
/usr/sbin/fifolog_create -s 50688 /var/log/apinger.log
|
276
|
else
|
277
|
/usr/sbin/clog -i -s 512144 /var/log/system.log
|
278
|
/usr/sbin/clog -i -s 512144 /var/log/filter.log
|
279
|
/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
|
280
|
/usr/sbin/clog -i -s 65535 /var/log/vpn.log
|
281
|
/usr/sbin/clog -i -s 50688 /var/log/pptps.log
|
282
|
/usr/sbin/clog -i -s 50688 /var/log/poes.log
|
283
|
/usr/sbin/clog -i -s 50688 /var/log/l2tps.log
|
284
|
/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
|
285
|
/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
|
286
|
/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
|
287
|
/usr/sbin/clog -i -s 65535 /var/log/ppp.log
|
288
|
/usr/sbin/clog -i -s 65535 /var/log/slbd.log
|
289
|
/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
|
290
|
/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
|
291
|
/usr/sbin/clog -i -s 65535 /var/log/relayd.log
|
292
|
/usr/sbin/clog -i -s 65535 /var/log/apinger.log
|
293
|
fi
|
294
|
fi
|
295
|
# change permissions on newly created fifolog files.
|
296
|
/bin/chmod 0600 /var/log/*.log
|
297
|
|
298
|
echo -n "."
|
299
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
300
|
if [ "$DEVFS" = "0" ]; then
|
301
|
mount_devfs devfs /dev
|
302
|
fi
|
303
|
|
304
|
# Create an initial utmp file
|
305
|
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
|
306
|
|
307
|
echo -n "."
|
308
|
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
|
309
|
|
310
|
# Make sure /etc/rc.conf doesn't exist.
|
311
|
if [ -f /etc/rc.conf ]; then
|
312
|
/bin/rm -rf /etc/rc.conf
|
313
|
fi
|
314
|
|
315
|
# Launching kbdmux(4)
|
316
|
if [ -f "/dev/kbdmux0" ]; then
|
317
|
echo -n "."
|
318
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
319
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
320
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
321
|
fi
|
322
|
|
323
|
# Fire up unionfs if mount points exist.
|
324
|
if [ -f /dist/uniondirs ]; then
|
325
|
echo -n "."
|
326
|
/etc/rc.d/unionfs start
|
327
|
fi
|
328
|
|
329
|
echo "done."
|
330
|
|
331
|
# Ensure gettytab is of a sane size
|
332
|
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
|
333
|
echo ">>> Restoring /etc/gettytab due to unusal size"
|
334
|
echo ">>> Restoring /etc/gettytab due to unusal size" | /usr/bin/logger
|
335
|
/bin/cp /etc/gettytab.bak /etc/gettytab
|
336
|
fi
|
337
|
|
338
|
# Recreate capabilities DB
|
339
|
/usr/bin/cap_mkdb /etc/login.conf
|
340
|
|
341
|
# Run the php.ini setup file and populate
|
342
|
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
|
343
|
/etc/rc.php_ini_setup
|
344
|
|
345
|
# Launch external configuration loader for supported platforms
|
346
|
if [ "$PLATFORM" = "embedded" ]; then
|
347
|
/usr/local/bin/php -q /etc/ecl.php
|
348
|
fi
|
349
|
|
350
|
# Launch external configuration loader for supported platforms
|
351
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
352
|
/usr/local/bin/php -q /etc/ecl.php
|
353
|
fi
|
354
|
|
355
|
# Launch external configuration loader for supported platforms
|
356
|
if [ "$PLATFORM" = "pfSense" ]; then
|
357
|
/usr/local/bin/php -q /etc/ecl.php
|
358
|
fi
|
359
|
|
360
|
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
361
|
|
362
|
# let the PHP-based configuration subsystem set up the system now
|
363
|
echo -n "Launching the init system..."
|
364
|
/bin/rm -f /cf/conf/backup/backup.cache
|
365
|
/bin/rm -f /root/lighttpd*
|
366
|
/usr/bin/touch $varrunpath/booting
|
367
|
/etc/rc.bootup
|
368
|
|
369
|
# If a shell was selected from recovery
|
370
|
# console then just drop to the shell now.
|
371
|
if [ -f "/tmp/donotbootup" ]; then
|
372
|
echo "Dropping to recovery shell."
|
373
|
exit 0
|
374
|
fi
|
375
|
|
376
|
echo -n "Starting CRON... "
|
377
|
cd /tmp && /usr/sbin/cron -s 2>/dev/null
|
378
|
echo "done."
|
379
|
|
380
|
# Start packages
|
381
|
/etc/rc.start_packages
|
382
|
|
383
|
/bin/rm -rf /usr/local/pkg/pf/CVS
|
384
|
|
385
|
# Start ping handler every 240 seconds
|
386
|
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
|
387
|
|
388
|
# Start account expire handler every hour
|
389
|
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /etc/rc.expireaccounts
|
390
|
|
391
|
# Start alias url updater every 24 hours
|
392
|
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /etc/rc.update_alias_url_data
|
393
|
|
394
|
/bin/chmod a+rw /tmp/.
|
395
|
|
396
|
echo "Bootup complete"
|
397
|
/bin/rm $varrunpath/booting
|
398
|
|
399
|
/usr/local/bin/beep.sh start 2>&1 >/dev/null
|
400
|
|
401
|
# Reset the cache. read-only requires this.
|
402
|
/bin/rm /tmp/config.cache
|
403
|
|
404
|
/etc/rc.conf_mount_ro
|
405
|
|
406
|
exit 0
|