]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/rootfiles/core/66/update.sh
Merge remote-tracking branch 'origin/next' into thirteen
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / 66 / update.sh
CommitLineData
f0a4269b
AF
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# #
20# Copyright (C) 2012 IPFire-Team <info@ipfire.org>. #
21# #
22############################################################################
23#
24. /opt/pakfire/lib/functions.sh
25/usr/local/bin/backupctrl exclude >/dev/null 2>&1
26
5e307382
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
f0a4269b
AF
36#
37# Remove old core updates from pakfire cache to save space...
b9d4e380 38#
0eb9a71a 39core=66
f0a4269b
AF
40for (( i=1; i<=$core; i++ ))
41do
42 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
43done
44
590bdf1b
AF
45#
46# Do some sanity checks.
505ceb2a
AF
47case $(uname -r) in
48 *-ipfire-versatile )
49 /usr/bin/logger -p syslog.emerg -t ipfire \
50 "core-update-$core: ERROR cannot update. versatile support is dropped."
51 # Report no error to pakfire. So it does not try to install it again.
52 exit 0
53 ;;
54 *-ipfire-xen )
55 BOOTSIZE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f2 | tail -n 1`
56 if [ $BOOTSIZE -lt 28000 ]; then
57 /usr/bin/logger -p syslog.emerg -t ipfire \
58 "core-update-$core: ERROR cannot update because not enough space on boot."
59 exit 2
60 fi
61 ;;
62 *-ipfire* )
63 # Ok.
64 ;;
65 * )
66 /usr/bin/logger -p syslog.emerg -t ipfire \
67 "core-update-$core: ERROR cannot update. No IPFire Kernel."
68 # Report no error to pakfire. So it does not try to install it again.
69 exit 0
70 ;;
71esac
72
590bdf1b 73if [ ! "$(mount | grep " reiser4 (")" == "" ]; then
b9d4e380
AF
74 /usr/bin/logger -p syslog.emerg -t ipfire \
75 "core-update-$core: ERROR cannot update because there is a reiser4 fs mounted."
5691eba9 76 exit 1
590bdf1b
AF
77fi
78
79#
f0a4269b 80#
01f54726 81KVER="3.2.34"
505ceb2a 82MOUNT=`grep "kernel" /boot/grub/grub.conf 2>/dev/null | tail -n 1 `
f0a4269b
AF
83# Nur den letzten Parameter verwenden
84echo $MOUNT > /dev/null
85MOUNT=$_
86if [ ! $MOUNT == "rw" ]; then
87 MOUNT="ro"
88fi
89
90#
91# check if we the backup file already exist
0eb9a71a 92if [ -e /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz ]; then
f0a4269b 93 echo Moving backup to backup-old ...
0eb9a71a
AF
94 mv -f /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz \
95 /var/ipfire/backup/core-upgrade$core_$KVER-old.tar.xz
f0a4269b
AF
96fi
97echo First we made a backup of all files that was inside of the
98echo update archive. This may take a while ...
99# Add some files that are not in the package to backup
5e307382
AF
100add_to_backup lib/modules
101add_to_backup etc/udev
102add_to_backup lib/udev
103add_to_backup boot
104add_to_backup etc/snort
105add_to_backup usr/lib/snort_*
106add_to_backup usr/share/zoneinfo
033d2763 107add_to_backup lib/libncurses*
275f872d
AF
108add_to_backup etc/dircolors
109add_to_backup etc/profile.d
110add_to_backup usr/share/terminfo
b9d4e380
AF
111add_to_backup etc/sysconfig/lm_sensors
112add_to_backup etc/sysconfig/rc.local
0338cdb0
MT
113add_to_backup usr/local/bin/vpn-watch
114add_to_backup usr/libexec/ipsec
f0a4269b
AF
115
116# Backup the files
117tar cJvf /var/ipfire/backup/core-upgrade_$KVER.tar.xz \
118 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
119
b9d4e380
AF
120# Check diskspace on root
121ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
122
123if [ $ROOTSPACE -lt 70000 ]; then
124 /usr/bin/logger -p syslog.emerg -t ipfire \
125 "core-update-$core: ERROR cannot update because not enough free space on root."
126 exit 2
127fi
128
f0a4269b
AF
129echo
130echo Update Kernel to $KVER ...
131#
132# Remove old kernel, configs, initrd, modules ...
133#
134rm -rf /boot/System.map-*
135rm -rf /boot/config-*
136rm -rf /boot/ipfirerd-*
137rm -rf /boot/vmlinuz-*
1d3d1bbc
AF
138rm -rf /boot/uImage-ipfire-*
139rm -rf /boot/uInit-ipfire-*
140rm -rf /lib/modules
275f872d
AF
141rm -rf /etc/dircolors
142rm -rf /etc/profile.d
143rm -rf /usr/share/terminfo
0eb9a71a 144rm -rf /bin/[
275f872d 145
f0a4269b
AF
146#
147# Remove old udev rules.
148#
5e307382
AF
149if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
150 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
151fi
f0a4269b
AF
152cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
153rm -rf /etc/udev
154rm -rf /lib/udev
155mkdir -p /etc/udev/rules.d
5e307382
AF
156if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
157 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
158fi
f0a4269b
AF
159mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
160
505ceb2a
AF
161case $(uname -m) in
162 i?86 )
163 #
164 # Backup grub.conf
165 #
166 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
167 ;;
168esac
f0a4269b
AF
169#
170#Stop services
171/etc/init.d/snort stop
172/etc/init.d/squid stop
173/etc/init.d/ipsec stop
174
033d2763 175#Remove old snort, zoneinfo and ncurses-libs(wrong path).
f0a4269b
AF
176rm -rf /etc/snort
177rm -rf /usr/lib/snort_*
5e307382 178rm -rf /usr/share/zoneinfo
033d2763 179rm -rf /lib/libncurses*
f0a4269b 180
0338cdb0
MT
181# Remove old pluto binaries.
182rm -f /usr/libexec/ipsec/{pluto,_pluto_adns,whack}
183rm -f /usr/local/bin/vpn-watch
184
f0a4269b
AF
185#
186#Extract files
5691eba9 187tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
f0a4269b 188
505ceb2a
AF
189# Check diskspace on boot
190BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
191
192if [ $BOOTSPACE -lt 1000 ]; then
193 case $(uname -r) in
194 *-ipfire-kirkwood )
195 # Special handling for old kirkwood images.
196 # (install only kirkwood kernel)
197 rm -rf /boot/*
198 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
199 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
200 ;;
201 * )
202 /usr/bin/logger -p syslog.emerg -t ipfire \
203 "core-update-$core: FATAL-ERROR space run out on boot. System is not bootable..."
204 exit 4
205 ;;
206 esac
207fi
208
44967a84
AF
209#
210#Reload init to close old linker/glibc
211telinit u
212
0338cdb0
MT
213# Regenerate ipsec configuration files.
214/srv/web/ipfire/cgi-bin/vpnmain.cgi
215
f0a4269b
AF
216#
217# Start services
218#
219/etc/init.d/squid start
220/etc/init.d/snort start
221if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
222 /etc/init.d/ipsec start
223fi
224
225#
226# Rebuild qosscript if enabled
227#
228if [ -e /var/ipfire/qos/enable ]; then
229 /usr/local/bin/qosctrl stop
230 /usr/local/bin/qosctrl generate
231 /usr/local/bin/qosctrl start
232fi
233
1f7e3a1c
MT
234# Remove preloading libsafe.
235rm -f /etc/ld.so.preload
236
505ceb2a
AF
237case $(uname -m) in
238 i?86 )
239 #
240 # Modify grub.conf
241 #
242 echo
243 echo Update grub configuration ...
244 ROOT=`mount | grep " / " | cut -d" " -f1`
245
246 if [ ! -z $ROOT ]; then
247 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
248 fi
249
250 if [ ! -z $ROOTUUID ]; then
251 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
252 else
253 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
254 fi
255 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
256 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
257
258 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
259 echo "grub use default console ..."
260 else
261 echo "grub use serial console ..."
262 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
263 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
264 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
265 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
266 fi
267
268 #
269 # ReInstall grub
270 #
271 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
272 ;;
273esac
f0a4269b
AF
274#
275# Delete old lm-sensor modullist to force search at next boot
276#
277rm -rf /etc/sysconfig/lm_sensors
278
b9d4e380
AF
279#
280# Remove powerbutton loop from rc local.
281#
282sed -i "/# power button shutdown/,+3d" /etc/sysconfig/rc.local
283
f0a4269b
AF
284#
285#Update Language cache
286perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
287
288#
289# Remove meta's of packages that are now common...
290#
291rm -rf /opt/pakfire/db/*/meta-fontconfig
292rm -rf /opt/pakfire/db/*/meta-glib
293
b9d4e380
AF
294# Force (re)install pae kernel if pae is supported
295rm -rf /opt/pakfire/db/*/meta-linux-pae
296if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
505ceb2a
AF
297 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
298 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
299 if [ $BOOTSPACE -lt 8000 -o $ROOTSPACE -lt 70000 ]; then
300 /usr/bin/logger -p syslog.emerg -t ipfire \
301 "core-update-$core: WARNING not enough space for pae kernel."
302 else
303 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
304 echo "ProgVersion: 3.2.34" >> /opt/pakfire/db/installed/meta-linux-pae
305 echo "Release: 23" >> /opt/pakfire/db/installed/meta-linux-pae
306 fi
b9d4e380
AF
307fi
308
309# Force reinstall xen kernel if it was installed
310if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
311 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
83601a06
AF
312 echo "ProgVersion: 2.6.32.60" >> /opt/pakfire/db/installed/meta-linux-xen
313 echo "Release: 23" >> /opt/pakfire/db/installed/meta-linux-xen
b9d4e380
AF
314fi
315
f0a4269b
AF
316#
317# After pakfire has ended run it again and update the lists and do upgrade
318#
319echo '#!/bin/bash' > /tmp/pak_update
320echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
321echo ' sleep 1' >> /tmp/pak_update
322echo 'done' >> /tmp/pak_update
323echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
324echo ' sleep 1' >> /tmp/pak_update
325echo 'done' >> /tmp/pak_update
326echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
327echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
328echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
329echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
b9d4e380
AF
330echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
331echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
332echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
f0a4269b
AF
333echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
334#
335chmod +x /tmp/pak_update
336/tmp/pak_update &
337
338sync
339
340#
341#Finish
342/etc/init.d/fireinfo start
343sendprofile
344
345echo
346echo Please wait until pakfire has ended...
347echo
348#Don't report the exitcode last command
349exit 0
350