]>
Commit | Line | Data |
---|---|---|
5b64ed2e MT |
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) 2015 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 | ||
12b5c00d AF |
27 | |
28 | function find_device() { | |
29 | local mountpoint="${1}" | |
30 | ||
31 | local root | |
32 | local dev mp fs flags rest | |
33 | while read -r dev mp fs flags rest; do | |
34 | # Skip unwanted entries | |
35 | [ "${dev}" = "rootfs" ] && continue | |
36 | ||
37 | if [ "${mp}" = "${mountpoint}" ] && [ -b "${dev}" ]; then | |
38 | root="$(basename "${dev}")" | |
39 | break | |
40 | fi | |
41 | done < /proc/mounts | |
42 | ||
43 | # Get the actual device from the partition that holds / | |
44 | while [ -n "${root}" ]; do | |
45 | if [ -e "/sys/block/${root}" ]; then | |
46 | echo "${root}" | |
47 | return 0 | |
48 | fi | |
49 | ||
50 | # Remove last character | |
51 | root="${root::-1}" | |
52 | done | |
53 | ||
54 | return 1 | |
55 | } | |
56 | ||
57 | ||
58 | # | |
5b64ed2e | 59 | # Remove old core updates from pakfire cache to save space... |
4b046d73 | 60 | core=95 |
5b64ed2e MT |
61 | for (( i=1; i<=$core; i++ )) |
62 | do | |
63 | rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire | |
64 | done | |
65 | ||
12b5c00d AF |
66 | # |
67 | # Do some sanity checks. | |
68 | case $(uname -r) in | |
69 | *-ipfire-versatile ) | |
70 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
71 | "core-update-${core}: ERROR cannot update. versatile support is dropped." | |
72 | # Report no error to pakfire. So it does not try to install it again. | |
73 | exit 0 | |
74 | ;; | |
75 | *-ipfire* ) | |
76 | # Ok. | |
77 | ;; | |
78 | * ) | |
79 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
80 | "core-update-${core}: ERROR cannot update. No IPFire Kernel." | |
81 | exit 1 | |
82 | ;; | |
83 | esac | |
84 | ||
85 | ||
86 | # | |
87 | # | |
88 | KVER="xxxKVERxxx" | |
89 | ||
90 | # Check diskspace on root | |
91 | ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
92 | ||
93 | if [ $ROOTSPACE -lt 100000 ]; then | |
94 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
95 | "core-update-${core}: ERROR cannot update because not enough free space on root." | |
96 | exit 2 | |
97 | fi | |
98 | ||
99 | ||
100 | echo | |
101 | echo Update Kernel to $KVER ... | |
102 | # | |
103 | # Remove old kernel, configs, initrd, modules, dtb's ... | |
104 | # | |
105 | rm -rf /boot/System.map-* | |
106 | rm -rf /boot/config-* | |
107 | rm -rf /boot/ipfirerd-* | |
108 | rm -rf /boot/initramfs-* | |
109 | rm -rf /boot/vmlinuz-* | |
110 | rm -rf /boot/uImage-ipfire-* | |
111 | rm -rf /boot/uInit-ipfire-* | |
112 | rm -rf /boot/dtb-*-ipfire-* | |
113 | rm -rf /lib/modules | |
114 | ||
115 | case "$(uname -m)" in | |
116 | armv*) | |
117 | # Backup uEnv.txt if exist | |
118 | if [ -e /boot/uEnv.txt ]; then | |
119 | cp -vf /boot/uEnv.txt /boot/uEnv.txt.org | |
120 | fi | |
121 | ||
122 | # work around the u-boot folder detection bug | |
123 | mkdir -pv /boot/dtb-$KVER-ipfire-kirkwood | |
124 | mkdir -pv /boot/dtb-$KVER-ipfire-multi | |
125 | ;; | |
126 | esac | |
127 | ||
55eb745e MT |
128 | # Remove files |
129 | rm -f /etc/rc.d/init.d/network-vlans | |
130 | rm -f /etc/rc.d/rcsysinit.d/S91network-vlans | |
131 | ||
12b5c00d AF |
132 | # |
133 | #Stop services | |
134 | /etc/init.d/snort stop | |
135 | /etc/init.d/squid stop | |
8235f17d | 136 | /etc/init.d/ipsec stop |
12b5c00d AF |
137 | /etc/init.d/ntp stop |
138 | /etc/init.d/apache stop | |
139 | ||
140 | # | |
141 | #Extract files | |
142 | tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C / | |
143 | ||
144 | # Check diskspace on boot | |
145 | BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
146 | ||
147 | if [ $BOOTSPACE -lt 1000 ]; then | |
148 | case $(uname -r) in | |
149 | *-ipfire-kirkwood ) | |
150 | # Special handling for old kirkwood images. | |
151 | # (install only kirkwood kernel) | |
152 | rm -rf /boot/* | |
153 | # work around the u-boot folder detection bug | |
154 | mkdir -pv /boot/dtb-$KVER-ipfire-kirkwood | |
155 | tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \ | |
156 | --numeric-owner -C / --wildcards 'boot/*-kirkwood*' | |
157 | ;; | |
158 | * ) | |
159 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
160 | "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..." | |
161 | /etc/init.d/apache start | |
162 | exit 4 | |
163 | ;; | |
164 | esac | |
165 | fi | |
5b64ed2e | 166 | |
12b5c00d AF |
167 | # Regenerate IPsec configuration |
168 | sudo -u nobody /srv/web/ipfire/cgi-bin/vpnmain.cgi | |
5b64ed2e MT |
169 | |
170 | # Update Language cache | |
171 | /usr/local/bin/update-lang-cache | |
172 | ||
12b5c00d | 173 | # |
3dc6dced | 174 | # Start services |
12b5c00d AF |
175 | # |
176 | /etc/init.d/apache start | |
177 | /etc/init.d/ntp start | |
178 | /etc/init.d/squid start | |
179 | /etc/init.d/snort start | |
8235f17d MT |
180 | if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then |
181 | /etc/init.d/ipsec start | |
182 | fi | |
3dc6dced | 183 | |
12b5c00d AF |
184 | if [ -e /boot/grub/grub.cfg ]; then |
185 | grub-mkconfig > /boot/grub/grub.cfg | |
186 | fi | |
5b64ed2e | 187 | |
12b5c00d AF |
188 | # Upadate Kernel version uEnv.txt |
189 | if [ -e /boot/uEnv.txt ]; then | |
190 | sed -i -e "s/KVER=.*/KVER=${KVER}/g" /boot/uEnv.txt | |
191 | fi | |
192 | ||
193 | # call user update script (needed for some arm boards) | |
194 | if [ -e /boot/pakfire-kernel-update ]; then | |
195 | /boot/pakfire-kernel-update ${KVER} | |
196 | fi | |
197 | ||
198 | case "$(uname -m)" in | |
199 | i?86) | |
200 | # Force (re)install pae kernel if pae is supported | |
201 | rm -rf /opt/pakfire/db/installed/meta-linux-pae | |
202 | if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then | |
203 | ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
204 | BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1` | |
205 | if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then | |
206 | /usr/bin/logger -p syslog.emerg -t ipfire \ | |
207 | "core-update-${core}: WARNING not enough space for pae kernel." | |
208 | else | |
209 | echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae | |
210 | echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae | |
211 | echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae | |
212 | fi | |
213 | fi | |
214 | ;; | |
215 | esac | |
216 | # | |
217 | # After pakfire has ended run it again and update the lists and do upgrade | |
218 | # | |
219 | echo '#!/bin/bash' > /tmp/pak_update | |
220 | echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update | |
221 | echo ' sleep 1' >> /tmp/pak_update | |
222 | echo 'done' >> /tmp/pak_update | |
223 | echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update | |
224 | echo ' sleep 1' >> /tmp/pak_update | |
225 | echo 'done' >> /tmp/pak_update | |
226 | echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update | |
227 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
228 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
229 | echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update | |
230 | echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub/uboot config"' >> /tmp/pak_update | |
231 | echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update | |
232 | echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update | |
233 | echo 'touch /var/run/need_reboot ' >> /tmp/pak_update | |
234 | # | |
235 | killall -KILL pak_update | |
236 | chmod +x /tmp/pak_update | |
237 | /tmp/pak_update & | |
238 | ||
239 | sync | |
240 | ||
241 | # | |
242 | #Finish | |
5b64ed2e MT |
243 | /etc/init.d/fireinfo start |
244 | sendprofile | |
245 | # Update grub config to display new core version | |
246 | if [ -e /boot/grub/grub.cfg ]; then | |
7383bf2b | 247 | grub-mkconfig -o /boot/grub/grub.cfg |
5b64ed2e MT |
248 | fi |
249 | sync | |
250 | ||
12b5c00d AF |
251 | echo |
252 | echo Please wait until pakfire has ended... | |
253 | echo | |
254 | ||
5b64ed2e MT |
255 | # Don't report the exitcode last command |
256 | exit 0 |