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