]> git.ipfire.org Git - ipfire-2.x.git/blob - config/rootfiles/core/65/update.sh
dbd38c4d2ad2c3eafb6af9ed2e7c1beed02295d7
[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 #
176 # Modify grub.conf
177 #
178 echo
179 echo Update grub configuration ...
180 ROOT=`mount | grep " / " | cut -d" " -f1`
181
182 if [ ! -z $ROOT ]; then
183 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
184 fi
185
186 if [ ! -z $ROOTUUID ]; then
187 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
188 else
189 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
190 fi
191 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
192 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
193
194 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
195 echo "grub use default console ..."
196 else
197 echo "grub use serial console ..."
198 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
199 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
200 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
201 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
202 fi
203
204 #
205 # ReInstall grub
206 #
207 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
208
209 #
210 # Delete old lm-sensor modullist to force search at next boot
211 #
212 rm -rf /etc/sysconfig/lm_sensors
213
214 #
215 # Remove powerbutton loop from rc local.
216 #
217 sed -i "/# power button shutdown/,+3d" /etc/sysconfig/rc.local
218
219 #
220 #Update Language cache
221 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
222
223 #
224 # Remove meta's of packages that are now common...
225 #
226 rm -rf /opt/pakfire/db/*/meta-fontconfig
227 rm -rf /opt/pakfire/db/*/meta-glib
228
229 # Force (re)install pae kernel if pae is supported
230 rm -rf /opt/pakfire/db/*/meta-linux-pae
231 if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
232 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
233 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
234 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
235 fi
236
237 # Force reinstall xen kernel if it was installed
238 if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then
239 echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen
240 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen
241 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen
242 fi
243
244 #
245 # After pakfire has ended run it again and update the lists and do upgrade
246 #
247 echo '#!/bin/bash' > /tmp/pak_update
248 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
249 echo ' sleep 1' >> /tmp/pak_update
250 echo 'done' >> /tmp/pak_update
251 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
252 echo ' sleep 1' >> /tmp/pak_update
253 echo 'done' >> /tmp/pak_update
254 echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
255 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
256 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
257 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
258 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
259 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
260 echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
261 echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
262 #
263 chmod +x /tmp/pak_update
264 /tmp/pak_update &
265
266 sync
267
268 #
269 #Finish
270 /etc/init.d/fireinfo start
271 sendprofile
272
273 echo
274 echo Please wait until pakfire has ended...
275 echo
276 #Don't report the exitcode last command
277 exit 0
278