]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/rootfiles/core/65/update.sh
ipsec: Shut up strongswan logging.
[people/teissler/ipfire-2.x.git] / config / rootfiles / core / 65 / 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) 2012 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 #
39 # TODO: need to be corrected before release
40 core=64
41 for (( i=1; i<=$core; i++ ))
42 do
43 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
44 done
45
46 #
47 # Do some sanity checks.
48 if [ ! "$(mount | grep " reiser4 (")" == "" ]; then
49 /usr/bin/logger -p syslog.emerg -t ipfire \
50 "core-update-$core: ERROR cannot update because there is a reiser4 fs mounted."
51 exit 1
52 fi
53
54 #
55 #
56 KVER="3.2.34"
57 MOUNT=`grep "kernel" /boot/grub/grub.conf | tail -n 1`
58 # Nur den letzten Parameter verwenden
59 echo $MOUNT > /dev/null
60 MOUNT=$_
61 if [ ! $MOUNT == "rw" ]; then
62 MOUNT="ro"
63 fi
64
65 #
66 # check if we the backup file already exist
67 if [ -e /var/ipfire/backup/core-upgrade_$KVER.tar.xz ]; then
68 echo Moving backup to backup-old ...
69 mv -f /var/ipfire/backup/core-upgrade_$KVER.tar.xz \
70 /var/ipfire/backup/core-upgrade_$KVER-old.tar.xz
71 fi
72 echo First we made a backup of all files that was inside of the
73 echo update archive. This may take a while ...
74 # Add some files that are not in the package to backup
75 add_to_backup lib/modules
76 add_to_backup etc/udev
77 add_to_backup lib/udev
78 add_to_backup boot
79 add_to_backup etc/snort
80 add_to_backup usr/lib/snort_*
81 add_to_backup usr/share/zoneinfo
82 add_to_backup lib/libncurses*
83 add_to_backup etc/dircolors
84 add_to_backup etc/profile.d
85 add_to_backup usr/share/terminfo
86 add_to_backup etc/sysconfig/lm_sensors
87 add_to_backup etc/sysconfig/rc.local
88
89 # Backup the files
90 tar cJvf /var/ipfire/backup/core-upgrade_$KVER.tar.xz \
91 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
92
93 # Check diskspace on root
94 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
95
96 if [ $ROOTSPACE -lt 70000 ]; then
97 /usr/bin/logger -p syslog.emerg -t ipfire \
98 "core-update-$core: ERROR cannot update because not enough free space on root."
99 exit 2
100 fi
101
102 echo
103 echo Update Kernel to $KVER ...
104 #
105 # Remove old kernel, configs, initrd, modules ...
106 #
107 rm -rf /boot/System.map-*
108 rm -rf /boot/config-*
109 rm -rf /boot/ipfirerd-*
110 rm -rf /boot/vmlinuz-*
111 rm -rf /boot/uImage-ipfire-*
112 rm -rf /boot/uInit-ipfire-*
113 rm -rf /lib/modules
114 rm -rf /etc/dircolors
115 rm -rf /etc/profile.d
116 rm -rf /usr/share/terminfo
117
118 #
119 # Remove old udev rules.
120 #
121 if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
122 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
123 fi
124 cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
125 rm -rf /etc/udev
126 rm -rf /lib/udev
127 mkdir -p /etc/udev/rules.d
128 if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
129 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
130 fi
131 mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
132
133 #
134 # Backup grub.conf
135 #
136 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
137
138 #
139 #Stop services
140 /etc/init.d/snort stop
141 /etc/init.d/squid stop
142 /etc/init.d/ipsec stop
143
144 #Remove old snort, zoneinfo and ncurses-libs(wrong path).
145 rm -rf /etc/snort
146 rm -rf /usr/lib/snort_*
147 rm -rf /usr/share/zoneinfo
148 rm -rf /lib/libncurses*
149
150 #
151 #Extract files
152 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
153
154 #
155 # Start services
156 #
157 /etc/init.d/squid start
158 /etc/init.d/snort start
159 if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
160 /etc/init.d/ipsec start
161 fi
162
163 #
164 # Rebuild qosscript if enabled
165 #
166 if [ -e /var/ipfire/qos/enable ]; then
167 /usr/local/bin/qosctrl stop
168 /usr/local/bin/qosctrl generate
169 /usr/local/bin/qosctrl start
170 fi
171
172 # Remove preloading libsafe.
173 rm -f /etc/ld.so.preload
174
175 # Regenerate ipsec configuration files.
176 /srv/web/ipfire/cgi-bin/vpnmain.cgi
177
178 #
179 # Modify grub.conf
180 #
181 echo
182 echo Update grub configuration ...
183 ROOT=`mount | grep " / " | cut -d" " -f1`
184
185 if [ ! -z $ROOT ]; then
186 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
187 fi
188
189 if [ ! -z $ROOTUUID ]; then
190 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
191 else
192 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
193 fi
194 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
195 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
196
197 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
198 echo "grub use default console ..."
199 else
200 echo "grub use serial console ..."
201 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
202 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
203 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
204 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
205 fi
206
207 #
208 # ReInstall grub
209 #
210 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
211
212 #
213 # Delete old lm-sensor modullist to force search at next boot
214 #
215 rm -rf /etc/sysconfig/lm_sensors
216
217 #
218 # Remove powerbutton loop from rc local.
219 #
220 sed -i "/# power button shutdown/,+3d" /etc/sysconfig/rc.local
221
222 #
223 #Update Language cache
224 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
225
226 #
227 # Remove meta's of packages that are now common...
228 #
229 rm -rf /opt/pakfire/db/*/meta-fontconfig
230 rm -rf /opt/pakfire/db/*/meta-glib
231
232 # Force (re)install pae kernel if pae is supported
233 rm -rf /opt/pakfire/db/*/meta-linux-pae
234 if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
235 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
236 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
237 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
238 fi
239
240 # Force reinstall xen kernel if it was installed
241 if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
242 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
243 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
244 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
245 fi
246
247 #
248 # After pakfire has ended run it again and update the lists and do upgrade
249 #
250 echo '#!/bin/bash' > /tmp/pak_update
251 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
252 echo ' sleep 1' >> /tmp/pak_update
253 echo 'done' >> /tmp/pak_update
254 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
255 echo ' sleep 1' >> /tmp/pak_update
256 echo 'done' >> /tmp/pak_update
257 echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
258 echo '/opt/pakfire/pakfire upgrade -y' >> /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 '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
262 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
263 echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
264 echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
265 #
266 chmod +x /tmp/pak_update
267 /tmp/pak_update &
268
269 sync
270
271 #
272 #Finish
273 /etc/init.d/fireinfo start
274 sendprofile
275
276 echo
277 echo Please wait until pakfire has ended...
278 echo
279 #Don't report the exitcode last command
280 exit 0
281