Project

General

Profile

Download (8.19 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/bin/sh
2
3 e5cd29a0 Scott Ullrich
# /etc/rc - master bootup script, invokes php setup
4
# part of pfSense by Scott Ullrich
5
# Copyright (C) 2004 Scott Ullrich, All rights reserved.
6
# originally based on m0n0wall (http://neon1.net/m0n0wall)
7 5b237745 Scott Ullrich
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
# All rights reserved.
9 d8a2ce2c Scott Ullrich
10
#/bin/stty status '^T'
11
#/bin/stty susp '^-' intr '^-' quit '^-'
12
13
#trap : 2
14
#trap : 3
15 5b237745 Scott Ullrich
16 31849b90 Scott Ullrich
# Set our operating platform
17 ed74be42 Scott Ullrich
PLATFORM=`/bin/cat /etc/platform`
18 c0819d14 Jeb Campbell
19 5b237745 Scott Ullrich
HOME=/
20 ce823053 Scott Ullrich
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
21 5b237745 Scott Ullrich
export HOME PATH
22
23 d4556e07 Scott Ullrich
# Set our current version
24 ed74be42 Scott Ullrich
version=`/bin/cat /etc/version`
25 3f38f066 Scott Ullrich
26 31540677 Colin Smith
if [ "$PLATFORM" = "cdrom" ]; then
27
	/etc/rc.cdrom
28
fi
29
30 16469df3 Scott Ullrich
if [ "$PLATFORM" = "embedded" ]; then
31 c613b74f Scott Ullrich
	/etc/rc.embedded
32
fi
33
34 7a3cc4df Scott Ullrich
if [ "$PLATFORM" = "nanobsd" ]; then
35
	/etc/rc.embedded
36
fi
37
38 c1688281 Seth Mos
if [ "$PLATFORM" = "pfSense" ]; then
39 11d67a3c Scott Ullrich
	mdmfs -S -M -s 4m md /var/run
40 c1688281 Seth Mos
fi
41
42 a35dd96f Scott Ullrich
product=`/bin/cat /etc/inc/globals.inc | /usr/bin/grep product_name | /usr/bin/cut -d'"' -f4`
43 ad225303 Scott Ullrich
hideplatform=`cat /etc/inc/globals.inc | grep hideplatform | wc -l`
44 1cb58b79 Scott Ullrich
45 446ffdbd Scott Ullrich
if [ "$hideplatform" -gt "0" ]; then
46 1cb58b79 Scott Ullrich
	platformbanner="" # hide the platform
47
else
48
	platformbanner=" on the '${PLATFORM}' platform"
49
fi
50 a35dd96f Scott Ullrich
51
echo
52
cat /etc/ascii-art/pfsense-logo-small.txt
53
echo
54
echo
55 1cb58b79 Scott Ullrich
echo "Welcome to ${product} ${version}${platformbanner}..."
56 a35dd96f Scott Ullrich
echo
57
58 d5f60dba Scott Ullrich
# Enable console output if its muted.
59
/sbin/conscontrol mute off >/dev/null
60
61 16469df3 Scott Ullrich
# Mount memory file system if it exists
62 ebe6a739 Scott Ullrich
echo -n "Mounting filesystems..."
63 16469df3 Scott Ullrich
/sbin/mount -a
64
65 3311566f Scott Ullrich
# Mount /. If it fails run a fsck.
66 625dda09 Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ] ; then
67 581daddc Scott Ullrich
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
68 fac17748 Scott Ullrich
69
	# If /conf is a directory, convert it to a symlink
70
	# to /cf/conf
71
	if [ -d "/conf" ]; then
72 0a9da6b5 Scott Ullrich
		# If item is not a symlink then rm and recreate
73 fb857017 Scott Ullrich
		CONFPOINTSTO=`readlink /conf` 
74
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
75 0a9da6b5 Scott Ullrich
			rm -rf /conf
76
			ln -s /cf/conf /conf
77
		fi
78 fac17748 Scott Ullrich
	fi
79 625dda09 Scott Ullrich
fi
80 fe1936d1 Scott Ullrich
81 3311566f Scott Ullrich
# Check to see if a compact flash mountpoint exists
82 581daddc Scott Ullrich
# If it fails to mount then run a fsck -fy
83 16469df3 Scott Ullrich
if grep -q cf /etc/fstab; then
84 faaa6942 Scott Ullrich
    /sbin/mount -uw /cf || \
85 581daddc Scott Ullrich
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
86 16125d1c Scott Ullrich
fi
87
88 5621d2d5 Scott Ullrich
if [ "$PLATFORM" = "cdrom" ] ; then
89
	# do nothing for cdrom platform
90
elif [ "$PLATFORM" = "embedded" ] ; then
91 f92e9ff3 Scott Ullrich
    # do nothing for embedded platform
92 7a3cc4df Scott Ullrich
elif [ "$PLATFORM" = "nanobsd" ] ; then
93 f25dc205 Scott Ullrich
	# Ensure that packages can be persistent across reboots
94 1213235c Scott Ullrich
	/bin/mkdir -p /root/var/db/pkg
95 06823877 Scott Ullrich
	rm -rf /var/db/pkg
96 be1e1880 Scott Ullrich
	ln -s /root/var/db/pkg/ /var/db/pkg
97 c0819d14 Jeb Campbell
else
98 d8a2ce2c Scott Ullrich
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
99 7050e57c Scott Ullrich
    /sbin/swapon -a 2>/dev/null >/dev/null
100 98546a74 Scott Ullrich
fi
101 ebe6a739 Scott Ullrich
echo " done."
102 5621d2d5 Scott Ullrich
103 2e269da2 Scott Ullrich
echo -n "Creating symlinks..."
104 895ecb35 Scott Ullrich
# Make sure symlink is correct on embedded
105
if [ "$PLATFORM" = "embedded" ] ; then
106
	rm /conf
107 4e7b2b27 Scott Ullrich
	ln -s /cf/conf/ /conf
108 895ecb35 Scott Ullrich
fi
109
110 7a3cc4df Scott Ullrich
# Make sure symlink is correct on embedded
111
if [ "$PLATFORM" = "nanobsd" ] ; then
112
	rm /conf
113
	ln -s /cf/conf/ /conf
114
fi
115
116 6bab150e Scott Ullrich
# Repair symlinks if they are broken
117
if [ ! -L /etc/syslog.conf ]; then
118
	rm -rf /etc/syslog.conf
119
	ln -s /var/etc/syslog.conf /etc/syslog.conf
120
fi
121
122 f1cc2287 Scott Ullrich
# Repair symlinks if they are broken
123
if [ ! -L /etc/hosts ]; then
124
	rm -rf /etc/hosts
125 4e7b2b27 Scott Ullrich
	ln -s /var/etc/hosts /etc/hosts
126 c8fcdb2f Scott Ullrich
fi
127 095d04db Scott Ullrich
128 f1cc2287 Scott Ullrich
if [ ! -L /etc/resolv.conf ]; then
129
    rm -rf /etc/resolv.conf
130 4e7b2b27 Scott Ullrich
    ln -s /var/etc/resolv.conf /etc/resolv.conf
131 f1cc2287 Scott Ullrich
fi
132 095d04db Scott Ullrich
133 652f9fa1 Scott Ullrich
# Setup compatibility link for packages that
134
# have trouble overriding the PREFIX configure
135
# argument since we build our packages in a
136
# seperated PREFIX area
137 6a19fc38 Chris Buechler
# Only create if symlink does not exist. 
138
if [ ! -h /tmp/tmp ]; then
139
    ln -hfs / /tmp/tmp
140
fi
141 652f9fa1 Scott Ullrich
142 27173ead Scott Ullrich
# Make sure our /tmp is 777 + Sticky
143
chmod 1777 /tmp
144
145 cecdf31c Scott Ullrich
# Malloc debugging check
146
if [ ! -L /etc/malloc.conf ]; then
147
    ln -s aj /etc/malloc.conf
148
fi
149
150 6484bb83 Scott Ullrich
if [ ! -L /etc/dhclient.conf ]; then
151
    rm -rf /etc/dhclient.conf
152
fi
153 c8fcdb2f Scott Ullrich
154 bfe6d078 Scott Ullrich
if [ ! -L /etc/sasyncd.conf ]; then
155 b8c835d2 Scott Ullrich
    mkdir -p /var/etc/
156 bfe6d078 Scott Ullrich
    touch /var/etc/sasyncd.conf
157
    rm -rf /etc/sasyncd.conf
158
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
159 84f68d65 Scott Ullrich
    chown root:wheel /var/etc/sasyncd.conf
160 bfe6d078 Scott Ullrich
    chmod 0600 /var/etc/sasyncd.conf
161
fi
162
163 4aa70cd8 Scott Ullrich
[ ! -d /var/tmp ] || mkdir -p /var/tmp 2>/dev/null
164
165 69588d92 Scott Ullrich
[ ! -d /cf/conf/backup/ ] || mkdir -p /cf/conf/backup/ 2>/dev/null
166 d42c2e20 Scott Ullrich
167 09c2529d Scott Ullrich
[ ! -f /var/db/ez-ipupdate.cache ] || touch /var/db/ez-ipupdate.cache 2>/dev/null
168
169 5b237745 Scott Ullrich
set -T
170
trap "echo 'Reboot interrupted'; exit 1" 3
171
172 61f1e2ec Scott Ullrich
# Remove old nameserver resolution files
173
rm -f /var/etc/nameserver*
174
175 f3677fc5 Scott Ullrich
# Create uploadbar tmp directory
176 e15f2001 Scott Ullrich
mkdir -p /tmp/uploadbar
177 f3677fc5 Scott Ullrich
chmod 777 /tmp/uploadbar
178
179 5b237745 Scott Ullrich
# make some directories in /var
180 102d8912 Scott Ullrich
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
181 ab230731 Scott Ullrich
rm /var/log/* 2>/dev/null
182 9cb8e6f0 Scott Ullrich
rm -rf /var/run/*
183 5b237745 Scott Ullrich
184 2e269da2 Scott Ullrich
echo -n "."
185 5b237745 Scott Ullrich
# generate circular logfiles
186 a7fcb832 Scott Ullrich
if [ ! "$PLATFORM" = "cdrom" ]; then
187 1d05769d Scott Ullrich
	clog -i -s 512144 /var/log/system.log
188 d42d2184 Scott Ullrich
	clog -i -s 512144 /var/log/filter.log
189 1d05769d Scott Ullrich
	clog -i -s 65535 /var/log/dhcpd.log
190
	clog -i -s 65535 /var/log/vpn.log
191
	clog -i -s 65535 /var/log/openvpn.log
192
	clog -i -s 65535 /var/log/portalauth.log
193
	clog -i -s 65535 /var/log/ipsec.log
194
	clog -i -s 65535 /var/log/slbd.log
195
	clog -i -s 65535 /var/log/lighttpd.log
196 18330d38 Scott Ullrich
	clog -i -s 65535 /var/log/ntpd.log
197 13c24013 Scott Ullrich
else
198
    clog -i -s 65535 /var/log/system.log
199
    clog -i -s 65535 /var/log/filter.log
200
    clog -i -s 65535 /var/log/dhcpd.log
201
    clog -i -s 65535 /var/log/vpn.log
202
	clog -i -s 65535 /var/log/openvpn.log
203
    clog -i -s 65535 /var/log/portalauth.log
204
    clog -i -s 65535 /var/log/ipsec.log
205
    clog -i -s 65535 /var/log/slbd.log
206 18330d38 Scott Ullrich
	clog -i -s 65535 /var/log/ntpd.log
207 a7fcb832 Scott Ullrich
fi
208 8d418ca9 Scott Ullrich
209
# change permissions on newly created clog files.
210 95a52053 Bill Marquette
chmod 0600 /var/log/system.log /var/log/filter.log /var/log/dhcpd.log /var/log/vpn.log /var/log/portalauth.log /var/log/slbd.log
211 5b237745 Scott Ullrich
212 2e269da2 Scott Ullrich
echo -n "."
213 f93c5384 Scott Ullrich
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
214
if [ "$DEVFS" = "0" ]; then
215
    mount_devfs devfs /dev
216
fi
217 5b237745 Scott Ullrich
218
# Create an initial utmp file
219
cd /var/run && cp /dev/null utmp && chmod 644 utmp
220
221 2e269da2 Scott Ullrich
echo -n "."
222 6fe4f291 Scott Ullrich
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
223 c268f10f Scott Ullrich
224 cdbc61b6 Scott Ullrich
# Make sure /etc/rc.conf doesn't exist.
225
if [ -f /etc/rc.conf ]; then
226
    rm -rf /etc/rc.conf
227
fi
228
229 b1ce7649 Scott Ullrich
# Launching kbdmux(4)
230
if [ -f "/dev/kbdmux0" ]; then
231 2e269da2 Scott Ullrich
	echo -n "."
232 b1ce7649 Scott Ullrich
	kbdcontrol -k /dev/kbdmux0 < /dev/console
233
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
234 4e7b2b27 Scott Ullrich
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
235
fi
236
237
# Fire up unionfs if mount points exist.
238
if [ -f /dist/uniondirs ]; then
239 2e269da2 Scott Ullrich
	echo -n "."
240 4e7b2b27 Scott Ullrich
	/etc/rc.d/unionfs start
241 b1ce7649 Scott Ullrich
fi
242 fa8f44ce Scott Ullrich
243 2e269da2 Scott Ullrich
echo "done."
244 deff30cd Scott Ullrich
245 ad0d7518 Scott Ullrich
# Recreate capabilities DB
246
cap_mkdb /etc/login.conf
247
248 816bfaaa Scott Ullrich
if [ "$PLATFORM" = "nanobsd" -o "$PLATFORM" = "embedded" ]; then
249
	upload_tmp_dir="/root"
250
else
251
	upload_tmp_dir="/tmp"
252
fi
253
254 6a63742f Scott Ullrich
if [ "$PLATFORM" != "cdrom" ]; then
255
# Populate a dummy php.ini to avoid
256
# the file being clobbered and the firewall
257
# not being able to boot back up.
258
cat >/usr/local/lib/php.ini <<EOF
259
output_buffering = "0"
260 1457211e Scott Ullrich
expose_php = Off
261 6a63742f Scott Ullrich
implicit_flush = true
262
magic_quotes_gpc = Off
263
max_execution_time = 99999999
264
max_input_time = 99999999
265 c339557b Scott Ullrich
register_argc_argv = On
266 6a63742f Scott Ullrich
file_uploads = On
267 816bfaaa Scott Ullrich
upload_tmp_dir = ${upload_tmp_dir}
268 6a63742f Scott Ullrich
upload_max_filesize = 90M
269
post_max_size = 90M
270
html_errors = Off
271
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
272
apc.enabled="1"
273
apc.enable_cli="1"
274
apc.shm_size="30"
275
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/
276
extension=apc.so
277 415c8d9a Scott Ullrich
extension=bcmath.so
278
extension=ctype.so
279
extension=curl.so
280
extension=mbstring.so
281
extension=overload.so
282
extension=pcntl.so
283
extension=pcre.so
284
extension=posix.so
285 6a63742f Scott Ullrich
extension=radius.so
286 415c8d9a Scott Ullrich
extension=readline.so
287
extension=session.so
288 85df6906 Scott Ullrich
extension=sysvsem.so
289 415c8d9a Scott Ullrich
extension=tokenizer.so
290
extension=xml.so
291 6a63742f Scott Ullrich
292
EOF
293
fi
294
295 136fc45a Scott Ullrich
rm -f /cf/conf/backup/backup.cache
296
297 634be286 Scott Ullrich
# Copy php.ini to alternate location after generation
298
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
299
300 b406ae66 Scott Ullrich
# let the PHP-based configuration subsystem set up the system now
301 6915d688 Scott Ullrich
echo -n "Launching the init system..."
302 b406ae66 Scott Ullrich
/etc/rc.bootup
303
304 34bb5b72 Scott Ullrich
# If a shell was selected from recovery 
305
# console then just drop to the shell now.
306
if [ -f "/tmp/donotbootup" ]; then
307
	echo "Dropping to recovery shell."
308
	exit 0
309
fi
310
311 0c5e431d Scott Ullrich
echo -n "Starting CRON... "
312 ea83ac64 Scott Ullrich
cd /tmp && /usr/sbin/cron -s 2>/dev/null
313 0c5e431d Scott Ullrich
echo "done."
314 3e08b3c1 Scott Ullrich
315 5be5825e Scott Ullrich
# Start packages
316
/etc/rc.start_packages
317 3bd1bd72 Scott Ullrich
318 58eba990 Scott Ullrich
rm -rf /usr/local/pkg/pf/CVS
319
320 d9f8db28 Scott Ullrich
# Remove stale files that have already been processed by bootup
321
# scripts
322 db54bc25 Scott Ullrich
rm -f /tmp/filter_dirty
323 6374d041 Scott Ullrich
rm -f /tmp/rc.linkup
324 e300a01e Seth Mos
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status &
325 bc086d51 Scott Ullrich
326 f2025e91 Scott Ullrich
# Start ping handler for every 240 seconds
327 9d44efe7 Seth Mos
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
328 f2025e91 Scott Ullrich
329 2d4be1c5 Scott Ullrich
/usr/local/bin/beep.sh start 2>&1 >/dev/null
330 e393a4a8 Scott Ullrich
331 c41aa4a5 Scott Ullrich
# Reset the cache.  read-only requires this.
332
rm /tmp/config.cache
333
334 27173ead Scott Ullrich
/etc/rc.conf_mount_ro
335 f83fd0f8 Scott Ullrich
336 23390125 Scott Ullrich
echo "Bootup complete"
337
338 d35cf0de Scott Ullrich
exit 0