Add uuid to swap partition at update.
[people/pmueller/ipfire-2.x.git] / config / rootfiles / core / test / 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) 2010 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 KVER="2.6.32.21"
28 MOUNT=`grep "kernel" /boot/grub/grub.conf | tail -n 1`
29 # Nur den letzten Parameter verwenden
30 echo $MOUNT > /dev/null
31 MOUNT=$_
32 if [ ! $MOUNT == "rw" ]; then
33 MOUNT="ro"
34 fi
35
36
37 #
38 # check if we the backup file already exist
39 if [ -e /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 ]; then
40 echo Moving backup to backup-old ...
41 mv -f /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
42 /var/ipfire/backup/core-upgrade_$KVER-old.tar.bz2
43 fi
44 echo First we made a backup of all files that was inside of the
45 echo update archive. This may take a while ...
46 # Add some files that are not in the package to backup
47 echo lib/modules >> /opt/pakfire/tmp/ROOTFILES
48 echo boot >> /opt/pakfire/tmp/ROOTFILES
49 echo etc/mkinitcpio.conf >> /opt/pakfire/tmp/ROOTFILES
50 echo etc/mkinitcpio.conf.org >> /opt/pakfire/tmp/ROOTFILES
51 echo etc/mkinitcpio.d >> /opt/pakfire/tmp/ROOTFILES
52 echo lib/initcpio >> /opt/pakfire/tmp/ROOTFILES
53 echo sbin/mkinitcpio >> /opt/pakfire/tmp/ROOTFILES
54
55 # Backup the files
56 tar cjvf /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
57 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' > /dev/null 2>&1
58
59 echo
60 echo Update Kernel to $KVER ...
61 # Remove old kernel, configs, initrd, modules ...
62 #
63 rm -rf /boot/System.map-*
64 rm -rf /boot/config-*
65 rm -rf /boot/ipfirerd-*
66 rm -rf /boot/vmlinuz-*
67 rm -rf /lib/modules/*-ipfire
68 # Remove mkinitcpio
69 rm -rf /etc/mkinitcpio.*
70 rm -rf /lib/initcpio
71 rm -rf /sbin/mkinitcpio
72 #
73 # Backup grub.conf
74 #
75 cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
76 #
77 # Unpack the updated files
78 #
79 echo
80 echo Unpack the updated files ...
81 #
82 tar xvf /opt/pakfire/tmp/files --preserve --numeric-owner -C / \
83 --no-overwrite-dir
84
85 #
86 # Stop services to save memory
87 #
88 /etc/init.d/snort stop
89 /etc/init.d/squid stop
90
91 # Convert /etc/fstab entries to UUID ...
92 #
93 echo Convert fstab entries to UUID ...
94 ROOT=`mount | grep " / " | cut -d" " -f1`
95 BOOT=`mount | grep " /boot " | cut -d" " -f1`
96 VAR=`mount | grep " /var " | cut -d" " -f1`
97 SWAP=`grep "/dev/" /proc/swaps | cut -d" " -f1`
98 #
99
100 if [ ! -z $ROOT ]; then
101 ROOTUUID=`blkid -sUUID $ROOT | cut -d'"' -f2`
102 if [ ! -z $ROOTUUID ]; then
103 sed -i "s|^$ROOT|UUID=$ROOTUUID|g" /etc/fstab
104 #else
105 #to do add uuid to rootfs
106 fi
107 else
108 echo "ERROR! / not found!!!"
109 fi
110
111 if [ ! -z $BOOT ]; then
112 BOOTUUID=`blkid -sUUID $BOOT | cut -d'"' -f2`
113 if [ ! -z $BOOTUUID ]; then
114 sed -i "s|^$BOOT|UUID=$BOOTUUID|g" /etc/fstab
115 #else
116 #to do add uuid to bootfs
117 fi
118 else
119 echo "WARNING! /boot not found!!!"
120 fi
121
122 if [ ! -z $VAR ]; then
123 VARUUID=`blkid -sUUID $VAR | cut -d'"' -f2`
124 if [ ! -z $VARUUID ]; then
125 sed -i "s|^$VAR|UUID=$VARUUID|g" /etc/fstab
126 #else
127 #to do add uuid to varfs
128 fi
129 else
130 echo "WARNING! /var not found!!!"
131 fi
132
133 if [ ! -z $SWAP ]; then
134 SWAPUUID=`blkid -sUUID $SWAP | cut -d'"' -f2`
135 if [ ! -z $SWAPUUID ]; then
136 sed -i "s|^$SWAP|UUID=$SWAPUUID|g" /etc/fstab
137 else
138 # Reformat swap to add a UUID
139 swapoff -a
140 mkswap $SWAP
141 swapon -a
142 SWAPUUID=`blkid -sUUID $SWAP | cut -d'"' -f2`
143 if [ ! -z $SWAPUUID ]; then
144 sed -i "s|^$SWAP|UUID=$SWAPUUID|g" /etc/fstab
145 fi
146 fi
147 else
148 echo "WARNING! swap not found!!!"
149 fi
150
151 #
152 # Start services
153 #
154 /etc/init.d/squid start
155 /etc/init.d/snort start
156
157 #
158 # Modify grub.conf
159 #
160 echo
161 echo Update grub configuration ...
162 if [ ! -z $ROOTUUID ]; then
163 sed -i "s|ROOT|UUID=$ROOTUUID|g" /boot/grub/grub.conf
164 else
165 sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
166 fi
167 sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
168 sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
169
170 if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
171 echo "grub use default console ..."
172 else
173 echo "grub use serial console ..."
174 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
175 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
176 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
177 sed -i -e "s| panic=10 | console=ttyS0,38400n8 panic=10 |g" /boot/grub/grub.conf
178 fi
179 #
180 # Change /dev/hd? to /dev/sda
181 #
182 if [ "${ROOT:0:7}" == "/dev/hd" ];then
183 sed -i -e "s|${ROOT:0:8}|/dev/sda|g" /boot/grub/grub.conf
184 sed -i -e "s|${ROOT:0:8}|/dev/sda|g" /etc/fstab
185 fi
186 #
187 # ReInstall grub
188 #
189 grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
190 #
191 # Rebuild Language
192 #
193 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
194 #
195 # Delete old lm-sensor modullist to force search at next boot
196 #
197 rm -rf /etc/sysconfig/lm_sensors
198 /usr/bin/logger -p syslog.emerg -t kernel "Upgrade finished. If you use a customized grub.cfg"
199 /usr/bin/logger -p syslog.emerg -t kernel "Check it before reboot !!!"
200 /usr/bin/logger -p syslog.emerg -t kernel " *** Please reboot... *** "