]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/rootfiles/core/76/update.sh
Reload all firewall rules when /etc/init.d/firewall reload is executed.
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / 76 / update.sh
CommitLineData
949d5c52
MT
1#!/bin/bash
2############################################################################
3# #
4# This file is part of the IPFire Firewall. #
5# #
6# IPFire is free software; you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation; either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# IPFire is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with IPFire; if not, write to the Free Software #
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
19# #
2106b71e 20# Copyright (C) 2014 IPFire-Team <info@ipfire.org>. #
949d5c52
MT
21# #
22############################################################################
23#
24. /opt/pakfire/lib/functions.sh
25/usr/local/bin/backupctrl exclude >/dev/null 2>&1
26
31d488a4
AF
27function add_to_backup ()
28{
29 # Add path to ROOTFILES but remove old entries to prevent double
30 # files in the tar
31 grep -v "^$1" /opt/pakfire/tmp/ROOTFILES > /opt/pakfire/tmp/ROOTFILES.tmp
32 mv /opt/pakfire/tmp/ROOTFILES.tmp /opt/pakfire/tmp/ROOTFILES
33 echo $1 >> /opt/pakfire/tmp/ROOTFILES
34}
35
949d5c52
MT
36#
37# Remove old core updates from pakfire cache to save space...
31d488a4 38core=76
62ae8b79 39for (( i=1; i<=${core}; i++ ))
949d5c52
MT
40do
41 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
42done
43
31d488a4
AF
44#
45# Do some sanity checks.
46case $(uname -r) in
47 *-ipfire-versatile )
48 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 49 "core-update-${core}: ERROR cannot update. versatile support is dropped."
31d488a4
AF
50 # Report no error to pakfire. So it does not try to install it again.
51 exit 0
52 ;;
53 *-ipfire-xen )
54 BOOTSIZE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f2 | tail -n 1`
55 if [ $BOOTSIZE -lt 28000 ]; then
56 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 57 "core-update-${core}: ERROR cannot update because not enough space on boot."
31d488a4
AF
58 exit 2
59 fi
60 ;;
61 *-ipfire* )
62 # Ok.
63 ;;
64 * )
65 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 66 "core-update-${core}: ERROR cannot update. No IPFire Kernel."
31d488a4
AF
67 exit 1
68 ;;
69esac
70
71
72#
73#
41e2c149 74KVER="xxxKVERxxx"
31d488a4
AF
75MOUNT=`grep "kernel" /boot/grub/grub.conf 2>/dev/null | tail -n 1 `
76# Nur den letzten Parameter verwenden
77echo $MOUNT > /dev/null
78MOUNT=$_
79if [ ! $MOUNT == "rw" ]; then
80 MOUNT="ro"
81fi
82
83#
84# check if we the backup file already exist
62ae8b79 85if [ -e /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz ]; then
31d488a4 86 echo Moving backup to backup-old ...
62ae8b79
AF
87 mv -f /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
88 /var/ipfire/backup/core-upgrade${core}_${KVER}-old.tar.xz
31d488a4
AF
89fi
90echo First we made a backup of all files that was inside of the
91echo update archive. This may take a while ...
92# Add some files that are not in the package to backup
93add_to_backup lib/modules
94add_to_backup etc/udev
95add_to_backup lib/udev
96add_to_backup boot
97add_to_backup etc/sysconfig/lm_sensors
98add_to_backup etc/sysconfig/rc.local
99add_to_backup srv/web/ipfire/html/themes/ipfire
100add_to_backup usr/lib/engines
101add_to_backup etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
102add_to_backup etc/rc.d/init.d/networking/red.up/25-portfw
103add_to_backup etc/rc.d/init.d/networking/red.up/26-xtaccess
104add_to_backup usr/local/bin/setportfw
105add_to_backup usr/local/bin/setdmzholes
106add_to_backup usr/local/bin/setxtaccess
107add_to_backup usr/local/bin/outgoingfwctrl
108add_to_backup srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
109add_to_backup var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
2106b71e
AF
110add_to_backup etc/inittab
111add_to_backup etc/fstab
986ba0d1 112add_to_backup usr/share/usb_modeswitch
31d488a4
AF
113
114# Backup the files
62ae8b79 115tar cJvf /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
31d488a4
AF
116 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
117
118# Check diskspace on root
119ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
120
50da765d 121if [ $ROOTSPACE -lt 100000 ]; then
31d488a4 122 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 123 "core-update-${core}: ERROR cannot update because not enough free space on root."
31d488a4
AF
124 exit 2
125fi
126
127
128echo
129echo Update Kernel to $KVER ...
130#
131# Remove old kernel, configs, initrd, modules ...
132#
133rm -rf /boot/System.map-*
134rm -rf /boot/config-*
135rm -rf /boot/ipfirerd-*
136rm -rf /boot/vmlinuz-*
137rm -rf /boot/uImage-ipfire-*
138rm -rf /boot/uInit-ipfire-*
139rm -rf /lib/modules
140
986ba0d1
AF
141# Remove old usb_modeswitch_data
142rm -rf /usr/share/usb_modeswitch
143
31d488a4
AF
144#
145# Remove old udev rules.
146#
147if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
148 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
149fi
150cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
151rm -rf /etc/udev
152rm -rf /lib/udev
153mkdir -p /etc/udev/rules.d
154if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
155 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
156fi
157mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
158
159case $(uname -m) in
160 i?86 )
161 #
162 # Backup grub.conf
163 #
164 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
165 ;;
166esac
167#
168#Stop services
169/etc/init.d/snort stop
170/etc/init.d/squid stop
171/etc/init.d/ipsec stop
172/etc/init.d/apache stop
173
8a39dd30
MT
174# Remove the old default theme
175rm -rf /srv/web/ipfire/html/themes/ipfire
176
2d0e29fc 177# rename /etc/modprobe.d files
ad33c5fd 178for i in $(find /etc/modprobe.d/* | grep -v ".conf"); do
2d0e29fc
AF
179 mv $i $i.conf
180done
181
b8e2d108
AF
182# Move /var/run to /run.
183if [ -L "/run" ]; then
184 rm -f /run
185fi
186
187mkdir -p /run
188if mountpoint /var/run; then
189 mount --move /var/run /run
190 rm -rf /var/run
191fi
192
193ln -svf ../run /var/run
194
5bdefccb
SS
195# Creating directories for new firewall.
196mkdir -p /var/ipfire/firewall
197mkdir -p /var/ipfire/fwhosts
198
585df65a
MT
199# Remove old ntp binaries
200rm -f /usr/sbin/ntp-keygen
201rm -f /usr/sbin/ntp-wait
202rm -f /usr/sbin/ntpq
203rm -f /usr/sbin/ntptime
204rm -f /usr/sbin/ntptrace
205rm -f /usr/sbin/tickadj
206
66f6b279
MT
207# Remove old firewall helper link
208rm -f /etc/rc.d/init.d/networking/red.up/22-forwardfwctrl
209
31d488a4
AF
210#
211#Extract files
212tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
949d5c52 213
31d488a4
AF
214# Check diskspace on boot
215BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
949d5c52 216
31d488a4
AF
217if [ $BOOTSPACE -lt 1000 ]; then
218 case $(uname -r) in
219 *-ipfire-kirkwood )
220 # Special handling for old kirkwood images.
221 # (install only kirkwood kernel)
222 rm -rf /boot/*
223 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
224 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
225 ;;
226 * )
227 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 228 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
31d488a4
AF
229 /etc/init.d/apache start
230 exit 4
231 ;;
232 esac
233fi
949d5c52 234
31d488a4
AF
235#
236#Reload init to close old linker/glibc
237telinit u
949d5c52 238
31d488a4
AF
239# Regenerate ipsec configuration files.
240/srv/web/ipfire/cgi-bin/vpnmain.cgi
949d5c52
MT
241
242# Update Language cache
243perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
244
dfe0a20d
MT
245# Remove old openssl engines
246rm -rf /usr/lib/engines
247
cf4d6bb7
MT
248# Remove old initscripts
249rm -f /etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
250rm -f /etc/rc.d/init.d/networking/red.up/25-portfw
251rm -f /etc/rc.d/init.d/networking/red.up/26-xtaccess
dfa68452 252rm -f /etc/rc.d/rcsysinit.d/S90sysctl
cf4d6bb7 253
8dafd717
AM
254# Remove old firewallscripts
255rm -f /usr/local/bin/setportfw
256rm -f /usr/local/bin/setdmzholes
257rm -f /usr/local/bin/setxtaccess
258rm -f /usr/local/bin/outgoingfwctrl
259
cf4d6bb7
MT
260# Remove old CGI files
261rm -f /srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
262
8ecb6450 263# Generate chains for new firewall
917ee261
SS
264/sbin/iptables -N INPUTFW 2>/dev/null
265/sbin/iptables -N FORWARDFW 2>/dev/null
266/sbin/iptables -N POLICYFWD 2>/dev/null
267/sbin/iptables -N POLICYIN 2>/dev/null
268/sbin/iptables -N POLICYOUT 2>/dev/null
269/sbin/iptables -t nat -N NAT_SOURCE 2>/dev/null
270/sbin/iptables -t nat -N NAT_DESTINATION 2>/dev/null
8ecb6450 271
5bdefccb
SS
272# Create config files for firewall and fix permissions.
273touch /var/ipfire/firewall/config
274touch /var/ipfire/firewall/input
275touch /var/ipfire/firewall/outgoing
5bdefccb
SS
276touch /var/ipfire/firewall/settings
277touch /var/ipfire/fwhosts/customhosts
278touch /var/ipfire/fwhosts/customnetworks
279touch /var/ipfire/fwhosts/customgroups
280touch /var/ipfire/fwhosts/customservices
281touch /var/ipfire/fwhosts/customservicegrp
282
283# Fix ownership.
284chown -R nobody:nobody /var/ipfire/firewall
285chown -R nobody:nobody /var/ipfire/fwhosts
286
8d0aa710 287# Convert firewall configuration
8ecb6450
AM
288/usr/sbin/convert-xtaccess
289/usr/sbin/convert-outgoingfw
290/usr/sbin/convert-portfw
291/usr/sbin/convert-dmz
8d0aa710
MT
292
293# Remove old firewall configuration files
294rm -rf /var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
295
37013b3a
SS
296# In previously released IPFire versions the DROPOUTPUT and DROPINPUT
297# option have two identical lines in the optionsfw/settings file as long as
298# the user hasn't done any changes on the WUI.
299#
300# To prevent from any kind of side effects we are going to solve this issue now.
301
302# Fix doubble enties of DROPOUTPUT when the default settings are still in use
303# (the save button on the WUI page never has been clicked) or convert to the
304# new option name required by the firewall of IPFire 2.15.
305
306optionsfw_file="/var/ipfire/optionsfw/settings"
307
308if [ $(grep -c "DROPOUTPUT" ${optionsfw_file}) -gt 1 ] ; then
309
310 # Drop all DROPUTPUT entries.
311 sed -e "/DROPOUTPUT/d" -i ${optionsfw_file}
312
313 # Add default line for new option.
314 echo "DROPOUTGOING=on" >> ${optionsfw_file}
315else
316
317 # Convert option name to new format.
318 sed -e "s/DROPOUTPUT/DROPOUTGOING/g" -i ${optionsfw_file}
319fi
320
321# Fix doubble enties of DROPINPUT when the default settings are still in use
322# (the save button on the WUI page never has been clicked).
323if [ $(grep -c "DROPINPUT" ${optionsfw_file}) -gt 1 ] ; then
324
325 # We only can remove all entries with an defined string.
326 sed -e "/DROPINPUT/d" -i ${optionsfw_file}
327
328 # Afterwards we have to add the required string with the default
329 # value again.
330 echo "DROPINPUT=on" >> ${optionsfw_file}
331fi
332
333# Add strings and default values for new options of the firewall.
334echo "DROPFORWARD=on" >> ${optionsfw_file}
335echo "FWPOLICY=DROP" >> ${optionsfw_file}
336echo "FWPOLICY1=DROP" >> ${optionsfw_file}
337echo "FWPOLICY2=DROP" >> ${optionsfw_file}
338echo "DROPSAMBA=off" >> ${optionsfw_file}
339echo "DROPPROXY=off" >> ${optionsfw_file}
340echo "SHOWREMARK=on" >> ${optionsfw_file}
341echo "SHOWCOLORS=on" >> ${optionsfw_file}
342echo "SHOWTABLES=off" >> ${optionsfw_file}
343echo "SHOWDROPDOWN=off" >> ${optionsfw_file}
344echo "DROPWIRELESSINPUT=on" >> ${optionsfw_file}
345echo "DROPWIRELESSFORWARD=on" >> ${optionsfw_file}
346
347unset optionsfw_file
348
2106b71e
AF
349# Convert inittab and fstab
350sed -i -e "s/tty1 9600$/tty1 9600 --noclear/g" /etc/inittab
ff740a73 351sed -i -e "s/xvc0 9600$/xvc0 9600 --noclear/g" /etc/inittab
2106b71e
AF
352sed -i -e "s/^proc/#proc/g" /etc/fstab
353sed -i -e "s/^sysfs/#sysfs/g" /etc/fstab
354sed -i -e "s/^devpts/#devpts/g" /etc/fstab
0053269b 355sed -i -e "s|^none\s/var/run|#none /var/run|g" /etc/fstab
2106b71e
AF
356
357# Convert udev persistent network rules
358sed -i -e "s/SYSFS{/ATTR{/g" /etc/udev/rules.d/30-persistent-network.rules
359
2a127986
AF
360# Firstsetup was already run
361touch /var/ipfire/main/firstsetup_ok
362
31d488a4
AF
363#
364# Start services
365#
366/etc/init.d/apache start
367/etc/init.d/squid start
368/etc/init.d/snort start
369if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
370 /etc/init.d/ipsec start
371fi
372
373#
374# Rebuild qosscript if enabled
375#
376if [ -e /var/ipfire/qos/enable ]; then
377 /usr/local/bin/qosctrl stop
378 /usr/local/bin/qosctrl generate
379 /usr/local/bin/qosctrl start
380fi
381
b23dd8b7
MT
382# Update crontab
383cat <<EOF >> /var/spool/cron/root.orig
384
385# Re-read firewall rules every Sunday in March, October and November to take care of daylight saving time
38600 3 * 3 0 /usr/local/bin/timezone-transition /usr/local/bin/firewallctrl
38700 2 * 10-11 0 /usr/local/bin/timezone-transition /usr/local/bin/firewallctrl
388EOF
389fcrontab -z &>/dev/null
390
31d488a4
AF
391
392case $(uname -m) in
393 i?86 )
394 #
395 # Modify grub.conf
396 #
397 echo
398 echo Update grub configuration ...
399 ROOT=`mount | grep " / " | cut -d" " -f1`
400
401 if [ ! -z $ROOT ]; then
402 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
403 fi
404
405 if [ ! -z $ROOTUUID ]; then
406 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
407 else
408 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
409 fi
410 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
411 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
412
413 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
414 echo "grub use default console ..."
415 else
416 echo "grub use serial console ..."
417 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
418 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
419 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
420 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
421 fi
422
423 #
424 # ReInstall grub
425 #
426 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
427 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
428 ;;
429esac
430#
431# Delete old lm-sensor modullist to force search at next boot
432#
433rm -rf /etc/sysconfig/lm_sensors
434
435
436# Force (re)install pae kernel if pae is supported
437rm -rf /opt/pakfire/db/*/meta-linux-pae
438if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
439 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
440 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
bf5e1c4c 441 if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then
31d488a4 442 /usr/bin/logger -p syslog.emerg -t ipfire \
62ae8b79 443 "core-update-${core}: WARNING not enough space for pae kernel."
31d488a4
AF
444 else
445 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
2106b71e
AF
446 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
447 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
e2398186
AF
448 echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae
449 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae
450 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae
31d488a4
AF
451 fi
452fi
453
454# Force reinstall xen kernel if it was installed
455if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
456 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
2106b71e
AF
457 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
458 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
e2398186
AF
459 echo "Name: linux-xen" > /opt/pakfire/db/meta/meta-linux-xen
460 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-xen
461 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-xen
31d488a4
AF
462 # Add xvc0 to /etc/securetty
463 echo "xvc0" >> /etc/securetty
464fi
465
466#
467# After pakfire has ended run it again and update the lists and do upgrade
468#
469echo '#!/bin/bash' > /tmp/pak_update
470echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
471echo ' sleep 1' >> /tmp/pak_update
472echo 'done' >> /tmp/pak_update
473echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
474echo ' sleep 1' >> /tmp/pak_update
475echo 'done' >> /tmp/pak_update
476echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
477echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
478echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
479echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
480echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
481echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
482echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
483echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
484#
fa37e705 485killall -KILL pak_update
31d488a4
AF
486chmod +x /tmp/pak_update
487/tmp/pak_update &
949d5c52 488
31d488a4 489sync
949d5c52 490
31d488a4
AF
491#
492#Finish
949d5c52
MT
493(
494 /etc/init.d/fireinfo start
495 sendprofile
496) >/dev/null 2>&1 &
497
ba83f4b9
AF
498# Update Package list for addon installation
499/opt/pakfire/pakfire update -y --force
500
31d488a4
AF
501echo
502echo Please wait until pakfire has ended...
503echo
504#Don't report the exitcode last command
949d5c52 505exit 0
31d488a4 506