]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/rootfiles/core/66/update.sh
Merge remote-tracking branch 'trikolon/next' into next
[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# #
3e5f2ee9 20# Copyright (C) 2013 IPFire-Team <info@ipfire.org>. #
f0a4269b
AF
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#
6f704a3c 81KVER="3.2.38"
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 113add_to_backup usr/local/bin/vpn-watch
a19f3396 114add_to_backup usr/local/bin/updxsetperms
0338cdb0 115add_to_backup usr/libexec/ipsec
f0a4269b
AF
116
117# Backup the files
d14229c0 118tar cJvf /var/ipfire/backup/core-upgrade$core_$KVER.tar.xz \
f0a4269b
AF
119 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
120
b9d4e380
AF
121# Check diskspace on root
122ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
123
124if [ $ROOTSPACE -lt 70000 ]; then
125 /usr/bin/logger -p syslog.emerg -t ipfire \
126 "core-update-$core: ERROR cannot update because not enough free space on root."
127 exit 2
128fi
129
a19f3396
MT
130# Add user nobody to group squid.
131usermod -a -G squid nobody
132
f0a4269b
AF
133echo
134echo Update Kernel to $KVER ...
135#
136# Remove old kernel, configs, initrd, modules ...
137#
138rm -rf /boot/System.map-*
139rm -rf /boot/config-*
140rm -rf /boot/ipfirerd-*
141rm -rf /boot/vmlinuz-*
1d3d1bbc
AF
142rm -rf /boot/uImage-ipfire-*
143rm -rf /boot/uInit-ipfire-*
144rm -rf /lib/modules
275f872d
AF
145rm -rf /etc/dircolors
146rm -rf /etc/profile.d
147rm -rf /usr/share/terminfo
0eb9a71a 148rm -rf /bin/[
275f872d 149
f0a4269b
AF
150#
151# Remove old udev rules.
152#
5e307382
AF
153if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
154 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
155fi
f0a4269b
AF
156cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
157rm -rf /etc/udev
158rm -rf /lib/udev
159mkdir -p /etc/udev/rules.d
5e307382
AF
160if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
161 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
162fi
f0a4269b
AF
163mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
164
505ceb2a
AF
165case $(uname -m) in
166 i?86 )
167 #
168 # Backup grub.conf
169 #
170 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
171 ;;
172esac
f0a4269b
AF
173#
174#Stop services
175/etc/init.d/snort stop
176/etc/init.d/squid stop
177/etc/init.d/ipsec stop
0413e130
AF
178/etc/init.d/apache stop
179
f0a4269b 180
033d2763 181#Remove old snort, zoneinfo and ncurses-libs(wrong path).
f0a4269b
AF
182rm -rf /etc/snort
183rm -rf /usr/lib/snort_*
5e307382 184rm -rf /usr/share/zoneinfo
033d2763 185rm -rf /lib/libncurses*
f0a4269b 186
0338cdb0
MT
187# Remove old pluto binaries.
188rm -f /usr/libexec/ipsec/{pluto,_pluto_adns,whack}
189rm -f /usr/local/bin/vpn-watch
190
a19f3396
MT
191# Remove update accelerator permissions script.
192rm -f /usr/local/bin/updxsetperms
193
f0a4269b
AF
194#
195#Extract files
5691eba9 196tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
f0a4269b 197
505ceb2a
AF
198# Check diskspace on boot
199BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
200
201if [ $BOOTSPACE -lt 1000 ]; then
202 case $(uname -r) in
203 *-ipfire-kirkwood )
204 # Special handling for old kirkwood images.
205 # (install only kirkwood kernel)
206 rm -rf /boot/*
207 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
208 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
209 ;;
210 * )
211 /usr/bin/logger -p syslog.emerg -t ipfire \
212 "core-update-$core: FATAL-ERROR space run out on boot. System is not bootable..."
0413e130 213 /etc/init.d/apache start
505ceb2a
AF
214 exit 4
215 ;;
216 esac
217fi
218
44967a84
AF
219#
220#Reload init to close old linker/glibc
221telinit u
222
0338cdb0
MT
223# Regenerate ipsec configuration files.
224/srv/web/ipfire/cgi-bin/vpnmain.cgi
225
0413e130
AF
226# Convert OpenVPN RW connections.
227/usr/sbin/ovpn-ccd-convert
228
d81d4fa8
AF
229touch /var/ipfire/ovpn/ccd.conf
230touch /var/ipfire/ovpn/ccdroute
231touch /var/ipfire/ovpn/ccdroute2
232chown nobody:nobody /var/ipfire/ovpn/ccd.conf
233chown nobody:nobody /var/ipfire/ovpn/ccdroute
234chown nobody:nobody /var/ipfire/ovpn/ccdroute2
235
0413e130
AF
236# Update crontab.
237sed -i /var/spool/cron/root.orig \
238 -e 's@^.*fcron.weekly.*$@\&nice(10),bootrun 47 2 \* \* 1\ttest -x /usr/local/bin/run-parts \&\& /usr/local/bin/run-parts /etc/fcron.weekly@'
239fcrontab -z &>/dev/null
240
f0a4269b
AF
241#
242# Start services
243#
0413e130 244/etc/init.d/apache start
f0a4269b
AF
245/etc/init.d/squid start
246/etc/init.d/snort start
247if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
248 /etc/init.d/ipsec start
249fi
250
251#
252# Rebuild qosscript if enabled
253#
254if [ -e /var/ipfire/qos/enable ]; then
255 /usr/local/bin/qosctrl stop
256 /usr/local/bin/qosctrl generate
257 /usr/local/bin/qosctrl start
258fi
259
1f7e3a1c
MT
260# Remove preloading libsafe.
261rm -f /etc/ld.so.preload
262
505ceb2a
AF
263case $(uname -m) in
264 i?86 )
265 #
266 # Modify grub.conf
267 #
268 echo
269 echo Update grub configuration ...
270 ROOT=`mount | grep " / " | cut -d" " -f1`
271
272 if [ ! -z $ROOT ]; then
273 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
274 fi
275
276 if [ ! -z $ROOTUUID ]; then
277 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
278 else
279 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
280 fi
281 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
282 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
283
284 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
285 echo "grub use default console ..."
286 else
287 echo "grub use serial console ..."
288 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
289 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
290 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
291 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
292 fi
293
294 #
295 # ReInstall grub
296 #
be6cb8ea 297 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
a57072e3 298 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
505ceb2a
AF
299 ;;
300esac
f0a4269b
AF
301#
302# Delete old lm-sensor modullist to force search at next boot
303#
304rm -rf /etc/sysconfig/lm_sensors
305
b9d4e380
AF
306#
307# Remove powerbutton loop from rc local.
308#
309sed -i "/# power button shutdown/,+3d" /etc/sysconfig/rc.local
310
f0a4269b
AF
311#
312#Update Language cache
313perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
314
315#
316# Remove meta's of packages that are now common...
317#
318rm -rf /opt/pakfire/db/*/meta-fontconfig
319rm -rf /opt/pakfire/db/*/meta-glib
320
b9d4e380
AF
321# Force (re)install pae kernel if pae is supported
322rm -rf /opt/pakfire/db/*/meta-linux-pae
323if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
505ceb2a
AF
324 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
325 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
326 if [ $BOOTSPACE -lt 8000 -o $ROOTSPACE -lt 70000 ]; then
327 /usr/bin/logger -p syslog.emerg -t ipfire \
328 "core-update-$core: WARNING not enough space for pae kernel."
329 else
330 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
6f704a3c
AF
331 echo "ProgVersion: 3.2.38" >> /opt/pakfire/db/installed/meta-linux-pae
332 echo "Release: 27" >> /opt/pakfire/db/installed/meta-linux-pae
505ceb2a 333 fi
b9d4e380
AF
334fi
335
336# Force reinstall xen kernel if it was installed
337if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
338 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
83601a06 339 echo "ProgVersion: 2.6.32.60" >> /opt/pakfire/db/installed/meta-linux-xen
91b86890 340 echo "Release: 24" >> /opt/pakfire/db/installed/meta-linux-xen
1cab447f
AF
341 # Add xvc0 to /etc/securetty
342 echo "xvc0" >> /etc/securetty
b9d4e380
AF
343fi
344
f0a4269b
AF
345#
346# After pakfire has ended run it again and update the lists and do upgrade
347#
348echo '#!/bin/bash' > /tmp/pak_update
349echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
350echo ' sleep 1' >> /tmp/pak_update
351echo 'done' >> /tmp/pak_update
352echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
353echo ' sleep 1' >> /tmp/pak_update
354echo 'done' >> /tmp/pak_update
355echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
356echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
357echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
358echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
b9d4e380
AF
359echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
360echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
361echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
f0a4269b
AF
362echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
363#
364chmod +x /tmp/pak_update
365/tmp/pak_update &
366
367sync
368
369#
370#Finish
371/etc/init.d/fireinfo start
372sendprofile
373
374echo
375echo Please wait until pakfire has ended...
376echo
377#Don't report the exitcode last command
378exit 0
379