]>
Commit | Line | Data |
---|---|---|
2308525f AF |
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=78 | |
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 boot | |
95 | ||
96 | # Backup the files | |
97 | tar cJvf /var/ipfire/backup/core-upgrade${core}_${KVER}.tar.xz \ | |
98 | -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1 | |
99 | ||
100 | # Check diskspace on root | |
101 | ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
102 | ||
103 | if [ $ROOTSPACE -lt 100000 ]; then | |
104 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
105 | "core-update-${core}: ERROR cannot update because not enough free space on root." | |
106 | exit 2 | |
107 | fi | |
108 | ||
109 | ||
110 | echo | |
111 | echo Update Kernel to $KVER ... | |
112 | # | |
113 | # Remove old kernel, configs, initrd, modules ... | |
114 | # | |
115 | rm -rf /boot/System.map-* | |
116 | rm -rf /boot/config-* | |
117 | rm -rf /boot/ipfirerd-* | |
118 | rm -rf /boot/vmlinuz-* | |
119 | rm -rf /boot/uImage-ipfire-* | |
120 | rm -rf /boot/uInit-ipfire-* | |
121 | rm -rf /lib/modules | |
122 | ||
123 | case $(uname -m) in | |
124 | i?86 ) | |
125 | # | |
126 | # Backup grub.conf | |
127 | # | |
128 | cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org | |
129 | ;; | |
130 | esac | |
131 | # | |
132 | #Stop services | |
133 | /etc/init.d/snort stop | |
134 | /etc/init.d/squid stop | |
135 | /etc/init.d/ipsec stop | |
136 | /etc/init.d/apache stop | |
137 | ||
2308525f AF |
138 | # rename /etc/modprobe.d files |
139 | for i in $(find /etc/modprobe.d/* | grep -v ".conf"); do | |
140 | mv $i $i.conf | |
141 | done | |
142 | ||
143 | # | |
144 | #Extract files | |
145 | tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C / | |
146 | ||
147 | # Check diskspace on boot | |
148 | BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
149 | ||
150 | if [ $BOOTSPACE -lt 1000 ]; then | |
151 | case $(uname -r) in | |
152 | *-ipfire-kirkwood ) | |
153 | # Special handling for old kirkwood images. | |
154 | # (install only kirkwood kernel) | |
155 | rm -rf /boot/* | |
156 | tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \ | |
157 | --numeric-owner -C / --wildcards 'boot/*-kirkwood*' | |
158 | ;; | |
159 | * ) | |
160 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
161 | "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..." | |
162 | /etc/init.d/apache start | |
163 | exit 4 | |
164 | ;; | |
165 | esac | |
166 | fi | |
167 | ||
c24eba27 MT |
168 | # Update ping |
169 | rm -f /bin/ping | |
170 | ln -sf ../usr/bin/ping /bin/ping | |
171 | chmod 4755 /usr/bin/ping | |
2308525f AF |
172 | |
173 | # Update Language cache | |
174 | perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" | |
175 | ||
1efa8995 MT |
176 | # Add nobody to group dialout |
177 | usermod -a -G dialout nobody | |
178 | ||
2308525f AF |
179 | # |
180 | # Start services | |
181 | # | |
182 | /etc/init.d/apache start | |
183 | /etc/init.d/squid start | |
184 | /etc/init.d/snort start | |
185 | if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then | |
186 | /etc/init.d/ipsec start | |
187 | fi | |
188 | ||
189 | case $(uname -m) in | |
190 | i?86 ) | |
191 | # | |
192 | # Modify grub.conf | |
193 | # | |
194 | echo | |
195 | echo Update grub configuration ... | |
196 | ROOT=`mount | grep " / " | cut -d" " -f1` | |
197 | ||
198 | if [ ! -z $ROOT ]; then | |
199 | ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2` | |
200 | fi | |
201 | ||
202 | if [ ! -z $ROOTUUID ]; then | |
203 | sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf | |
204 | else | |
205 | sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf | |
206 | fi | |
207 | sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf | |
208 | sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf | |
209 | ||
210 | if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then | |
211 | echo "grub use default console ..." | |
212 | else | |
213 | echo "grub use serial console ..." | |
214 | sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf | |
215 | sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf | |
216 | sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf | |
217 | sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf | |
218 | fi | |
219 | ||
220 | # | |
221 | # ReInstall grub | |
222 | # | |
223 | echo "(hd0) ${ROOT::`expr length $ROOT`-1}" > /boot/grub/device.map | |
224 | grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} | |
225 | ;; | |
226 | esac | |
227 | ||
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 | ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
233 | BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
234 | if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then | |
235 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
236 | "core-update-${core}: WARNING not enough space for pae kernel." | |
237 | else | |
238 | echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae | |
239 | echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae | |
240 | echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae | |
241 | echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae | |
242 | echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae | |
243 | echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae | |
244 | fi | |
245 | fi | |
246 | ||
247 | # Force reinstall xen kernel if it was installed | |
248 | if [ -e "/opt/pakfire/db/installed/meta-linux-xen" ]; then | |
249 | echo "Name: linux-xen" > /opt/pakfire/db/installed/meta-linux-xen | |
250 | echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-xen | |
251 | echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-xen | |
252 | echo "Name: linux-xen" > /opt/pakfire/db/meta/meta-linux-xen | |
253 | echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-xen | |
254 | echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-xen | |
255 | # Add xvc0 to /etc/securetty | |
256 | echo "xvc0" >> /etc/securetty | |
257 | fi | |
258 | ||
259 | # | |
260 | # After pakfire has ended run it again and update the lists and do upgrade | |
261 | # | |
262 | echo '#!/bin/bash' > /tmp/pak_update | |
263 | echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update | |
264 | echo ' sleep 1' >> /tmp/pak_update | |
265 | echo 'done' >> /tmp/pak_update | |
266 | echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update | |
267 | echo ' sleep 1' >> /tmp/pak_update | |
268 | echo 'done' >> /tmp/pak_update | |
269 | echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update | |
270 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
271 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
272 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
273 | echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update | |
274 | echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update | |
275 | echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update | |
276 | echo 'touch /var/run/need_reboot ' >> /tmp/pak_update | |
277 | # | |
278 | killall -KILL pak_update | |
279 | chmod +x /tmp/pak_update | |
280 | /tmp/pak_update & | |
281 | ||
282 | sync | |
283 | ||
284 | # | |
285 | #Finish | |
286 | ( | |
287 | /etc/init.d/fireinfo start | |
288 | sendprofile | |
289 | ) >/dev/null 2>&1 & | |
290 | ||
291 | # Update Package list for addon installation | |
292 | /opt/pakfire/pakfire update -y --force | |
293 | ||
294 | echo | |
295 | echo Please wait until pakfire has ended... | |
296 | echo | |
297 | #Don't report the exitcode last command | |
298 | exit 0 | |
299 |