]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/rootfiles/core/76/update.sh
Fix relocating NTP binaries.
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / 76 / 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=76
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-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 exit 1
68 ;;
69 esac
70
71
72 #
73 #
74 KVER="xxxKVERxxx"
75 MOUNT=`grep "kernel" /boot/grub/grub.conf 2>/dev/null | tail -n 1 `
76 # Nur den letzten Parameter verwenden
77 echo $MOUNT > /dev/null
78 MOUNT=$_
79 if [ ! $MOUNT == "rw" ]; then
80 MOUNT="ro"
81 fi
82
83 #
84 # check if we the backup file already exist
85 if [ -e /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz ]; then
86 echo Moving backup to backup-old ...
87 mv -f /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
88 /var/ipfire/backup/core-upgrade${core}_${KVER}-old.tar.xz
89 fi
90 echo First we made a backup of all files that was inside of the
91 echo update archive. This may take a while ...
92 # Add some files that are not in the package to backup
93 add_to_backup lib/modules
94 add_to_backup etc/udev
95 add_to_backup lib/udev
96 add_to_backup boot
97 add_to_backup etc/sysconfig/lm_sensors
98 add_to_backup etc/sysconfig/rc.local
99 add_to_backup srv/web/ipfire/html/themes/ipfire
100 add_to_backup usr/lib/engines
101 add_to_backup etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
102 add_to_backup etc/rc.d/init.d/networking/red.up/25-portfw
103 add_to_backup etc/rc.d/init.d/networking/red.up/26-xtaccess
104 add_to_backup usr/local/bin/setportfw
105 add_to_backup usr/local/bin/setdmzholes
106 add_to_backup usr/local/bin/setxtaccess
107 add_to_backup usr/local/bin/outgoingfwctrl
108 add_to_backup srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
109 add_to_backup var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
110 add_to_backup etc/inittab
111 add_to_backup etc/fstab
112 add_to_backup usr/share/usb_modeswitch
113
114 # Backup the files
115 tar cJvf /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \
116 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
117
118 # Check diskspace on root
119 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
120
121 if [ $ROOTSPACE -lt 100000 ]; then
122 /usr/bin/logger -p syslog.emerg -t ipfire \
123 "core-update-${core}: ERROR cannot update because not enough free space on root."
124 exit 2
125 fi
126
127
128 echo
129 echo Update Kernel to $KVER ...
130 #
131 # Remove old kernel, configs, initrd, modules ...
132 #
133 rm -rf /boot/System.map-*
134 rm -rf /boot/config-*
135 rm -rf /boot/ipfirerd-*
136 rm -rf /boot/vmlinuz-*
137 rm -rf /boot/uImage-ipfire-*
138 rm -rf /boot/uInit-ipfire-*
139 rm -rf /lib/modules
140
141 # Remove old usb_modeswitch_data
142 rm -rf /usr/share/usb_modeswitch
143
144 #
145 # Remove old udev rules.
146 #
147 if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
148 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
149 fi
150 cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
151 rm -rf /etc/udev
152 rm -rf /lib/udev
153 mkdir -p /etc/udev/rules.d
154 if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
155 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
156 fi
157 mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
158
159 case $(uname -m) in
160 i?86 )
161 #
162 # Backup grub.conf
163 #
164 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
165 ;;
166 esac
167 #
168 #Stop services
169 /etc/init.d/snort stop
170 /etc/init.d/squid stop
171 /etc/init.d/ipsec stop
172 /etc/init.d/apache stop
173
174 # Remove the old default theme
175 rm -rf /srv/web/ipfire/html/themes/ipfire
176
177 # rename /etc/modprobe.d files
178 for i in $(find /etc/modprobe.d/* | grep -v ".conf"); do
179 mv $i $i.conf
180 done
181
182 # Move /var/run to /run.
183 if [ -L "/run" ]; then
184 rm -f /run
185 fi
186
187 mkdir -p /run
188 if mountpoint /var/run; then
189 mount --move /var/run /run
190 rm -rf /var/run
191 fi
192
193 ln -svf ../run /var/run
194
195 # Creating directories for new firewall.
196 mkdir -p /var/ipfire/firewall
197 mkdir -p /var/ipfire/fwhosts
198
199 # Remove old ntp binaries
200 rm -f /usr/sbin/ntp-keygen
201 rm -f /usr/sbin/ntp-wait
202 rm -f /usr/sbin/ntpq
203 rm -f /usr/sbin/ntptime
204 rm -f /usr/sbin/ntptrace
205 rm -f /usr/sbin/tickadj
206
207 #
208 #Extract files
209 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
210
211 # Check diskspace on boot
212 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
213
214 if [ $BOOTSPACE -lt 1000 ]; then
215 case $(uname -r) in
216 *-ipfire-kirkwood )
217 # Special handling for old kirkwood images.
218 # (install only kirkwood kernel)
219 rm -rf /boot/*
220 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
221 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
222 ;;
223 * )
224 /usr/bin/logger -p syslog.emerg -t ipfire \
225 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
226 /etc/init.d/apache start
227 exit 4
228 ;;
229 esac
230 fi
231
232 #
233 #Reload init to close old linker/glibc
234 telinit u
235
236 # Regenerate ipsec configuration files.
237 /srv/web/ipfire/cgi-bin/vpnmain.cgi
238
239 # Update Language cache
240 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
241
242 # Remove old openssl engines
243 rm -rf /usr/lib/engines
244
245 # Remove old initscripts
246 rm -f /etc/rc.d/init.d/networking/red.up/22-outgoingfwctrl
247 rm -f /etc/rc.d/init.d/networking/red.up/25-portfw
248 rm -f /etc/rc.d/init.d/networking/red.up/26-xtaccess
249 rm -f /etc/rc.d/rcsysinit.d/S90sysctl
250
251 # Remove old firewallscripts
252 rm -f /usr/local/bin/setportfw
253 rm -f /usr/local/bin/setdmzholes
254 rm -f /usr/local/bin/setxtaccess
255 rm -f /usr/local/bin/outgoingfwctrl
256
257 # Remove old CGI files
258 rm -f /srv/web/ipfire/cgi-bin/{dmzholes,outgoingfw,portfw,xtaccess}.cgi
259
260 # Generate chains for new firewall
261 /sbin/iptables -N INPUTFW 2>/dev/null
262 /sbin/iptables -N FORWARDFW 2>/dev/null
263 /sbin/iptables -N POLICYFWD 2>/dev/null
264 /sbin/iptables -N POLICYIN 2>/dev/null
265 /sbin/iptables -N POLICYOUT 2>/dev/null
266 /sbin/iptables -t nat -N NAT_SOURCE 2>/dev/null
267 /sbin/iptables -t nat -N NAT_DESTINATION 2>/dev/null
268
269 # Create config files for firewall and fix permissions.
270 touch /var/ipfire/firewall/config
271 touch /var/ipfire/firewall/input
272 touch /var/ipfire/firewall/outgoing
273 touch /var/ipfire/firewall/settings
274 touch /var/ipfire/fwhosts/customhosts
275 touch /var/ipfire/fwhosts/customnetworks
276 touch /var/ipfire/fwhosts/customgroups
277 touch /var/ipfire/fwhosts/customservices
278 touch /var/ipfire/fwhosts/customservicegrp
279
280 # Fix ownership.
281 chown -R nobody:nobody /var/ipfire/firewall
282 chown -R nobody:nobody /var/ipfire/fwhosts
283
284 # Convert firewall configuration
285 /usr/sbin/convert-xtaccess
286 /usr/sbin/convert-outgoingfw
287 /usr/sbin/convert-portfw
288 /usr/sbin/convert-dmz
289
290 # Remove old firewall configuration files
291 rm -rf /var/ipfire/{dmzholes,portfw,outgoing,xtaccess}
292
293 # In previously released IPFire versions the DROPOUTPUT and DROPINPUT
294 # option have two identical lines in the optionsfw/settings file as long as
295 # the user hasn't done any changes on the WUI.
296 #
297 # To prevent from any kind of side effects we are going to solve this issue now.
298
299 # Fix doubble enties of DROPOUTPUT when the default settings are still in use
300 # (the save button on the WUI page never has been clicked) or convert to the
301 # new option name required by the firewall of IPFire 2.15.
302
303 optionsfw_file="/var/ipfire/optionsfw/settings"
304
305 if [ $(grep -c "DROPOUTPUT" ${optionsfw_file}) -gt 1 ] ; then
306
307 # Drop all DROPUTPUT entries.
308 sed -e "/DROPOUTPUT/d" -i ${optionsfw_file}
309
310 # Add default line for new option.
311 echo "DROPOUTGOING=on" >> ${optionsfw_file}
312 else
313
314 # Convert option name to new format.
315 sed -e "s/DROPOUTPUT/DROPOUTGOING/g" -i ${optionsfw_file}
316 fi
317
318 # Fix doubble enties of DROPINPUT when the default settings are still in use
319 # (the save button on the WUI page never has been clicked).
320 if [ $(grep -c "DROPINPUT" ${optionsfw_file}) -gt 1 ] ; then
321
322 # We only can remove all entries with an defined string.
323 sed -e "/DROPINPUT/d" -i ${optionsfw_file}
324
325 # Afterwards we have to add the required string with the default
326 # value again.
327 echo "DROPINPUT=on" >> ${optionsfw_file}
328 fi
329
330 # Add strings and default values for new options of the firewall.
331 echo "DROPFORWARD=on" >> ${optionsfw_file}
332 echo "FWPOLICY=DROP" >> ${optionsfw_file}
333 echo "FWPOLICY1=DROP" >> ${optionsfw_file}
334 echo "FWPOLICY2=DROP" >> ${optionsfw_file}
335 echo "DROPSAMBA=off" >> ${optionsfw_file}
336 echo "DROPPROXY=off" >> ${optionsfw_file}
337 echo "SHOWREMARK=on" >> ${optionsfw_file}
338 echo "SHOWCOLORS=on" >> ${optionsfw_file}
339 echo "SHOWTABLES=off" >> ${optionsfw_file}
340 echo "SHOWDROPDOWN=off" >> ${optionsfw_file}
341 echo "DROPWIRELESSINPUT=on" >> ${optionsfw_file}
342 echo "DROPWIRELESSFORWARD=on" >> ${optionsfw_file}
343
344 unset optionsfw_file
345
346 # Convert inittab and fstab
347 sed -i -e "s/tty1 9600$/tty1 9600 --noclear/g" /etc/inittab
348 sed -i -e "s/xvc0 9600$/xvc0 9600 --noclear/g" /etc/inittab
349 sed -i -e "s/^proc/#proc/g" /etc/fstab
350 sed -i -e "s/^sysfs/#sysfs/g" /etc/fstab
351 sed -i -e "s/^devpts/#devpts/g" /etc/fstab
352 sed -i -e "s|^none\s/var/run|#none /var/run|g" /etc/fstab
353
354 # Convert udev persistent network rules
355 sed -i -e "s/SYSFS{/ATTR{/g" /etc/udev/rules.d/30-persistent-network.rules
356
357 # Firstsetup was already run
358 touch /var/ipfire/main/firstsetup_ok
359
360 #
361 # Start services
362 #
363 /etc/init.d/apache start
364 /etc/init.d/squid start
365 /etc/init.d/snort start
366 if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
367 /etc/init.d/ipsec start
368 fi
369
370 #
371 # Rebuild qosscript if enabled
372 #
373 if [ -e /var/ipfire/qos/enable ]; then
374 /usr/local/bin/qosctrl stop
375 /usr/local/bin/qosctrl generate
376 /usr/local/bin/qosctrl start
377 fi
378
379 # Update crontab
380 cat <<EOF >> /var/spool/cron/root.orig
381
382 # Re-read firewall rules every Sunday in March, October and November to take care of daylight saving time
383 00 3 * 3 0 /usr/local/bin/timezone-transition /usr/local/bin/firewallctrl
384 00 2 * 10-11 0 /usr/local/bin/timezone-transition /usr/local/bin/firewallctrl
385 EOF
386 fcrontab -z &>/dev/null
387
388
389 case $(uname -m) in
390 i?86 )
391 #
392 # Modify grub.conf
393 #
394 echo
395 echo Update grub configuration ...
396 ROOT=`mount | grep " / " | cut -d" " -f1`
397
398 if [ ! -z $ROOT ]; then
399 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
400 fi
401
402 if [ ! -z $ROOTUUID ]; then
403 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
404 else
405 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
406 fi
407 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
408 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
409
410 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
411 echo "grub use default console ..."
412 else
413 echo "grub use serial console ..."
414 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
415 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
416 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
417 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
418 fi
419
420 #
421 # ReInstall grub
422 #
423 echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map
424 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1}
425 ;;
426 esac
427 #
428 # Delete old lm-sensor modullist to force search at next boot
429 #
430 rm -rf /etc/sysconfig/lm_sensors
431
432
433 # Force (re)install pae kernel if pae is supported
434 rm -rf /opt/pakfire/db/*/meta-linux-pae
435 if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
436 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
437 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
438 if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then
439 /usr/bin/logger -p syslog.emerg -t ipfire \
440 "core-update-${core}: WARNING not enough space for pae kernel."
441 else
442 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
443 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
444 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
445 echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae
446 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae
447 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae
448 fi
449 fi
450
451 # Force reinstall xen kernel if it was installed
452 if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
453 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
454 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
455 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
456 echo "Name: linux-xen" > /opt/pakfire/db/meta/meta-linux-xen
457 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-xen
458 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-xen
459 # Add xvc0 to /etc/securetty
460 echo "xvc0" >> /etc/securetty
461 fi
462
463 #
464 # After pakfire has ended run it again and update the lists and do upgrade
465 #
466 echo '#!/bin/bash' > /tmp/pak_update
467 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
468 echo ' sleep 1' >> /tmp/pak_update
469 echo 'done' >> /tmp/pak_update
470 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
471 echo ' sleep 1' >> /tmp/pak_update
472 echo 'done' >> /tmp/pak_update
473 echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
474 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
475 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
476 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
477 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
478 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
479 echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
480 echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
481 #
482 killall -KILL pak_update
483 chmod +x /tmp/pak_update
484 /tmp/pak_update &
485
486 sync
487
488 #
489 #Finish
490 (
491 /etc/init.d/fireinfo start
492 sendprofile
493 ) >/dev/null 2>&1 &
494
495 # Update Package list for addon installation
496 /opt/pakfire/pakfire update -y --force
497
498 echo
499 echo Please wait until pakfire has ended...
500 echo
501 #Don't report the exitcode last command
502 exit 0
503