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