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