Project

General

Profile

Download (8.47 KB) Statistics
| Branch: | Tag: | Revision:
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
if [ "$PLATFORM" = "cdrom" ]; then
29
	/etc/rc.cdrom
30
fi
31

    
32
if [ "$PLATFORM" = "embedded" ]; then
33
	/etc/rc.embedded
34
fi
35

    
36
if [ "$PLATFORM" = "pfSense" ]; then
37
	mdmfs -S -M -s 4m md /var/run
38
fi
39

    
40
product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4`
41
hideplatform=`cat /etc/inc/globals.inc | grep hideplatform | wc -l`
42

    
43
if [ "$hideplatform" -gt "0" ]; then
44
	platformbanner="" # hide the platform
45
else
46
	platformbanner=" on the '${PLATFORM}' platform"
47
fi
48

    
49
echo
50
cat /etc/ascii-art/pfsense-logo-small.txt
51
echo
52
echo
53
echo "Welcome to ${product} ${version} ${platformbanner} ..."
54
echo
55

    
56
# Enable console output if its muted.
57
/sbin/conscontrol mute off >/dev/null
58

    
59
# Mount memory file system if it exists
60
echo -n "Mounting filesystems..."
61
/sbin/mount -a
62

    
63
# Mount /. If it fails run a fsck.
64
if [ ! "$PLATFORM" = "cdrom" ] ; then
65
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
66

    
67
	# If /conf is a directory, convert it to a symlink
68
	# 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
			rm -rf /conf
74
			ln -s /cf/conf /conf
75
		fi
76
	fi
77
fi
78

    
79
# Check to see if a compact flash mountpoint exists
80
# If it fails to mount then run a fsck -fy
81
if grep -q cf /etc/fstab; then
82
    /sbin/mount -uw /cf || \
83
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
84
fi
85

    
86
if [ "$PLATFORM" = "cdrom" ] ; then
87
	# do nothing for cdrom platform
88
elif [ "$PLATFORM" = "embedded" ] ; then
89
    # do nothing for embedded platform
90
else
91
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
92
    /sbin/swapon -a 2>/dev/null >/dev/null
93
fi
94
echo " done."
95

    
96
if [ "$PLATFORM" = "cdrom" ] ; then
97
	mkdir /tmp/unionfs
98
	mkdir /tmp/unionfs/usr
99
	mkdir /tmp/unionfs/root
100
	mkdir /tmp/unionfs/sbin
101
	mkdir /tmp/unionfs/bin
102
	mkdir /tmp/unionfs/boot
103
	mkdir /tmp/unionfs/confdefault
104
	echo -n "Mounting unionfs directories:"
105
	echo -n " usr"
106
	mount_unionfs /tmp/unionfs/usr /usr/
107
	echo -n " root"
108
	mount_unionfs /tmp/unionfs/root /root/
109
	echo -n " bin"
110
	mount_unionfs /tmp/unionfs/bin /bin/		
111
	echo -n " sbin"
112
	mount_unionfs /tmp/unionfs/sbin /sbin/	
113
	echo -n " boot"
114
	mount_unionfs /tmp/unionfs/boot /boot/
115
	echo -n " conf.default"
116
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
117
	echo "... done."
118
fi
119

    
120
echo -n "Creating symlinks..."
121
# Make sure symlink is correct on embedded
122
if [ "$PLATFORM" = "embedded" ] ; then
123
	rm /conf
124
	ln -s /cf/conf/ /conf
125
fi
126

    
127
# Repair symlinks if they are broken
128
if [ ! -L /etc/syslog.conf ]; then
129
	rm -rf /etc/syslog.conf
130
	ln -s /var/etc/syslog.conf /etc/syslog.conf
131
fi
132

    
133
# Repair symlinks if they are broken
134
if [ ! -L /etc/hosts ]; then
135
	rm -rf /etc/hosts
136
	ln -s /var/etc/hosts /etc/hosts
137
fi
138

    
139
if [ ! -L /etc/resolv.conf ]; then
140
    rm -rf /etc/resolv.conf
141
    ln -s /var/etc/resolv.conf /etc/resolv.conf
142
fi
143

    
144
# Setup compatibility link for packages that
145
# have trouble overriding the PREFIX configure
146
# argument since we build our packages in a
147
# seperated PREFIX area
148
# Only create if symlink does not exist. 
149
if [ ! -h /tmp/tmp ]; then
150
    ln -hfs / /tmp/tmp
151
fi
152

    
153
# Make sure our /tmp is 777 + Sticky
154
chmod 1777 /tmp
155

    
156
if [ ! "$PLATFORM" = "cdrom" ] ; then
157
	# Malloc debugging check
158
	if [ -L /etc/malloc.conf ]; then
159
	    #ln -s aj /etc/malloc.conf
160
		rm /etc/malloc.conf
161
	fi
162
fi
163

    
164
if [ ! -L /etc/dhclient.conf ]; then
165
    rm -rf /etc/dhclient.conf
166
fi
167

    
168
if [ ! -L /etc/sasyncd.conf ]; then
169
    mkdir -p /var/etc/
170
    touch /var/etc/sasyncd.conf
171
    rm -rf /etc/sasyncd.conf
172
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
173
    chown root:wheel /var/etc/sasyncd.conf
174
    chmod 0600 /var/etc/sasyncd.conf
175
fi
176

    
177
if [ ! -d /var/tmp ]; then
178
	mkdir -p /var/tmp
179
fi
180

    
181
if [ ! -d /cf/conf/backup/ ]; then
182
	mkdir -p /cf/conf/backup/ 
183
fi
184

    
185
if [ ! -f /var/db/ez-ipupdate.cache ]; then
186
	touch /var/db/ez-ipupdate.cache
187
fi
188

    
189
# OpenVPN storage
190
if [ ! -d /var/etc/openvpn ]; then
191
	mkdir -p /var/etc/openvpn
192
fi
193
if [ ! -d /var/etc/openvpn-csc ]; then
194
	mkdir -p /var/etc/openvpn-csc
195
fi
196

    
197
set -T
198
trap "echo 'Reboot interrupted'; exit 1" 3
199

    
200
# Remove old nameserver resolution files
201
rm -f /var/etc/nameserver*
202

    
203
# Create uploadbar tmp directory
204
mkdir -p /tmp/uploadbar
205
chmod 0777 /tmp/uploadbar
206

    
207
# make some directories in /var
208
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
209
rm /var/log/* 2>/dev/null
210
rm -rf /var/run/*
211

    
212
echo -n "."
213
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
214
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
215
	touch /var/log/system.log
216
	touch /var/log/filter.log
217
	touch /var/log/dhcpd.log
218
	touch /var/log/vpn.log
219
	touch /var/log/openvpn.log
220
	touch /var/log/portalauth.log
221
	touch /var/log/ipsec.log
222
	touch /var/log/relayd.log
223
	touch /var/log/lighttpd.log
224
	touch /var/log/ntpd.log
225
else 
226
	ENABLEFIFOLOG=`cat /cf/conf/config.xml | grep usefifolog | wc -l | awk '{ print $1 }'`
227
	if [ "$ENABLEFIFOLOG" -gt "0" ]; then
228
		# generate fifolog files
229
		/usr/sbin/fifolog_create -s 511488 /var/log/system.log
230
		/usr/sbin/fifolog_create -s 511488 /var/log/filter.log
231
		/usr/sbin/fifolog_create -s 50688 /var/log/dhcpd.log
232
		/usr/sbin/fifolog_create -s 50688 /var/log/vpn.log
233
		/usr/sbin/fifolog_create -s 50688 /var/log/openvpn.log
234
		/usr/sbin/fifolog_create -s 50688 /var/log/portalauth.log
235
		/usr/sbin/fifolog_create -s 50688 /var/log/ipsec.log
236
		/usr/sbin/fifolog_create -s 50688 /var/log/relayd.log
237
		/usr/sbin/fifolog_create -s 50688 /var/log/lighttpd.log
238
		/usr/sbin/fifolog_create -s 50688 /var/log/ntpd.log
239
	else 
240
		/usr/sbin/clog -i -s 512144 /var/log/system.log
241
		/usr/sbin/clog -i -s 512144 /var/log/filter.log
242
		/usr/sbin/clog -i -s 65535 /var/log/dhcpd.log
243
		/usr/sbin/clog -i -s 65535 /var/log/vpn.log
244
		/usr/sbin/clog -i -s 65535 /var/log/openvpn.log
245
		/usr/sbin/clog -i -s 65535 /var/log/portalauth.log
246
		/usr/sbin/clog -i -s 65535 /var/log/ipsec.log
247
		/usr/sbin/clog -i -s 65535 /var/log/slbd.log
248
		/usr/sbin/clog -i -s 65535 /var/log/lighttpd.log
249
		/usr/sbin/clog -i -s 65535 /var/log/ntpd.log
250
		/usr/sbin/clog -i -s 65535 /var/log/relayd.log		
251
	fi
252
fi 
253
# change permissions on newly created fifolog files.
254
chmod 0600 /var/log/*.log
255

    
256
echo -n "."
257
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
258
if [ "$DEVFS" = "0" ]; then
259
    mount_devfs devfs /dev
260
fi
261

    
262
# Create an initial utmp file
263
cd /var/run && cp /dev/null utmp && chmod 644 utmp
264

    
265
echo -n "."
266
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
267

    
268
# Make sure /etc/rc.conf doesn't exist.
269
if [ -f /etc/rc.conf ]; then
270
    rm -rf /etc/rc.conf
271
fi
272

    
273
# Launching kbdmux(4)
274
if [ -f "/dev/kbdmux0" ]; then
275
	echo -n "."
276
	kbdcontrol -k /dev/kbdmux0 < /dev/console
277
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
278
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
279
fi
280

    
281
# Fire up unionfs if mount points exist.
282
if [ -f /dist/uniondirs ]; then
283
	echo -n "."
284
	/etc/rc.d/unionfs start
285
fi
286

    
287
echo "done."
288

    
289
# Recreate capabilities DB
290
cap_mkdb /etc/login.conf
291

    
292
# Run the php.ini setup file and populate
293
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
294
. /etc/rc.php_ini_setup
295

    
296
# let the PHP-based configuration subsystem set up the system now
297
echo -n "Launching PHP init system..."
298
rm -f /cf/conf/backup/backup.cache
299
rm -f /root/lighttpd*
300
/etc/rc.bootup
301

    
302
# If a shell was selected from recovery 
303
# console then just drop to the shell now.
304
if [ -f "/tmp/donotbootup" ]; then
305
	echo "\nDropping to recovery shell.\n\n"
306
	exit 0
307
fi
308

    
309
echo -n "Starting CRON... "
310
cd /tmp && /usr/sbin/cron -s 2>/dev/null
311
echo "done."
312

    
313
# Start packages
314
/etc/rc.start_packages
315

    
316
rm -rf /usr/local/pkg/pf/CVS
317

    
318
/usr/local/bin/php -f /etc/rc.conf_mount_ro
319

    
320
# Remove stale files that have already been processed by bootup
321
# scripts
322
rm -f /tmp/filter_dirty
323
rm -f /tmp/rc.linkup
324
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
325

    
326
# Start ping handler every 240 seconds
327
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
328

    
329
# Start account expire handler every hour
330
minicron 3600 /var/run/expire_accounts.pid /etc/inc/rc.exipireaccounts
331

    
332
chmod a+rw /tmp/.
333

    
334
echo "Bootup complete"
335

    
336
/usr/local/bin/beep.sh start 2>&1 >/dev/null
337

    
338
exit 0
(30-30/85)