Project

General

Profile

Download (7.27 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

    
42
echo
43
cat /etc/ascii-art/pfsense-logo-small.txt
44
echo
45
echo
46
echo "Welcome to ${product} ${version} on the '${PLATFORM}' platform..."
47
echo
48

    
49
# Enable console output if its muted.
50
/sbin/conscontrol mute off >/dev/null
51

    
52
# Mount memory file system if it exists
53
echo -n "Mounting filesystems..."
54
/sbin/mount -a
55

    
56
# Mount /. If it fails run a fsck.
57
if [ ! "$PLATFORM" = "cdrom" ] ; then
58
	/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
59

    
60
	# If /conf is a directory, convert it to a symlink
61
	# to /cf/conf
62
	if [ -d "/conf" ]; then
63
		# If item is not a symlink then rm and recreate
64
		CONFPOINTSTO=`readlink /conf` 
65
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
66
			rm -rf /conf
67
			ln -s /cf/conf /conf
68
		fi
69
	fi
70
fi
71

    
72
# Check to see if a compact flash mountpoint exists
73
# If it fails to mount then run a fsck -fy
74
if grep -q cf /etc/fstab; then
75
    /sbin/mount -uw /cf || \
76
	(/sbin/umount /cf; /sbin/fsck -fy /cf; /sbin/mount -w /cf)
77
fi
78

    
79
if [ "$PLATFORM" = "cdrom" ] ; then
80
	# do nothing for cdrom platform
81
elif [ "$PLATFORM" = "embedded" ] ; then
82
    # do nothing for embedded platform
83
else
84
    SWAPDEVICE=`cat /etc/fstab | grep swap | cut -f1`
85
    /sbin/swapon -a 2>/dev/null >/dev/null
86
fi
87
echo " done."
88

    
89
if [ "$PLATFORM" = "cdrom" ] ; then
90
	mkdir /tmp/unionfs
91
	mkdir /tmp/unionfs/usr
92
	mkdir /tmp/unionfs/root
93
	mkdir /tmp/unionfs/sbin
94
	mkdir /tmp/unionfs/bin
95
	mkdir /tmp/unionfs/boot
96
	mkdir /tmp/unionfs/confdefault
97
	echo -n "Mounting unionfs directories:"
98
	echo -n " usr"
99
	mount_unionfs /tmp/unionfs/usr /usr/
100
	echo -n " root"
101
	mount_unionfs /tmp/unionfs/root /root/
102
	echo -n " bin"
103
	mount_unionfs /tmp/unionfs/bin /bin/		
104
	echo -n " sbin"
105
	mount_unionfs /tmp/unionfs/sbin /sbin/	
106
	echo -n " boot"
107
	mount_unionfs /tmp/unionfs/boot /boot/
108
	echo -n " conf.default"
109
	mount_unionfs /tmp/unionfs/confdefault /conf.default/
110
	echo "... done."
111
fi
112

    
113
echo -n "Creating symlinks..."
114
# Make sure symlink is correct on embedded
115
if [ "$PLATFORM" = "embedded" ] ; then
116
	rm /conf
117
	ln -s /cf/conf/ /conf
118
fi
119

    
120
# Repair symlinks if they are broken
121
if [ ! -L /etc/syslog.conf ]; then
122
	rm -rf /etc/syslog.conf
123
	ln -s /var/etc/syslog.conf /etc/syslog.conf
124
fi
125

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

    
132
if [ ! -L /etc/resolv.conf ]; then
133
    rm -rf /etc/resolv.conf
134
    ln -s /var/etc/resolv.conf /etc/resolv.conf
135
fi
136

    
137
# Setup compatibility link for packages that
138
# have trouble overriding the PREFIX configure
139
# argument since we build our packages in a
140
# seperated PREFIX area
141
# Only create if symlink does not exist. 
142
if [ ! -h /tmp/tmp ]; then
143
    ln -hfs / /tmp/tmp
144
fi
145

    
146
# Make sure our /tmp is 777 + Sticky
147
chmod 1777 /tmp
148

    
149
if [ ! "$PLATFORM" = "cdrom" ] ; then
150
	# Malloc debugging check
151
	if [ -L /etc/malloc.conf ]; then
152
	    #ln -s aj /etc/malloc.conf
153
		rm /etc/malloc.conf
154
	fi
155
fi
156

    
157
if [ ! -L /etc/dhclient.conf ]; then
158
    rm -rf /etc/dhclient.conf
159
fi
160

    
161
if [ ! -L /etc/sasyncd.conf ]; then
162
    mkdir -p /var/etc/
163
    touch /var/etc/sasyncd.conf
164
    rm -rf /etc/sasyncd.conf
165
    ln -s /var/etc/sasyncd.conf /etc/sasyncd.conf
166
    chown root:wheel /var/etc/sasyncd.conf
167
    chmod 0600 /var/etc/sasyncd.conf
168
fi
169

    
170
if [ ! -d /var/tmp ]; then
171
	mkdir -p /var/tmp
172
fi
173

    
174
if [ ! -d /cf/conf/backup/ ]; then
175
	mkdir -p /cf/conf/backup/ 
176
fi
177

    
178
if [ ! -f /var/db/ez-ipupdate.cache ]; then
179
	touch /var/db/ez-ipupdate.cache
180
fi
181

    
182
# OpenVPN storage
183
if [ ! -d /var/etc/openvpn ]; then
184
	mkdir -p /var/etc/openvpn
185
fi
186
if [ ! -d /var/etc/openvpn-csc ]; then
187
	mkdir -p /var/etc/openvpn-csc
188
fi
189

    
190
set -T
191
trap "echo 'Reboot interrupted'; exit 1" 3
192

    
193
# Remove old nameserver resolution files
194
rm -f /var/etc/nameserver*
195

    
196
# Create uploadbar tmp directory
197
mkdir -p /tmp/uploadbar
198
chmod 0777 /tmp/uploadbar
199

    
200
# make some directories in /var
201
mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
202
rm /var/log/* 2>/dev/null
203
rm -rf /var/run/*
204

    
205
echo -n "."
206
DISABLESYSLOGCLOG=`cat /cf/conf/config.xml | grep disablesyslogclog | wc -l | awk '{ print $1 }'`
207
if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
208
	touch /var/log/system.log
209
	touch /var/log/filter.log
210
	touch /var/log/dhcpd.log
211
	touch /var/log/vpn.log
212
	touch /var/log/openvpn.log
213
	touch /var/log/portalauth.log
214
	touch /var/log/ipsec.log
215
	touch /var/log/relayd.log
216
	touch /var/log/lighttpd.log
217
	touch /var/log/ntpd.log
218
else 
219
	# generate circular logfiles
220
	clog -i -s 512144 /var/log/system.log
221
	clog -i -s 512144 /var/log/filter.log
222
	clog -i -s 65535 /var/log/dhcpd.log
223
	clog -i -s 65535 /var/log/vpn.log
224
	clog -i -s 65535 /var/log/openvpn.log
225
	clog -i -s 65535 /var/log/portalauth.log
226
	clog -i -s 65535 /var/log/ipsec.log
227
	clog -i -s 65535 /var/log/relayd.log
228
	clog -i -s 65535 /var/log/lighttpd.log
229
	clog -i -s 65535 /var/log/ntpd.log
230
fi 
231
# change permissions on newly created clog files.
232
chmod 0600 /var/log/system.log /var/log/filter.log /var/log/dhcpd.log /var/log/vpn.log /var/log/portalauth.log /var/log/relayd.log	
233

    
234
echo -n "."
235
DEVFS=`mount | grep devfs | wc -l | cut -d" " -f8`
236
if [ "$DEVFS" = "0" ]; then
237
    mount_devfs devfs /dev
238
fi
239

    
240
# Create an initial utmp file
241
cd /var/run && cp /dev/null utmp && chmod 644 utmp
242

    
243
echo -n "."
244
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
245

    
246
# Make sure /etc/rc.conf doesn't exist.
247
if [ -f /etc/rc.conf ]; then
248
    rm -rf /etc/rc.conf
249
fi
250

    
251
# Launching kbdmux(4)
252
if [ -f "/dev/kbdmux0" ]; then
253
	echo -n "."
254
	kbdcontrol -k /dev/kbdmux0 < /dev/console
255
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
256
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
257
fi
258

    
259
# Fire up unionfs if mount points exist.
260
if [ -f /dist/uniondirs ]; then
261
	echo -n "."
262
	/etc/rc.d/unionfs start
263
fi
264

    
265
echo "done."
266

    
267
# Recreate capabilities DB
268
cap_mkdb /etc/login.conf
269

    
270
# Run the php.ini setup file and populate
271
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
272
. /etc/rc.php_ini_setup
273

    
274
# let the PHP-based configuration subsystem set up the system now
275
echo -n "Launching PHP init system..."
276
rm -f /cf/conf/backup/backup.cache
277
rm -f /root/lighttpd*
278
/etc/rc.bootup
279

    
280
echo -n "Starting CRON... "
281
cd /tmp && /usr/sbin/cron -s 2>/dev/null
282
echo "done."
283

    
284
# Start packages
285
/etc/rc.start_packages
286

    
287
rm -rf /usr/local/pkg/pf/CVS
288

    
289
/usr/local/bin/php -f /etc/rc.conf_mount_ro
290

    
291
# Remove stale files that have already been processed by bootup
292
# scripts
293
rm -f /tmp/filter_dirty
294
rm -f /tmp/rc.linkup
295
nohup /usr/bin/nice -n20 /usr/local/sbin/check_reload_status 2>/dev/null &
296

    
297
# Start ping handler for every 240 seconds
298
minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
299

    
300
chmod a+rw /tmp/.
301

    
302
echo "Bootup complete"
303

    
304
/usr/local/bin/beep.sh start 2>&1 >/dev/null
305

    
306
exit 0
(30-30/84)