]> git.ipfire.org Git - ipfire-2.x.git/blame - config/rootfiles/core/87/update.sh
core86 is now core87.
[ipfire-2.x.git] / config / rootfiles / core / 87 / update.sh
CommitLineData
c172d453
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# #
20# Copyright (C) 2014 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
741fa41c
AF
27
28function find_device() {
29 local mountpoint="${1}"
30
31 local root
32 local dev mp fs flags rest
33 while read -r dev mp fs flags rest; do
34 # Skip unwanted entries
35 [ "${dev}" = "rootfs" ] && continue
36
37 if [ "${mp}" = "${mountpoint}" ] && [ -b "${dev}" ]; then
38 root="$(basename "${dev}")"
39 break
40 fi
41 done < /proc/mounts
42
43 # Get the actual device from the partition that holds /
44 while [ -n "${root}" ]; do
45 if [ -e "/sys/block/${root}" ]; then
46 echo "${root}"
47 return 0
48 fi
49
50 # Remove last character
51 root="${root::-1}"
52 done
53
54 return 1
55}
56
57
77642396 58#
c172d453
MT
59# Remove old core updates from pakfire cache to save space...
60core=86
77642396 61for (( i=1; i<=${core}; i++ ))
c172d453
MT
62do
63 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
64done
65
77642396
MT
66#
67# Do some sanity checks.
68case $(uname -r) in
69 *-ipfire-versatile )
70 /usr/bin/logger -p syslog.emerg -t ipfire \
71 "core-update-${core}: ERROR cannot update. versatile support is dropped."
72 # Report no error to pakfire. So it does not try to install it again.
73 exit 0
74 ;;
75 *-ipfire* )
76 # Ok.
77 ;;
78 * )
79 /usr/bin/logger -p syslog.emerg -t ipfire \
80 "core-update-${core}: ERROR cannot update. No IPFire Kernel."
81 exit 1
82 ;;
83esac
c172d453 84
c172d453 85
77642396
MT
86#
87#
88KVER="xxxKVERxxx"
c172d453 89
77642396
MT
90# Check diskspace on root
91ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
92
93if [ $ROOTSPACE -lt 100000 ]; then
94 /usr/bin/logger -p syslog.emerg -t ipfire \
95 "core-update-${core}: ERROR cannot update because not enough free space on root."
96 exit 2
97fi
98
99
100echo
101echo Update Kernel to $KVER ...
102#
40a8ea81 103# Remove old kernel, configs, initrd, modules, dtb's ...
77642396
MT
104#
105rm -rf /boot/System.map-*
106rm -rf /boot/config-*
107rm -rf /boot/ipfirerd-*
2b94001c 108rm -rf /boot/initramfs-*
77642396
MT
109rm -rf /boot/vmlinuz-*
110rm -rf /boot/uImage-ipfire-*
111rm -rf /boot/uInit-ipfire-*
40a8ea81 112rm -rf /boot/dtb-*-ipfire-*
77642396
MT
113rm -rf /lib/modules
114
115case "$(uname -m)" in
116 i?86)
db5b0f96
AF
117 # Backup old grub config
118 if [ -f /boot/grub/grub.conf ]; then
119 cp -vf /boot/grub/grub.conf /boot/old-grub-config
120 fi
121 if [ -f /boot/grub/menu.lst ]; then
122 cp -vf /boot/grub/menu.lst /boot/old-grub-config
123 fi
124 if [ -f /boot/grub/grub.cfg ]; then
125 cp -vf /boot/grub/grub.cfg /boot/old-grub-config
126 fi
77642396
MT
127
128 # Remove all files that belong to GRUB-legacy
129 rm -rfv /boot/grub
130 ;;
8d903f6d
AF
131 armv*)
132 # Backup uEnv.txt if exist
133 if [ -e /boot/uEnv.txt ]; then
134 cp -vf /boot/uEnv.txt /boot/uEnv.txt.org
135 fi
136
137 # work around the u-boot folder detection bug
138 mkdir -pv /boot/dtb-$KVER-ipfire-kirkwood
139 mkdir -pv /boot/dtb-$KVER-ipfire-multi
140 ;;
77642396 141esac
40a8ea81 142
77642396
MT
143#
144#Stop services
145/etc/init.d/snort stop
146/etc/init.d/squid stop
147/etc/init.d/ipsec stop
148/etc/init.d/apache stop
149
150#
151#Extract files
152tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
153
bbdd37b1
AF
154#
155#restart init because glibc was updated.
75f3abe2 156telinit u
bbdd37b1 157
77642396
MT
158# Check diskspace on boot
159BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
160
161if [ $BOOTSPACE -lt 1000 ]; then
162 case $(uname -r) in
163 *-ipfire-kirkwood )
164 # Special handling for old kirkwood images.
165 # (install only kirkwood kernel)
166 rm -rf /boot/*
8d903f6d
AF
167 # work around the u-boot folder detection bug
168 mkdir -pv /boot/dtb-$KVER-ipfire-kirkwood
77642396
MT
169 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
170 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
171 ;;
172 * )
173 /usr/bin/logger -p syslog.emerg -t ipfire \
174 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
175 /etc/init.d/apache start
176 exit 4
177 ;;
178 esac
179fi
c172d453
MT
180
181# Update Language cache
182perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
183
77642396
MT
184# Add nobody to group dialout
185usermod -a -G dialout nobody
186
187#
188# Start services
189#
190/etc/init.d/apache start
191/etc/init.d/squid start
192/etc/init.d/snort start
193if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
194 /etc/init.d/ipsec start
195fi
196
197case "$(uname -m)" in
198 i?86)
741fa41c
AF
199 case "$(find_device "/")" in
200 xvd* )
201 echo Skip bootloader update on xen.
202 ;;
203 * )
204 #
205 # Update to GRUB2
206 #
207 echo
208 echo Update grub configuration ...
209 if grep -qE "^serial" /boot/old-grub-config; then
210 sed -i /etc/default/grub \
211 -e "s|panic=10|& console=ttyS0,115200n8|g"
212 echo "GRUB_TERMINAL=\"serial\"" >> /etc/default/grub
213 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
214 fi
215
216 if ! /usr/local/bin/update-bootloader; then
217 logger -p syslog.emerg -t ipfire \
218 "Could not update the bootloader!"
219 fi
220 ;;
221 esac
77642396
MT
222esac
223
224# Force (re)install pae kernel if pae is supported
225rm -rf /opt/pakfire/db/*/meta-linux-pae
226if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
227 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
228 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
229 if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then
230 /usr/bin/logger -p syslog.emerg -t ipfire \
231 "core-update-${core}: WARNING not enough space for pae kernel."
232 else
233 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
234 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
235 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
236 echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae
237 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae
238 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae
c172d453
MT
239 fi
240fi
241
77642396
MT
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
a5b2c823 256echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub/uboot config"' >> /tmp/pak_update
77642396
MT
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#
261killall -KILL pak_update
262chmod +x /tmp/pak_update
263/tmp/pak_update &
264
c172d453
MT
265sync
266
77642396
MT
267#
268#Finish
269(
270 /etc/init.d/fireinfo start
271 sendprofile
272) >/dev/null 2>&1 &
273
274# Update Package list for addon installation
275/opt/pakfire/pakfire update -y --force
c172d453 276
77642396
MT
277echo
278echo Please wait until pakfire has ended...
279echo
c172d453
MT
280
281# Don't report the exitcode last command
282exit 0