]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/rootfiles/core/70/update.sh
core70: add kernel update to script.
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / 70 / update.sh
CommitLineData
7becf946
AM
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) 2013 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
a7094642
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
7becf946
AM
36#
37# Remove old core updates from pakfire cache to save space...
38core=70
39for (( i=1; i<=$core; i++ ))
40do
41 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
42done
43
a7094642
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 # Report no error to pakfire. So it does not try to install it again.
68 exit 0
69 ;;
70esac
71
72
73#
74#
75KVER="3.2.47"
76MOUNT=`grep "kernel" /boot/grub/grub.conf 2>/dev/null | tail -n 1 `
77# Nur den letzten Parameter verwenden
78echo $MOUNT > /dev/null
79MOUNT=$_
80if [ ! $MOUNT == "rw" ]; then
81 MOUNT="ro"
82fi
83
84#
85# check if we the backup file already exist
86if [ -e /var/ipfire/backup/core-upgrade${core}_$KVER.tar.xz ]; then
87 echo Moving backup to backup-old ...
88 mv -f /var/ipfire/backup/core-upgrade${core}_$KVER.tar.xz \
89 /var/ipfire/backup/core-upgrade${core}_$KVER-old.tar.xz
90fi
91echo First we made a backup of all files that was inside of the
92echo update archive. This may take a while ...
93# Add some files that are not in the package to backup
94add_to_backup lib/modules
95add_to_backup boot
96add_to_backup etc/sysconfig/lm_sensors
97add_to_backup etc/sysconfig/rc.local
98
99# Backup the files
100tar cJvf /var/ipfire/backup/core-upgrade${core}_$KVER.tar.xz \
101 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
102
103# Check diskspace on root
104ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
105
106if [ $ROOTSPACE -lt 70000 ]; then
107 /usr/bin/logger -p syslog.emerg -t ipfire \
108 "core-update-${core}: ERROR cannot update because not enough free space on root."
109 exit 2
110fi
111
112echo
113echo Update Kernel to $KVER ...
114#
115# Remove old kernel, configs, initrd, modules ...
116#
117rm -rf /boot/System.map-*
118rm -rf /boot/config-*
119rm -rf /boot/ipfirerd-*
120rm -rf /boot/vmlinuz-*
121rm -rf /boot/uImage-ipfire-*
122rm -rf /boot/uInit-ipfire-*
123rm -rf /lib/modules
124
125case $(uname -m) in
126 i?86 )
127 #
128 # Backup grub.conf
129 #
130 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
131 ;;
132esac
133
7becf946
AM
134#
135# Remove meta's of packages that are now common...
136#
137rm -rf /opt/pakfire/db/*/meta-freefont
138
139#
140#Stop services
7becf946
AM
141
142#
143#Extract files
a7094642
AF
144tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
145
146# Check diskspace on boot
147BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
148
149if [ $BOOTSPACE -lt 1000 ]; then
150 case $(uname -r) in
151 *-ipfire-kirkwood )
152 # Special handling for old kirkwood images.
153 # (install only kirkwood kernel)
154 rm -rf /boot/*
155 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
156 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
157 ;;
158 * )
159 /usr/bin/logger -p syslog.emerg -t ipfire \
160 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
161 /etc/init.d/apache start
162 exit 4
163 ;;
164 esac
165fi
7becf946 166
7becf946
AM
167
168#
169#Start services
7becf946 170
a7094642
AF
171case $(uname -m) in
172 i?86 )
173 #
174 # Modify grub.conf
175 #
176 echo
177 echo Update grub configuration ...
178 ROOT=`mount | grep " / " | cut -d" " -f1`
179
180 if [ ! -z $ROOT ]; then
181 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
182 fi
183
184 if [ ! -z $ROOTUUID ]; then
185 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
186 else
187 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
188 fi
189 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
190 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
191
192 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
193 echo "grub use default console ..."
194 else
195 echo "grub use serial console ..."
196 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
197 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
198 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
199 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
200 fi
201
202 #
203 # ReInstall grub
204 #
205 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
206 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
207 ;;
208esac
209#
210# Delete old lm-sensor modullist to force search at next boot
211#
212rm -rf /etc/sysconfig/lm_sensors
22358c06 213
7becf946
AM
214#
215#Update Language cache
216perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
217
a7094642
AF
218# Force (re)install pae kernel if pae is supported
219rm -rf /opt/pakfire/db/*/meta-linux-pae
220if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
221 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
222 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
223 if [ $BOOTSPACE -lt 8000 -o $ROOTSPACE -lt 70000 ]; then
224 /usr/bin/logger -p syslog.emerg -t ipfire \
225 "core-update-${core}: WARNING not enough space for pae kernel."
226 else
227 rm -f /boot/grub/grub-backup-*-pae_install.conf
228 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
229 echo "ProgVersion: 3.2.46" >> /opt/pakfire/db/installed/meta-linux-pae
230 echo "Release: 29" >> /opt/pakfire/db/installed/meta-linux-pae
231 fi
232fi
7becf946 233
a7094642
AF
234# Force reinstall xen kernel if it was installed
235if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
236 rm -f /boot/grub/grub-backup-*-xen.conf
237 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
238 echo "ProgVersion: 2.6.32.60" >> /opt/pakfire/db/installed/meta-linux-xen
239 echo "Release: 26" >> /opt/pakfire/db/installed/meta-linux-xen
240fi
7becf946 241
a7094642
AF
242#
243# After pakfire has ended run it again and update the lists and do upgrade
244#
245echo '#!/bin/bash' > /tmp/pak_update
246echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
247echo ' sleep 1' >> /tmp/pak_update
248echo 'done' >> /tmp/pak_update
249echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
250echo ' sleep 1' >> /tmp/pak_update
251echo 'done' >> /tmp/pak_update
252echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
253echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
254echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
255echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
256echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
257echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
258echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
259echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
260#
261chmod +x /tmp/pak_update
262/tmp/pak_update &
263
264
265sync
7becf946 266# This update need a reboot...
a7094642 267#touch /var/run/need_reboot
7becf946
AM
268
269#
270#Finish
271/etc/init.d/fireinfo start
272sendprofile
273#Don't report the exitcode last command
274exit 0