summaryrefslogtreecommitdiffstats
path: root/scripts/upd-kernel
blob: af01656f8904a55eda008620ea73926c1f656d73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# take a boot directory with kernel + initrd and create a new one
# with a new kernel + initrd
# Usage: ./upd-kernel <olddir> <newdir> <newkernelrpm>
#
# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

OLDDIR=`readlink -f $1`
NEWDIR=$2
KRPM=`readlink -f $3`
KNAME=$(rpm -qp --qf "%{NAME}" $KRPM)
if [ "$KNAME" != "kernel" ]; then
    var=$(echo $KNAME | sed -e 's/kernel-//')
fi

ARCH=$(rpm -qp --qf "%{ARCH}" $KRPM)
NEWVER=$(rpm -qp --qf "%{VERSION}-%{RELEASE}" $KRPM)$var


if [ -z "$OLDDIR" -o -z "$NEWDIR" -o -z "$KRPM" ]; then
  echo "Usage: $0 <olddir> <newdir> <newkernelrpm>"
  exit 1
fi

if [ ! -d $OLDDIR ]; then
  echo "Directory $OLDDIR doesn't exist"
  exit 1
fi

if [ -f $NEWDIR ]; then
    NEWDIR=`readlink -f $NEWDIR`
else
    NEWDIR=`readlink -f .`/$NEWDIR
    mkdir $NEWDIR
fi

WORKDIR=$(/bin/mktemp -d /tmp/kernrpm.XXXXXX)

pushd $WORKDIR

# explode the rpm
mkdir rpm
pushd rpm
rpm2cpio $KRPM |cpio -id
popd

# explode the rpm
mkdir initrd
pushd initrd
zcat $OLDDIR/initrd.img |cpio -id
popd

mkdir initrd/modules/mods
# explode the moduleball
pushd initrd/modules/mods
zcat ../modules.cgz |cpio -id
popd

mkdir -p newmods/$NEWVER/$ARCH
for i in $(find initrd/modules/mods -type f -name '*.ko' -exec basename {} \;); do find $WORKDIR/rpm/lib/modules/*/ -name $i -exec cp -v {} $WORKDIR/newmods/$NEWVER/$ARCH \; ; done
rm -rf initrd/modules/mods

pushd newmods
find . |cpio --quiet -H crc -o |gzip -9 > $WORKDIR/initrd/modules/modules.cgz
popd

pushd initrd
find . |cpio -c -o |gzip -9 > $NEWDIR/initrd.img
popd

cp -v $WORKDIR/rpm/boot/vmlinuz-* $NEWDIR/vmlinuz
popd
rm -rf $WORKDIR