]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/rootfiles/core/fifteen/update.sh
convert-outgoingfw: Fix permissions of p2protocols configuration file.
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / fifteen / 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
949d5c52
MT
39for (( i=1; i<=$core; i++ ))
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 \
49 "core-update-$core: ERROR cannot update. versatile support is dropped."
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 \
57 "core-update-$core: ERROR cannot update because not enough space on boot."
58 exit 2
59 fi
60 ;;
61 *-ipfire* )
62 # Ok.
63 ;;
64 * )
65 /usr/bin/logger -p syslog.emerg -t ipfire \
66 "core-update-$core: ERROR cannot update. No IPFire Kernel."
67 exit 1
68 ;;
69esac
70
71
72#
73#
2505d276 74KVER="3.10.26"
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
85if [ -e /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz ]; then
86 echo Moving backup to backup-old ...
87 mv -f /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz \
88 /var/ipfire/backup/core-upgrade$core_$KVER-old.tar.xz
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
31d488a4
AF
112
113# Backup the files
114tar cJvf /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz \
115 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
116
117# Check diskspace on root
118ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
119
120if [ $ROOTSPACE -lt 70000 ]; then
121 /usr/bin/logger -p syslog.emerg -t ipfire \
122 "core-update-$core: ERROR cannot update because not enough free space on root."
123 exit 2
124fi
125
126
127echo
128echo Update Kernel to $KVER ...
129#
130# Remove old kernel, configs, initrd, modules ...
131#
132rm -rf /boot/System.map-*
133rm -rf /boot/config-*
134rm -rf /boot/ipfirerd-*
135rm -rf /boot/vmlinuz-*
136rm -rf /boot/uImage-ipfire-*
137rm -rf /boot/uInit-ipfire-*
138rm -rf /lib/modules
139
140#
141# Remove old udev rules.
142#
143if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
144 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
145fi
146cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
147rm -rf /etc/udev
148rm -rf /lib/udev
149mkdir -p /etc/udev/rules.d
150if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
151 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
152fi
153mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
154
155case $(uname -m) in
156 i?86 )
157 #
158 # Backup grub.conf
159 #
160 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
161 ;;
162esac
163#
164#Stop services
165/etc/init.d/snort stop
166/etc/init.d/squid stop
167/etc/init.d/ipsec stop
168/etc/init.d/apache stop
169
8a39dd30
MT
170# Remove the old default theme
171rm -rf /srv/web/ipfire/html/themes/ipfire
172
31d488a4
AF
173#
174#Extract files
175tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
949d5c52 176
31d488a4
AF
177# Check diskspace on boot
178BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
949d5c52 179
31d488a4
AF
180if [ $BOOTSPACE -lt 1000 ]; then
181 case $(uname -r) in
182 *-ipfire-kirkwood )
183 # Special handling for old kirkwood images.
184 # (install only kirkwood kernel)
185 rm -rf /boot/*
186 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
187 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
188 ;;
189 * )
190 /usr/bin/logger -p syslog.emerg -t ipfire \
191 "core-update-$core: FATAL-ERROR space run out on boot. System is not bootable..."
192 /etc/init.d/apache start
193 exit 4
194 ;;
195 esac
196fi
949d5c52 197
31d488a4
AF
198#
199#Reload init to close old linker/glibc
200telinit u
949d5c52 201
31d488a4
AF
202# Regenerate ipsec configuration files.
203/srv/web/ipfire/cgi-bin/vpnmain.cgi
949d5c52
MT
204
205# Update Language cache
206perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
207
dfe0a20d
MT
208# Remove old openssl engines
209rm -rf /usr/lib/engines
210
cf4d6bb7
MT
211# Remove old initscripts
212rm -f /etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
213rm -f /etc/rc.d/init.d/networking/red.up/25-portfw
214rm -f /etc/rc.d/init.d/networking/red.up/26-xtaccess
215
8dafd717
AM
216# Remove old firewallscripts
217rm -f /usr/local/bin/setportfw
218rm -f /usr/local/bin/setdmzholes
219rm -f /usr/local/bin/setxtaccess
220rm -f /usr/local/bin/outgoingfwctrl
221
cf4d6bb7
MT
222# Remove old CGI files
223rm -f /srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
224
8ecb6450
AM
225# Generate chains for new firewall
226/sbin/iptables -N INPUTFW
227/sbin/iptables -N FORWARDFW
12f8cdd5
AM
228/sbin/iptables -N POLICYFWD
229/sbin/iptables -N POLICYIN
230/sbin/iptables -N POLICYOUT
231/sbin/iptables -t nat -N NAT_SOURCE
232/sbin/iptables -t nat -N NAT_DESTINATION
8ecb6450 233
8d0aa710 234# Convert firewall configuration
8ecb6450
AM
235/usr/sbin/convert-xtaccess
236/usr/sbin/convert-outgoingfw
237/usr/sbin/convert-portfw
238/usr/sbin/convert-dmz
8d0aa710
MT
239
240# Remove old firewall configuration files
241rm -rf /var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
242
2106b71e
AF
243# Convert inittab and fstab
244sed -i -e "s/tty1 9600$/tty1 9600 --noclear/g" /etc/inittab
245sed -i -e "s/^proc/#proc/g" /etc/fstab
246sed -i -e "s/^sysfs/#sysfs/g" /etc/fstab
247sed -i -e "s/^devpts/#devpts/g" /etc/fstab
248
249# Convert udev persistent network rules
250sed -i -e "s/SYSFS{/ATTR{/g" /etc/udev/rules.d/30-persistent-network.rules
251
31d488a4
AF
252#
253# Start services
254#
255/etc/init.d/apache start
256/etc/init.d/squid start
257/etc/init.d/snort start
258if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
259 /etc/init.d/ipsec start
260fi
261
262#
263# Rebuild qosscript if enabled
264#
265if [ -e /var/ipfire/qos/enable ]; then
266 /usr/local/bin/qosctrl stop
267 /usr/local/bin/qosctrl generate
268 /usr/local/bin/qosctrl start
269fi
270
271
272case $(uname -m) in
273 i?86 )
274 #
275 # Modify grub.conf
276 #
277 echo
278 echo Update grub configuration ...
279 ROOT=`mount | grep " / " | cut -d" " -f1`
280
281 if [ ! -z $ROOT ]; then
282 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
283 fi
284
285 if [ ! -z $ROOTUUID ]; then
286 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
287 else
288 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
289 fi
290 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
291 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
292
293 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
294 echo "grub use default console ..."
295 else
296 echo "grub use serial console ..."
297 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
298 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
299 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
300 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
301 fi
302
303 #
304 # ReInstall grub
305 #
306 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
307 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
308 ;;
309esac
310#
311# Delete old lm-sensor modullist to force search at next boot
312#
313rm -rf /etc/sysconfig/lm_sensors
314
315
316# Force (re)install pae kernel if pae is supported
317rm -rf /opt/pakfire/db/*/meta-linux-pae
318if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
319 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
320 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
321 if [ $BOOTSPACE -lt 8000 -o $ROOTSPACE -lt 70000 ]; then
322 /usr/bin/logger -p syslog.emerg -t ipfire \
323 "core-update-$core: WARNING not enough space for pae kernel."
324 else
325 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
2106b71e
AF
326 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
327 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
31d488a4
AF
328 fi
329fi
330
331# Force reinstall xen kernel if it was installed
332if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
333 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
2106b71e
AF
334 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
335 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
31d488a4
AF
336 # Add xvc0 to /etc/securetty
337 echo "xvc0" >> /etc/securetty
338fi
339
340#
341# After pakfire has ended run it again and update the lists and do upgrade
342#
343echo '#!/bin/bash' > /tmp/pak_update
344echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
345echo ' sleep 1' >> /tmp/pak_update
346echo 'done' >> /tmp/pak_update
347echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
348echo ' sleep 1' >> /tmp/pak_update
349echo 'done' >> /tmp/pak_update
350echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
351echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
352echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
353echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
354echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
355echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
356echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
357echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
358#
359chmod +x /tmp/pak_update
360/tmp/pak_update &
949d5c52 361
31d488a4 362sync
949d5c52 363
31d488a4
AF
364#
365#Finish
949d5c52
MT
366(
367 /etc/init.d/fireinfo start
368 sendprofile
369) >/dev/null 2>&1 &
370
31d488a4
AF
371echo
372echo Please wait until pakfire has ended...
373echo
374#Don't report the exitcode last command
949d5c52 375exit 0
31d488a4 376