]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/rootfiles/core/65/update.sh
updater: fix baudrate for serial console.
[people/teissler/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 core=65
39 for (( i=1; i<=$core; i++ ))
40 do
41 rm -f /var/cache/pakfire/core-upgrade-*-$i.ipfire
42 done
43
44 #
45 KVER="3.2.33"
46 MOUNT=`grep "kernel" /boot/grub/grub.conf | tail -n 1`
47 # Nur den letzten Parameter verwenden
48 echo $MOUNT > /dev/null
49 MOUNT=$_
50 if [ ! $MOUNT == "rw" ]; then
51 MOUNT="ro"
52 fi
53
54 #
55 # check if we the backup file already exist
56 if [ -e /var/ipfire/backup/core-upgrade_$KVER.tar.xz ]; then
57 echo Moving backup to backup-old ...
58 mv -f /var/ipfire/backup/core-upgrade_$KVER.tar.xz \
59 /var/ipfire/backup/core-upgrade_$KVER-old.tar.xz
60 fi
61 echo First we made a backup of all files that was inside of the
62 echo update archive. This may take a while ...
63 # Add some files that are not in the package to backup
64 add_to_backup lib/modules
65 add_to_backup etc/udev
66 add_to_backup lib/udev
67 add_to_backup boot
68 add_to_backup etc/snort
69 add_to_backup usr/lib/snort_*
70 add_to_backup usr/share/zoneinfo
71
72 # Backup the files
73 tar cJvf /var/ipfire/backup/core-upgrade_$KVER.tar.xz \
74 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' --exclude='/var/cache' > /dev/null 2>&1
75
76 echo
77 echo Update Kernel to $KVER ...
78 #
79 # Remove old kernel, configs, initrd, modules ...
80 #
81 rm -rf /boot/System.map-*
82 rm -rf /boot/config-*
83 rm -rf /boot/ipfirerd-*
84 rm -rf /boot/vmlinuz-*
85 rm -rf /lib/modules/*-ipfire
86 #
87 # Remove old udev rules.
88 #
89 if [ -e /etc/udev/rules.d/29-ct-server-network.rules ]; then
90 cp /etc/udev/rules.d/29-ct-server-network.rules /tmp/
91 fi
92 cp /etc/udev/rules.d/30-persistent-network.rules /tmp/
93 rm -rf /etc/udev
94 rm -rf /lib/udev
95 mkdir -p /etc/udev/rules.d
96 if [ -e /tmp/rules.d/29-ct-server-network.rules ]; then
97 mv /tmp/29-ct-server-network.rules /etc/udev/rules.d/
98 fi
99 mv /tmp/30-persistent-network.rules /etc/udev/rules.d/
100
101 #
102 # Backup grub.conf
103 #
104 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
105
106 #
107 #Stop services
108 /etc/init.d/snort stop
109 /etc/init.d/squid stop
110 /etc/init.d/ipsec stop
111
112 #Remove old snort and zoneinfo
113 rm -rf /etc/snort
114 rm -rf /usr/lib/snort_*
115 rm -rf /usr/share/zoneinfo
116
117 #
118 #Extract files
119 extract_files
120
121 #
122 # Start services
123 #
124 /etc/init.d/squid start
125 /etc/init.d/snort start
126 if [ `grep "ENABLED=on" /var/ipfire/vpn/settings` ]; then
127 /etc/init.d/ipsec start
128 fi
129
130 #
131 # Rebuild qosscript if enabled
132 #
133 if [ -e /var/ipfire/qos/enable ]; then
134 /usr/local/bin/qosctrl stop
135 /usr/local/bin/qosctrl generate
136 /usr/local/bin/qosctrl start
137 fi
138
139 #
140 # Modify grub.conf
141 #
142 echo
143 echo Update grub configuration ...
144 ROOT=`mount | grep " / " | cut -d" " -f1`
145
146 if [ ! -z $ROOT ]; then
147 ROOTUUID=`blkid -c /dev/null -sUUID $ROOT | cut -d'"' -f2`
148 fi
149
150 if [ ! -z $ROOTUUID ]; then
151 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
152 else
153 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
154 fi
155 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
156 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
157
158 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
159 echo "grub use default console ..."
160 else
161 echo "grub use serial console ..."
162 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
163 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
164 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
165 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" /boot/grub/grub.conf
166 fi
167 #
168 # Delete old lm-sensor modullist to force search at next boot
169 #
170 rm -rf /etc/sysconfig/lm_sensors
171
172 #
173 #Update Language cache
174 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
175
176 #
177 # Remove meta's of packages that are now common...
178 #
179 rm -rf /opt/pakfire/db/*/meta-fontconfig
180 rm -rf /opt/pakfire/db/*/meta-glib
181
182 #
183 # After pakfire has ended run it again and update the lists and do upgrade
184 #
185 echo '#!/bin/bash' > /tmp/pak_update
186 echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
187 echo ' sleep 1' >> /tmp/pak_update
188 echo 'done' >> /tmp/pak_update
189 echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
190 echo ' sleep 1' >> /tmp/pak_update
191 echo 'done' >> /tmp/pak_update
192 echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
193 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
194 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
195 echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
196 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-65 "Upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
197 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-65 "Check it before reboot !!!"' >> /tmp/pak_update
198 echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-65 " *** Please reboot... *** "' >> /tmp/pak_update
199 echo 'touch /var/run/need_reboot ' >> /tmp/pak_update
200 #
201 chmod +x /tmp/pak_update
202 /tmp/pak_update &
203
204 sync
205
206 #
207 #Finish
208 /etc/init.d/fireinfo start
209 sendprofile
210
211 echo
212 echo Please wait until pakfire has ended...
213 echo
214 #Don't report the exitcode last command
215 exit 0
216