Moved squid restart at coreupdate to the end of update process.
[ipfire-2.x.git] / config / rootfiles / core / 38 / 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) 2010 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 OLDVERSION=`grep "version = " /opt/pakfire/etc/pakfire.conf | cut -d'"' -f2`
28 #
29 # Test if we running on xen
30 #
31 uname -r | grep "ipfire-xen";
32 if [ ${?} = 0 ]; then
33         #Xen Kernel is active
34         NEWVERSION="2.7-xen"
35 else
36         #Normal Kernel
37         NEWVERSION="2.7"
38 fi
39 #
40 KVER="2.6.32.15"
41 ROOT=`grep "root=" /boot/grub/grub.conf | cut -d"=" -f2 | cut -d" " -f1 | tail -n 1`
42 MOUNT=`grep "kernel" /boot/grub/grub.conf | tail -n 1`
43 # Nur den letzten Parameter verwenden
44 echo $MOUNT > /dev/null
45 MOUNT=$_
46 if [ ! $MOUNT == "rw" ]; then
47         MOUNT="ro"
48 fi
49 #
50 # check if we the backup file already exist
51 if [ -e /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 ]; then
52     echo Moving backup to backup-old ...
53     mv -f /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
54        /var/ipfire/backup/core-upgrade_$KVER-old.tar.bz2
55 fi
56 echo First we made a backup of all files that was inside of the
57 echo update archive. This may take a while ...
58 # Add some files that are not in the package to backup
59 echo lib/modules >> /opt/pakfire/tmp/ROOTFILES
60 echo boot >> /opt/pakfire/tmp/ROOTFILES
61 echo etc/sysconfig/lm_sensors >> /opt/pakfire/tmp/ROOTFILES
62 echo usr/lib/ipsec >> /opt/pakfire/tmp/ROOTFILES
63 echo usr/libexec/ipsec >> /opt/pakfire/tmp/ROOTFILES
64 tar cjvf /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
65     -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' > /dev/null 2>&1
66
67 #
68 # Stop Sevices
69 #
70 /etc/init.d/collectd stop
71 /etc/init.d/squid stop
72 /etc/init.d/ipsec stop
73 /etc/init.d/snort stop
74
75 echo
76 echo Update Kernel to $KVER ...
77 # Remove old kernel, configs, initrd, modules ...
78 #
79 rm -rf /boot/System.map-*
80 rm -rf /boot/config-*
81 rm -rf /boot/ipfirerd-*
82 rm -rf /boot/vmlinuz-*
83 rm -rf /lib/modules/*-ipfire
84 # Don't remove all old xen modules. Kernel may stored outside.
85 # only from 2.6.27.25 and 31
86 rm -rf /lib/modules/2.6.27.25-ipfire-xen
87 rm -rf /lib/modules/2.6.27.31-ipfire-xen
88 #
89 # remove openswan libs ...
90 #
91 rm -rf /usr/lib/ipsec
92 rm -rf /usr/libexec/ipsec
93 #
94 # old snort libs and rules ...
95 #
96 rm -rf /usr/lib/snort_*
97 rm -rf /etc/snort
98 #
99 # mISDN Files that was moved to sbin
100 #
101 rm -rf /usr/bin/misdn_rename
102 rm -rf /usr/bin/misdn_cleanl2
103 #
104 # Backup grub.conf
105 #
106 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
107 #
108 # Stop sysklogd
109 /etc/init.d/sysklogd stop
110 #
111 # Unpack the updated files
112 #
113 echo
114 echo Unpack the updated files ...
115 #
116 tar xvf /opt/pakfire/tmp/files --preserve --numeric-owner -C / \
117         --no-overwrite-dir
118 #
119 # Start sysklogd
120 /etc/init.d/sysklogd start
121 #
122 # Modify grub.conf
123 #
124 echo
125 echo Update grub configuration ...
126 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
127 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
128 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
129
130 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
131         echo "grub use default console ..."
132 else
133         echo "grub use serial console ..."
134         sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
135         sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
136         sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
137         sed -i -e "s| panic=10 | console=ttyS0,38400n8 panic=10 |g" /boot/grub/grub.conf
138 fi
139 #
140 # Made emergency - initramdisk
141 #
142 echo
143 echo Create new Initramdisks ...
144 cp -f /etc/mkinitcpio.conf /etc/mkinitcpio.conf.org
145 sed -i "s| autodetect | |g" /etc/mkinitcpio.conf
146 mkinitcpio -k $KVER-ipfire -g /boot/ipfirerd-$KVER-emergency.img
147 cp -f /etc/mkinitcpio.conf.org /etc/mkinitcpio.conf
148 #
149 # Made initramdisk
150 #
151 if [ "${ROOT:0:7}" == "/dev/sd" ]; then
152     # Remove ide hook if root is on sda
153     sed -i "s| ide | |g" /etc/mkinitcpio.conf
154 else
155 if [ "${ROOT:0:7}" == "/dev/hd" ]; then
156     # Remove pata & sata hook if root is on hda
157     sed -i "s| pata | |g" /etc/mkinitcpio.conf
158     sed -i "s| sata | |g" /etc/mkinitcpio.conf
159 fi
160 fi
161 mkinitcpio -k $KVER-ipfire -g /boot/ipfirerd-$KVER.img
162 #
163 # ReInstall grub
164 #
165 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
166 #
167 # Rebuild Language
168 #
169 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
170 #
171 # Cleanup Collectd statistics...
172 #
173 PRECLEAN=`du -sh /var/log/rrd/collectd`
174 #
175 rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_count*
176 rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_pagefaults*
177 rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_stacksize*
178 rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_state*
179 rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_vm*
180 #
181 rm -rf /var/log/rrd*/collectd/localhost/interface/if_errors*
182 rm -rf /var/log/rrd*/collectd/localhost/interface/if_packets*
183 #
184 rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_merged*
185 rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_ops*
186 rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_time*
187 #
188 rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-INPUT/*-DROP_Wirelessinput*
189 rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-FORWARD/*-DROP_Wirelessforward*
190 rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-OUTGOINGFW
191 POSTCLEAN=`du -sh /var/log/rrd/collectd`
192 #
193 echo Cleaned up collectd directory from $PRECLEAN to $POSTCLEAN size.
194 #
195 # Start collectd
196 /etc/init.d/collectd start
197 #
198 # Delete old lm-sensor modullist to force search at next boot
199 #
200 rm -rf /etc/sysconfig/lm_sensors
201 #
202 # USB Modeswitch conf now called setup, rename ...
203 #
204 if [ -e /etc/usb_modeswitch.conf ]; then
205 mv -f /etc/usb_modeswitch.conf /etc/usb_modeswitch.setup
206 fi
207 #
208 # rebuild qosscript if enabled...
209 if [ -e /var/ipfire/qos/enable ]; then
210         /usr/local/bin/qosctrl stop
211         /usr/local/bin/qosctrl generate
212         /usr/local/bin/qosctrl start
213 fi
214 #
215 #
216 # convert ipsec.conf from openswan to strongswan...
217 mv /var/ipfire/vpn/ipsec.conf /var/ipfire/vpn/ipsec.conf.org
218 cat /var/ipfire/vpn/ipsec.conf.org | \
219 grep -v "disablearrivalcheck=" | \
220 grep -v "klipsdebug=" | \
221 grep -v "leftfirewall=" | \
222 grep -v "lefthostaccess=" | \
223 grep -v "charonstart=" | \
224 grep -v "aggrmode=" > /var/ipfire/vpn/ipsec.conf
225 sed -i "s|ipsec[0-9]=||g" /var/ipfire/vpn/ipsec.conf
226 sed -i "s|nat_t ||g" /var/ipfire/vpn/ipsec.conf
227 sed -i "s|klips ||g" /var/ipfire/vpn/ipsec.conf
228 sed -i "s|^conn [A-Za-z].*$|&\n\tleftfirewall=yes\n\tlefthostaccess=yes|g" /var/ipfire/vpn/ipsec.conf
229 sed -i "s|^config setup$|&\n\tcharonstart=no|g" /var/ipfire/vpn/ipsec.conf
230 chown nobody:nobody /var/ipfire/vpn/ipsec.conf
231 chmod 644 /var/ipfire/vpn/ipsec.conf
232 #
233 # Add cryptodev to /etc/sysconfig/modules
234 mv /etc/sysconfig/modules /etc/sysconfig/modules.org
235 cat /etc/sysconfig/modules.org | \
236 grep -v "cryptodev" | \
237 grep -v "# End /etc/sysconfig/modules" > /etc/sysconfig/modules
238 echo "" >> /etc/sysconfig/modules
239 echo "### cryptodev" >> /etc/sysconfig/modules
240 echo "#" >> /etc/sysconfig/modules
241 echo "cryptodev" >> /etc/sysconfig/modules
242 echo "" >> /etc/sysconfig/modules
243 echo "# End /etc/sysconfig/modules" >> /etc/sysconfig/modules
244 chmod 644 /etc/sysconfig/modules
245 # Change version of Pakfire.conf
246 #
247 sed -i "s|$OLDVERSION|$NEWVERSION|g" /opt/pakfire/etc/pakfire.conf
248 #
249 # After pakfire has ended run it again and update the lists and do upgrade
250 #
251 echo '#!/bin/bash'                                        >  /tmp/pak_update
252 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
253 echo '    sleep 1'                                        >> /tmp/pak_update
254 echo 'done'                                               >> /tmp/pak_update
255 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do'   >> /tmp/pak_update
256 echo '    sleep 1'                                        >> /tmp/pak_update
257 echo 'done'                                               >> /tmp/pak_update
258 echo '/opt/pakfire/pakfire update -y --force'             >> /tmp/pak_update
259 echo '/opt/pakfire/pakfire upgrade -y'                    >> /tmp/pak_update
260 echo '/opt/pakfire/pakfire upgrade -y'                    >> /tmp/pak_update
261 echo '/opt/pakfire/pakfire upgrade -y'                    >> /tmp/pak_update
262 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 "Upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
263 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 "Check it before reboot !!!"' >> /tmp/pak_update
264 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 " *** Please reboot... *** "' >> /tmp/pak_update
265 #
266 chmod +x /tmp/pak_update
267 /tmp/pak_update &
268 #
269 # Start squid
270 /etc/init.d/squid start
271 #
272 echo
273 echo Please wait until pakfire has ended...
274 echo