fifteen: rename /etc/modprobe.d config files.
[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
986ba0d1 112add_to_backup usr/share/usb_modeswitch
31d488a4
AF
113
114# Backup the files
115tar cJvf /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz \
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
121if [ $ROOTSPACE -lt 70000 ]; then
122 /usr/bin/logger -p syslog.emerg -t ipfire \
123 "core-update-$core: ERROR cannot update because not enough free space on root."
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
AF
177# rename /etc/modprobe.d files
178for i in $(find /etc/modprobe.d/* | grep -v ".conf")
179 mv $i $i.conf
180done
181
31d488a4
AF
182#
183#Extract files
184tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
949d5c52 185
31d488a4
AF
186# Check diskspace on boot
187BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
949d5c52 188
31d488a4
AF
189if [ $BOOTSPACE -lt 1000 ]; then
190 case $(uname -r) in
191 *-ipfire-kirkwood )
192 # Special handling for old kirkwood images.
193 # (install only kirkwood kernel)
194 rm -rf /boot/*
195 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
196 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
197 ;;
198 * )
199 /usr/bin/logger -p syslog.emerg -t ipfire \
200 "core-update-$core: FATAL-ERROR space run out on boot. System is not bootable..."
201 /etc/init.d/apache start
202 exit 4
203 ;;
204 esac
205fi
949d5c52 206
31d488a4
AF
207#
208#Reload init to close old linker/glibc
209telinit u
949d5c52 210
31d488a4
AF
211# Regenerate ipsec configuration files.
212/srv/web/ipfire/cgi-bin/vpnmain.cgi
949d5c52
MT
213
214# Update Language cache
215perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
216
dfe0a20d
MT
217# Remove old openssl engines
218rm -rf /usr/lib/engines
219
cf4d6bb7
MT
220# Remove old initscripts
221rm -f /etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
222rm -f /etc/rc.d/init.d/networking/red.up/25-portfw
223rm -f /etc/rc.d/init.d/networking/red.up/26-xtaccess
224
8dafd717
AM
225# Remove old firewallscripts
226rm -f /usr/local/bin/setportfw
227rm -f /usr/local/bin/setdmzholes
228rm -f /usr/local/bin/setxtaccess
229rm -f /usr/local/bin/outgoingfwctrl
230
cf4d6bb7
MT
231# Remove old CGI files
232rm -f /srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
233
8ecb6450
AM
234# Generate chains for new firewall
235/sbin/iptables -N INPUTFW
236/sbin/iptables -N FORWARDFW
12f8cdd5
AM
237/sbin/iptables -N POLICYFWD
238/sbin/iptables -N POLICYIN
239/sbin/iptables -N POLICYOUT
240/sbin/iptables -t nat -N NAT_SOURCE
241/sbin/iptables -t nat -N NAT_DESTINATION
8ecb6450 242
8d0aa710 243# Convert firewall configuration
8ecb6450
AM
244/usr/sbin/convert-xtaccess
245/usr/sbin/convert-outgoingfw
246/usr/sbin/convert-portfw
247/usr/sbin/convert-dmz
8d0aa710
MT
248
249# Remove old firewall configuration files
250rm -rf /var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
251
2106b71e
AF
252# Convert inittab and fstab
253sed -i -e "s/tty1 9600$/tty1 9600 --noclear/g" /etc/inittab
254sed -i -e "s/^proc/#proc/g" /etc/fstab
255sed -i -e "s/^sysfs/#sysfs/g" /etc/fstab
256sed -i -e "s/^devpts/#devpts/g" /etc/fstab
257
258# Convert udev persistent network rules
259sed -i -e "s/SYSFS{/ATTR{/g" /etc/udev/rules.d/30-persistent-network.rules
260
31d488a4
AF
261#
262# Start services
263#
264/etc/init.d/apache start
265/etc/init.d/squid start
266/etc/init.d/snort start
267if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
268 /etc/init.d/ipsec start
269fi
270
271#
272# Rebuild qosscript if enabled
273#
274if [ -e /var/ipfire/qos/enable ]; then
275 /usr/local/bin/qosctrl stop
276 /usr/local/bin/qosctrl generate
277 /usr/local/bin/qosctrl start
278fi
279
280
281case $(uname -m) in
282 i?86 )
283 #
284 # Modify grub.conf
285 #
286 echo
287 echo Update grub configuration ...
288 ROOT=`mount | grep " / " | cut -d" " -f1`
289
290 if [ ! -z $ROOT ]; then
291 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
292 fi
293
294 if [ ! -z $ROOTUUID ]; then
295 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
296 else
297 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
298 fi
299 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
300 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
301
302 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
303 echo "grub use default console ..."
304 else
305 echo "grub use serial console ..."
306 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
307 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
308 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
309 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
310 fi
311
312 #
313 # ReInstall grub
314 #
315 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
316 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
317 ;;
318esac
319#
320# Delete old lm-sensor modullist to force search at next boot
321#
322rm -rf /etc/sysconfig/lm_sensors
323
324
325# Force (re)install pae kernel if pae is supported
326rm -rf /opt/pakfire/db/*/meta-linux-pae
327if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
328 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
329 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
330 if [ $BOOTSPACE -lt 8000 -o $ROOTSPACE -lt 70000 ]; then
331 /usr/bin/logger -p syslog.emerg -t ipfire \
332 "core-update-$core: WARNING not enough space for pae kernel."
333 else
334 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
2106b71e
AF
335 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
336 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
31d488a4
AF
337 fi
338fi
339
340# Force reinstall xen kernel if it was installed
341if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
342 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
2106b71e
AF
343 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
344 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
31d488a4
AF
345 # Add xvc0 to /etc/securetty
346 echo "xvc0" >> /etc/securetty
347fi
348
349#
350# After pakfire has ended run it again and update the lists and do upgrade
351#
352echo '#!/bin/bash' > /tmp/pak_update
353echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
354echo ' sleep 1' >> /tmp/pak_update
355echo 'done' >> /tmp/pak_update
356echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
357echo ' sleep 1' >> /tmp/pak_update
358echo 'done' >> /tmp/pak_update
359echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
360echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
361echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
362echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
363echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
364echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
365echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
366echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
367#
368chmod +x /tmp/pak_update
369/tmp/pak_update &
949d5c52 370
31d488a4 371sync
949d5c52 372
31d488a4
AF
373#
374#Finish
949d5c52
MT
375(
376 /etc/init.d/fireinfo start
377 sendprofile
378) >/dev/null 2>&1 &
379
31d488a4
AF
380echo
381echo Please wait until pakfire has ended...
382echo
383#Don't report the exitcode last command
949d5c52 384exit 0
31d488a4 385