]> git.ipfire.org Git - ipfire-2.x.git/blame - config/rootfiles/core/86/update.sh
core86: fix init restart.
[ipfire-2.x.git] / config / rootfiles / core / 86 / 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
77642396
MT
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
c172d453
MT
34}
35
77642396 36#
c172d453
MT
37# Remove old core updates from pakfire cache to save space...
38core=86
77642396 39for (( i=1; i<=${core}; i++ ))
c172d453
MT
40do
41 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
42done
43
77642396
MT
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* )
54 # Ok.
55 ;;
56 * )
57 /usr/bin/logger -p syslog.emerg -t ipfire \
58 "core-update-${core}: ERROR cannot update. No IPFire Kernel."
59 exit 1
60 ;;
61esac
c172d453 62
c172d453 63
77642396
MT
64#
65#
66KVER="xxxKVERxxx"
c172d453 67
77642396
MT
68#
69# check if we the backup file already exist
70if [ -e /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz ]; then
71 echo Moving backup to backup-old ...
72 mv -f /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
73 /var/ipfire/backup/core-upgrade${core}_${KVER}-old.tar.xz
74fi
75echo First we made a backup of all files that was inside of the
76echo update archive. This may take a while ...
77# Add some files that are not in the package to backup
78add_to_backup lib/modules
79add_to_backup boot
80
81# Backup the files
82tar cJvf /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
83 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
84
85# Check diskspace on root
86ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
87
88if [ $ROOTSPACE -lt 100000 ]; then
89 /usr/bin/logger -p syslog.emerg -t ipfire \
90 "core-update-${core}: ERROR cannot update because not enough free space on root."
91 exit 2
92fi
93
94
95echo
96echo Update Kernel to $KVER ...
97#
98# Remove old kernel, configs, initrd, modules ...
99#
100rm -rf /boot/System.map-*
101rm -rf /boot/config-*
102rm -rf /boot/ipfirerd-*
2b94001c 103rm -rf /boot/initramfs-*
77642396
MT
104rm -rf /boot/vmlinuz-*
105rm -rf /boot/uImage-ipfire-*
106rm -rf /boot/uInit-ipfire-*
107rm -rf /lib/modules
108
109case "$(uname -m)" in
110 i?86)
111 # Backup grub.conf
112 cp -vf /boot/grub/grub.conf /boot/grub-legacy.conf
113
114 # Remove all files that belong to GRUB-legacy
115 rm -rfv /boot/grub
116 ;;
117esac
118#
119#Stop services
120/etc/init.d/snort stop
121/etc/init.d/squid stop
122/etc/init.d/ipsec stop
123/etc/init.d/apache stop
124
125#
126#Extract files
127tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
128
bbdd37b1
AF
129#
130#restart init because glibc was updated.
75f3abe2 131telinit u
bbdd37b1 132
77642396
MT
133# Check diskspace on boot
134BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
135
136if [ $BOOTSPACE -lt 1000 ]; then
137 case $(uname -r) in
138 *-ipfire-kirkwood )
139 # Special handling for old kirkwood images.
140 # (install only kirkwood kernel)
141 rm -rf /boot/*
142 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
143 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
144 ;;
145 * )
146 /usr/bin/logger -p syslog.emerg -t ipfire \
147 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
148 /etc/init.d/apache start
149 exit 4
150 ;;
151 esac
152fi
c172d453
MT
153
154# Update Language cache
155perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
156
77642396
MT
157# Add nobody to group dialout
158usermod -a -G dialout nobody
159
160#
161# Start services
162#
163/etc/init.d/apache start
164/etc/init.d/squid start
165/etc/init.d/snort start
166if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
167 /etc/init.d/ipsec start
168fi
169
170case "$(uname -m)" in
171 i?86)
172 #
173 # Update to GRUB2
174 #
175 echo
176 echo Update grub configuration ...
177 if grep -qE "^serial" /boot/grub-legacy.conf; then
178 sed -i /etc/default/grub \
179 -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g"
180 echo "GRUB_TERMINAL=\"serial\"" >> /etc/default/grub
181 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
182 fi
77642396 183
ff3bae7b
MT
184 if ! /usr/local/bin/update-bootloader; then
185 logger -p syslog.emerg -t ipfire \
186 "Could not update the bootloader!"
77642396
MT
187 fi
188 ;;
189esac
190
191# Force (re)install pae kernel if pae is supported
192rm -rf /opt/pakfire/db/*/meta-linux-pae
193if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
194 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
195 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
196 if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then
197 /usr/bin/logger -p syslog.emerg -t ipfire \
198 "core-update-${core}: WARNING not enough space for pae kernel."
199 else
200 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
201 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
202 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
203 echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae
204 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae
205 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae
c172d453
MT
206 fi
207fi
208
77642396
MT
209# Force reinstall xen kernel if it was installed
210if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
211 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
212 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
213 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
214 echo "Name: linux-xen" > /opt/pakfire/db/meta/meta-linux-xen
215 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-xen
216 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-xen
217 # Add xvc0 to /etc/securetty
218 echo "xvc0" >> /etc/securetty
219fi
220
221#
222# After pakfire has ended run it again and update the lists and do upgrade
223#
224echo '#!/bin/bash' > /tmp/pak_update
225echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
226echo ' sleep 1' >> /tmp/pak_update
227echo 'done' >> /tmp/pak_update
228echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
229echo ' sleep 1' >> /tmp/pak_update
230echo 'done' >> /tmp/pak_update
231echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
232echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
233echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
234echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
235echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
236echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
237echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
238echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
239#
240killall -KILL pak_update
241chmod +x /tmp/pak_update
242/tmp/pak_update &
243
c172d453
MT
244sync
245
77642396
MT
246#
247#Finish
248(
249 /etc/init.d/fireinfo start
250 sendprofile
251) >/dev/null 2>&1 &
252
253# Update Package list for addon installation
254/opt/pakfire/pakfire update -y --force
c172d453 255
77642396
MT
256echo
257echo Please wait until pakfire has ended...
258echo
c172d453
MT
259
260# Don't report the exitcode last command
261exit 0