]> git.ipfire.org Git - ipfire-2.x.git/blob - config/rootfiles/core/86/update.sh
3d08ed4fa492b19b93c1c10d64eb87163ef04fd1
[ipfire-2.x.git] / config / rootfiles / core / 86 / 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) 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 #
28 # Remove old core updates from pakfire cache to save space...
29 core=86
30 for (( i=1; i<=${core}; i++ ))
31 do
32 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
33 done
34
35 #
36 # Do some sanity checks.
37 case $(uname -r) in
38 *-ipfire-versatile )
39 /usr/bin/logger -p syslog.emerg -t ipfire \
40 "core-update-${core}: ERROR cannot update. versatile support is dropped."
41 # Report no error to pakfire. So it does not try to install it again.
42 exit 0
43 ;;
44 *-ipfire* )
45 # Ok.
46 ;;
47 * )
48 /usr/bin/logger -p syslog.emerg -t ipfire \
49 "core-update-${core}: ERROR cannot update. No IPFire Kernel."
50 exit 1
51 ;;
52 esac
53
54
55 #
56 #
57 KVER="xxxKVERxxx"
58
59 # Check diskspace on root
60 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
61
62 if [ $ROOTSPACE -lt 100000 ]; then
63 /usr/bin/logger -p syslog.emerg -t ipfire \
64 "core-update-${core}: ERROR cannot update because not enough free space on root."
65 exit 2
66 fi
67
68
69 echo
70 echo Update Kernel to $KVER ...
71 #
72 # Remove old kernel, configs, initrd, modules, dtb's ...
73 #
74 rm -rf /boot/System.map-*
75 rm -rf /boot/config-*
76 rm -rf /boot/ipfirerd-*
77 rm -rf /boot/initramfs-*
78 rm -rf /boot/vmlinuz-*
79 rm -rf /boot/uImage-ipfire-*
80 rm -rf /boot/uInit-ipfire-*
81 rm -rf /boot/dtb-*-ipfire-*
82 rm -rf /lib/modules
83
84 case "$(uname -m)" in
85 i?86)
86 # Backup grub.conf
87 cp -vf /boot/grub/grub.conf /boot/grub-legacy.conf
88
89 # Remove all files that belong to GRUB-legacy
90 rm -rfv /boot/grub
91 ;;
92 esac
93 # Backup uEnv.txt if exist
94 if [ -e /boot/uEnv.txt ]; then
95 cp -vf /boot/uEnv.txt /boot/uEnv.txt.org
96 fi
97
98 #
99 #Stop services
100 /etc/init.d/snort stop
101 /etc/init.d/squid stop
102 /etc/init.d/ipsec stop
103 /etc/init.d/apache stop
104
105 #
106 #Extract files
107 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p --numeric-owner -C /
108
109 #
110 #restart init because glibc was updated.
111 telinit u
112
113 # Check diskspace on boot
114 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
115
116 if [ $BOOTSPACE -lt 1000 ]; then
117 case $(uname -r) in
118 *-ipfire-kirkwood )
119 # Special handling for old kirkwood images.
120 # (install only kirkwood kernel)
121 rm -rf /boot/*
122 tar xavf /opt/pakfire/tmp/files* --no-overwrite-dir -p \
123 --numeric-owner -C / --wildcards 'boot/*-kirkwood*'
124 ;;
125 * )
126 /usr/bin/logger -p syslog.emerg -t ipfire \
127 "core-update-${core}: FATAL-ERROR space run out on boot. System is not bootable..."
128 /etc/init.d/apache start
129 exit 4
130 ;;
131 esac
132 fi
133
134 # Update Language cache
135 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
136
137 # Add nobody to group dialout
138 usermod -a -G dialout nobody
139
140 #
141 # Start services
142 #
143 /etc/init.d/apache start
144 /etc/init.d/squid start
145 /etc/init.d/snort start
146 if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
147 /etc/init.d/ipsec start
148 fi
149
150 case "$(uname -m)" in
151 i?86)
152 #
153 # Update to GRUB2
154 #
155 echo
156 echo Update grub configuration ...
157 if grep -qE "^serial" /boot/grub-legacy.conf; then
158 sed -i /etc/default/grub \
159 -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g"
160 echo "GRUB_TERMINAL=\"serial\"" >> /etc/default/grub
161 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
162 fi
163
164 if ! /usr/local/bin/update-bootloader; then
165 logger -p syslog.emerg -t ipfire \
166 "Could not update the bootloader!"
167 fi
168 ;;
169 esac
170
171 # Force (re)install pae kernel if pae is supported
172 rm -rf /opt/pakfire/db/*/meta-linux-pae
173 if [ ! "$(grep "^flags.* pae " /proc/cpuinfo)" == "" ]; then
174 ROOTSPACE=`df / -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
175 BOOTSPACE=`df /boot -Pk | sed "s| * | |g" | cut -d" " -f4 | tail -n 1`
176 if [ $BOOTSPACE -lt 12000 -o $ROOTSPACE -lt 90000 ]; then
177 /usr/bin/logger -p syslog.emerg -t ipfire \
178 "core-update-${core}: WARNING not enough space for pae kernel."
179 else
180 echo "Name: linux-pae" > /opt/pakfire/db/installed/meta-linux-pae
181 echo "ProgVersion: 0" >> /opt/pakfire/db/installed/meta-linux-pae
182 echo "Release: 0" >> /opt/pakfire/db/installed/meta-linux-pae
183 echo "Name: linux-pae" > /opt/pakfire/db/meta/meta-linux-pae
184 echo "ProgVersion: 0" >> /opt/pakfire/db/meta/meta-linux-pae
185 echo "Release: 0" >> /opt/pakfire/db/meta/meta-linux-pae
186 fi
187 fi
188
189 #
190 # After pakfire has ended run it again and update the lists and do upgrade
191 #
192 echo '#!/bin/bash' > /tmp/pak_update
193 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
194 echo ' sleep 1' >> /tmp/pak_update
195 echo 'done' >> /tmp/pak_update
196 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
197 echo ' sleep 1' >> /tmp/pak_update
198 echo 'done' >> /tmp/pak_update
199 echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
200 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
201 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
202 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
203 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Core-upgrade finished. If you use a customized grub/uboot config"' >> /tmp/pak_update
204 echo '/usr/bin/logger -p syslog.emerg -t ipfire "Check it before reboot !!!"' >> /tmp/pak_update
205 echo '/usr/bin/logger -p syslog.emerg -t ipfire " *** Please reboot... *** "' >> /tmp/pak_update
206 echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
207 #
208 killall -KILL pak_update
209 chmod +x /tmp/pak_update
210 /tmp/pak_update &
211
212 sync
213
214 #
215 #Finish
216 (
217 /etc/init.d/fireinfo start
218 sendprofile
219 ) >/dev/null 2>&1 &
220
221 # Update Package list for addon installation
222 /opt/pakfire/pakfire update -y --force
223
224 echo
225 echo Please wait until pakfire has ended...
226 echo
227
228 # Don't report the exitcode last command
229 exit 0