summaryrefslogtreecommitdiffstats
path: root/scripts/mk-images
blob: 2f6ef0dde69ec14b83c9cf03bf23403f3d67e1ff (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#!/bin/bash
#
# mk-images
#
# 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/>.
#

LANG=C

PATH=$PATH:/sbin:/usr/sbin
IMAGEUUID=$(date +%Y%m%d%H%M).$(uname -i)
TMPDIR=${TMPDIR:-/tmp}

usage () {
    echo "usage: mk-images <pkgsrc> <toplevel> <template> <imgdir> <buildarch> <productname> <version>"
    exit 0
}

DEBUG=""
BUILDARCH=`uname -m`
BOOTISO="boot.iso"
ISBETA="false"

while [ $# -gt 0 ]; do
    case $1 in
        --debug)
            DEBUG="--debug"
            shift
        ;;
        --noiso)
            BOOTISO=""
            shift
        ;;
        --isbeta)
            ISBETA="true"
            shift
        ;;
        --arch)
            BUILDARCH=$2
            shift; shift
        ;;
        --imgdir)
            IMGPATH=$2
            shift; shift
        ;;
        --product)
            PRODUCT=$2
            shift; shift
        ;;
        --version)
            VERSION=$2
            shift; shift
        ;;
        --bugurl)
            BUGURL=$2
            shift; shift
        ;;
        --output)
            TOPDESTPATH=$2
            shift; shift
        ;;
        --nogr)
            echo "*** DeprecationWarning: ignoring --nogr option." >&2
            shift
        ;;
        --mindir)
            echo "*** DeprecationWarning: ignoring --mindir option." >&2
            shift; shift
        ;;
        --stg2dir)
            echo "*** DeprecationWarning: please use --imgdir instead of --stg2dir." >&2
            shift; shift
        ;;
        *)
            yumconf=$1
            shift
        ;;
    esac
done

if [ -z "$TOPDESTPATH" -o -z "$IMGPATH" -o -z "$PRODUCT" -o -z "$VERSION" ]; then usage; fi

TOPDIR=$(echo $0 | sed "s,/[^/]*$,,")
if [ $TOPDIR = $0 ]; then
    $TOPDIR="."
fi
TOPDIR=$(cd $TOPDIR; pwd)

# modules that are needed.  this is the generic "needed for every arch" stuff
COMMONMODS="fat vfat nfs sunrpc lockd floppy cramfs loop edd pcspkr squashfs ipv6 8021q virtio_pci netconsole"
UMSMODS="ums-jumpshot ums-datafab ums-freecom ums-usbat ums-sddr55 ums-onetouch ums-alauda ums-karma ums-sddr09 ums-cypress"
USBMODS="$UMSMODS ohci-hcd uhci-hcd ehci-hcd usbhid mousedev usb-storage sd_mod sr_mod ub appletouch bcm5974"
FIREWIREMODS="ohci1394 sbp2 fw-ohci fw-sbp2 firewire-sbp2 firewire-ohci"
SDMODS="mmc-block sdhci sdhci-pci"
IDEMODS="ide-cd ide-cd_mod"
SCSIMODS="sr_mod sg st sd_mod scsi_mod iscsi_tcp iscsi_ibft scsi_wait_scan"
FSMODS="fat msdos vfat ext2 ext3 ext4 reiserfs jfs xfs gfs2 cifs fuse btrfs hfsplus"
LVMMODS="dm-mod dm-zero dm-snapshot dm-mirror dm-multipath dm-round-robin dm-crypt"
RAIDMODS="raid0 raid1 raid5 raid6 raid456 raid10 linear"
CRYPTOMODS="sha256_generic cbc xts lrw aes_generic crypto_blkcipher crc32c ecb arc4"
PCMCIASOCKMODS="yenta_socket i82365 tcic pcmcia"
INITRDMODS="$USBMODS $FIREWIREMODS $IDEMODS $SCSIMODS $FSMODS $LVMMODS $RAIDMODS $CRYPTOMODS $COMMONMODS $PCMCIASOCKMODS $SDMODS =scsi =net =drm"

. $(dirname $0)/buildinstall.functions

# Set, verify, and create paths
IMAGEPATH=$TOPDESTPATH/images
FULLMODPATH=$TMPDIR/instimagemods.$$
FINALFULLMODPATH=$IMGPATH/modules
INSTIMGPATH=$TOPDESTPATH/images
KERNELBASE=$TMPDIR/updboot.kernel.$$

KERNELNAME=vmlinuz
if [ "$BUILDARCH" = "ia64" ]; then
    KERNELDIR="/boot/efi/EFI/redhat"
else
    KERNELDIR="/boot"
fi

if [ "$BUILDARCH" = "sparc64" ]; then
    BASEARCH=sparc
elif [ "$BUILDARCH" = "ppc64" ]; then
    BASEARCH=ppc
else
    BASEARCH=$BUILDARCH
fi

# explicit block size setting for some arches (FIXME: we compose
# ppc64-ish trees as ppc, so we have to set the "wrong" block size)
if [ "$BUILDARCH" = "sparc64" ]; then
    CRAMBS="--blocksize 8192"
elif [ "$BUILDARCH" = "sparc" ]; then
    CRAMBS="--blocksize 4096"
else
    CRAMBS=""
fi

if [ "$BUILDARCH" = "x86_64" -o "$BUILDARCH" = "s390x" -o "$BUILDARCH" = "ppc64" ]; then
    LIBDIR=lib64
else
    LIBDIR=lib
fi

rm -rf $IMAGEPATH
rm -rf $FULLMODPATH
rm -rf $FINALFULLMODPATH
rm -rf $KERNELBASE
mkdir -p $IMAGEPATH
mkdir -p $FULLMODPATH
mkdir -p $FINALFULLMODPATH
mkdir -p $KERNELBASE
mkdir -p $INSTIMGPATH

# Stuff that we need
TRIMPCIIDS=$IMGPATH/usr/libexec/anaconda/trimpciids
GETKEYMAPS=$IMGPATH/usr/libexec/anaconda/getkeymaps
LIBEXECBINDIR=$IMGPATH/usr/libexec/anaconda
ADDRSIZE=$IMGPATH/usr/$LIBDIR/anaconda/addrsize
MKS390CDBOOT=$IMGPATH/usr/$LIBDIR/anaconda/mk-s390-cdboot
GENMODINFO=$IMGPATH/usr/libexec/anaconda/genmodinfo
SCREENFONT=$IMGPATH/usr/share/anaconda/screenfont-${BASEARCH}.gz
MODLIST=$IMGPATH/usr/libexec/anaconda/modlist
MODINFO=$TMPDIR/modinfo-$BUILDARCH.$$
LOADERBINDIR=$IMGPATH/usr/$LIBDIR/anaconda
BOOTDISKDIR=$IMGPATH/usr/share/anaconda/boot
LANGTABLE=$IMGPATH/usr/share/anaconda/lang-table
PCIIDS=$IMGPATH/usr/share/hwdata/pci.ids
XDRIVERS=$IMGPATH/usr/share/hwdata/videoaliases
XDRIVERDESCS=$IMGPATH/usr/share/hwdata/videodrivers

REQUIREMENTS="$TRIMPCIIDS $PCIIDS $XDRIVERDESCS $GENMODINFO
      $LANGTABLE $GETKEYMAPS"

dieLater=
for n in $REQUIREMENTS; do
    if [ ! -f $n ]; then
        echo "$n doesn't exist"
        dieLater=1
    fi
done

for n in $BOOTDISKDIR; do
    if [ ! -d $n ]; then
        echo "$n doesn't exist"
        dieLater=1
    fi
done

if [ -n "$dieLater" ]; then exit 1; fi

if [ "$BUILDARCH" != "s390" -a "$BUILDARCH" != "s390x" ]; then
    # go ahead and create the keymaps so we only have to do it once
    if [ -f $IMGPATH/usr/share/anaconda/keymaps-override-$BASEARCH ]; then
        echo "Found keymap override, using it"
        cp $IMGPATH/usr/share/anaconda/keymaps-override-$BASEARCH $IMGPATH/etc/keymaps.gz
    else
        echo "Running: $GETKEYMAPS $BUILDARCH $KEYMAPS $IMGPATH"
        $GETKEYMAPS $BUILDARCH $IMGPATH/etc/keymaps.gz $IMGPATH
        if [ $? != 0 ]; then
            echo "Unable to create keymaps and thus can't create initrd."
            exit 1
        fi
    fi
fi

findPackage() {
    name=$1

    pkg=$(repoquery --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}" -c $yumconf --archlist=$KERNELARCH $name.$KERNELARCH)
    if [ -n "$pkg" ]; then
        echo $pkg
        return
    fi
    echo "cannot find package $name" >&2
}

rundepmod () {
    where=$1

    $FAKEARCH /sbin/depmod -a -F $KERNELROOT/boot/System.map-$version \
            -b $where $version
}

# This loops to make sure it resolves dependencies of dependencies of...
resdeps () {
    items="$*"

    deplist=""
    for item in $items ; do
        deps=$(awk -F ':' "/$item.ko: / { print gensub(\".*/$item.ko: \",\"\",\"g\") }" $KERNELROOT/lib/modules/$version/modules.dep)
        for dep in $deps ; do
            depfile=${dep##*/}
            depname=${dep%%.ko}
            deplist="$deplist $depname"
        done
    done
    items=$(for n in $items $deplist; do echo $n; done | sort -u)
    echo $items
}

expandModuleSet() {
    SET=""
    for name in $1; do
        char=$(echo $name | cut -c1)
        if [ $char = '=' ]; then
	    NAME=$(echo $name | cut -c2-)
	    if [ "$NAME" = "ata" ]; then
		SET="$SET $(egrep '(ata|ahci)' $KERNELROOT/lib/modules/$version/modules.block |sed -e 's/.ko//')"
	    elif [ "$NAME" = "scsi" ]; then
		SET="$SET $(sed -e 's/.ko//' $KERNELROOT/lib/modules/$version/modules.block)"
	    elif [ "$NAME" = "net" ]; then
		SET="$SET $(sed -e 's/.ko//' $KERNELROOT/lib/modules/$version/modules.networking)"
	    else
                # Ignore if group list does not exist
                if [ -e $KERNELROOT/lib/modules/$version/modules.$NAME ]; then
		    SET="$SET $(sed -e 's/.ko//' $KERNELROOT/lib/modules/$version/modules.$NAME)"
                fi
            fi
        else
            SET="$SET $name"
        fi
    done

    echo $SET
}

makemoduletree() {
    MMB_DIR=$1
    MMB_MODULESET=$(resdeps $2)

    mkdir -p $MMB_DIR/lib
    mkdir -p $MMB_DIR/modules
    mkdir -p $MMB_DIR/firmware
    ln -snf ../modules $MMB_DIR/lib/modules
    ln -snf ../firmware $MMB_DIR/lib/firmware

    echo "Copying kernel modules..."
    cp -a $KERNELROOT/lib/modules/* $MMB_DIR/lib/modules/
    echo "Removing extraneous modules..."
    find $MMB_DIR/lib/modules/ -name *.ko | while read module ; do
        m=${module##*/}
        modname=${m%%.ko}
        echo $MMB_MODULESET | grep -wq $modname || {
            rm -f $module
        }
    done

    echo "Copying required firmware..."
    find $MMB_DIR/lib/modules/ -name *.ko | while read module ; do
        for fw in $(modinfo -F firmware $module); do
            dest=$MBD_DIR/firmware/$fw
            destdir=$(dirname $dest)

            # Some firmware files are expected to be in their own directories.
            if [ ! -d $destdir ]; then
                mkdir -p $destdir
            fi

            cp $KERNELROOT/lib/firmware/$fw $dest
        done
    done

    # Copy in driver firmware we know we'll want during installation. This is
    # required for modules which still don't (or can't) export information
    # about what firmware files they require.
    for module in $MODSET ; do
        case $module in
            ipw2100)
                cp $KERNELROOT/lib/firmware/ipw2100* $MBD_DIR/firmware
            ;;
            ipw2200)
                cp $KERNELROOT/lib/firmware/ipw2200* $MBD_DIR/firmware
            ;;
            iwl3945)
                cp $KERNELROOT/lib/firmware/iwlwifi-3945* $MBD_DIR/firmware
            ;;
            atmel)
                cp $KERNELROOT/lib/firmware/atmel_*.bin $MBD_DIR/firmware
            ;;
            zd1211rw)
                cp -r $KERNELROOT/lib/firmware/zd1211 $MBD_DIR/firmware
            ;;
        esac
    done

    # create depmod.conf to support DDs
    mkdir -p $MMB_DIR/etc/depmod.d
    cat > $MMB_DIR/etc/depmod.d/dd.conf << EOF
search updates built-in
EOF

    # clean up leftover cruft
    find -H $MMB_DIR/lib/modules -type d -exec rmdir -f {} \; 2>/dev/null
    $MODLIST --modinfo-file $MODINFO --ignore-missing --modinfo \
    $MMB_MODULESET > $MMB_DIR/lib/modules/module-info
    # compress modules
    find -H $MMB_DIR/lib/modules -type f -name *.ko -exec gzip -9 {} \;
    rundepmod $MMB_DIR
    rm -f $MMB_DIR/lib/modules/*/modules.*map
    rm -f $MMB_DIR/lib/modules/*/{build,source}

    # create the pci.ids, from modules.alias and the X driver aliases
    awk '!/^(\t\t|#)/ { print ;if ($0 == "ffff  Illegal Vendor ID") nextfile; }' < $PCIIDS | \
        $TRIMPCIIDS $MMB_DIR/lib/modules/*/modules.alias $XDRIVERS/* > ../pci.ids
}


makeproductfile() {
    root=$1

    rm -f $root/.buildstamp
    cat > $root/.buildstamp << EOF
[Main]
BugURL=$BUGURL
IsBeta=$ISBETA
Product=$PRODUCT
UUID=$IMAGEUUID
Version=$VERSION
EOF
}

makeinitrd() {
    INITRDMODULES=""
    KEEP=""
    OUTFILE=""

    while [ x$(echo $1 | cut -c1-2) = x"--" ]; do
        if [ $1 = "--dest" ]; then
            OUTFILE=$2
            shift; shift
            continue
        elif [ $1 = "--keep" ]; then
            KEEP=yes
            shift
            continue
        elif [ $1 = "--modules" ]; then
            INITRDMODULES=$2
            shift; shift
            continue
        fi
        echo "Unknown option passed to makeinitrd"
        exit 1
    done

    if [ -z "$INITRDMODULES" ]; then
        echo "warning: no loader modules specified!" >&2
    fi

    MBD_FSIMAGE=$TMPDIR/makebootdisk.initrdimage.$$
    MBD_BOOTTREE=$TMPDIR/makebootdisk.tree.$$

    if [ -n "$INITRDMODULES" ]; then
        MODSET=`expandModuleSet "$INITRDMODULES"`
        makemoduletree $IMGPATH "$MODSET"
    fi

    makeproductfile $IMGPATH

    rm -f $MBD_FSIMAGE
    (cd $IMGPATH; find . |cpio --quiet -c -o) |gzip -9 > $MBD_FSIMAGE

    size=$(du $MBD_FSIMAGE | awk '{ print $1 }')

    echo "Wrote $MBD_FSIMAGE (${size}k compressed)"

    if [ -n "$OUTFILE" ]; then
        mkdir -p `dirname $OUTFILE`
        cp -a $MBD_FSIMAGE $OUTFILE
    fi

    if [ -z "$KEEP" ]; then
        rm -rf $MBD_FSIMAGE $MBD_BOOTTREE
    fi
}

makemainimage () {
    imagename=$1
    type=$2
    mmi_tmpimage=$TMPDIR/instimage.img.$$
    mmi_mntpoint=$TMPDIR/instimage.mnt.$$

    rm -rf $mmi_tmpimage $mmi_mntpoint
    mkdir $mmi_mntpoint

    if [ $type = "ext2" ]; then
        SIZE=$(du -sk $IMGPATH | awk '{ print int($1 * 1.1) }')
        if [ -d $IMGPATH/usr/share/anaconda]; then
            ERROR=$(du -sk $IMGPATH/usr/share/anaconda | awk '{ print $1 }')
            SIZE=$(expr $SIZE - $ERROR)
        fi
        if [ -d $IMGPATH/usr/share/syslinux ]; then
            ERROR=$(du -sk $IMGPATH/usr/share/syslinux | awk '{ print $1 }')
            SIZE=$(expr $SIZE - $ERROR)
        fi
        dd if=/dev/zero bs=1k count=${SIZE} of=$mmi_tmpimage 2>/dev/null
        mke2fs -q -F $mmi_tmpimage > /dev/null
        tune2fs -c0 -i0 $mmi_tmpimage >/dev/null
        mount -o loop $mmi_tmpimage $mmi_mntpoint

        (cd $IMGPATH; find . |
            fgrep -v "./usr/share/anaconda" |
            fgrep -v "./usr/share/syslinux"
            cpio -H crc -o) | (cd $mmi_mntpoint; cpio -iumd)
        makeproductfile $mmi_mntpoint
        umount $mmi_mntpoint
        rmdir $mmi_mntpoint
    elif [ $type = "squashfs" ]; then
        makeproductfile $IMGPATH
        echo "Running mksquashfs $IMGPATH $mmi_tmpimage -no-fragments -no-progress"
        mksquashfs $IMGPATH $mmi_tmpimage -no-fragments -no-progress
        chmod 0644 $mmi_tmpimage
        SIZE=$(expr `cat $mmi_tmpimage | wc -c` / 1024)
    elif [ $type = "cramfs" ]; then
        makeproductfile $IMGPATH
        echo "Running mkcramfs $CRAMBS $IMGPATH $mmi_tmpimage"
        mkfs.cramfs $CRAMBS $IMGPATH $mmi_tmpimage
        SIZE=$(expr `cat $mmi_tmpimage | wc -c` / 1024)
    fi

    cp $mmi_tmpimage $INSTIMGPATH/${imagename}.img
    chmod 644 $INSTIMGPATH/${imagename}.img

    echo "Wrote $INSTIMGPATH/${imagename}.img (${SIZE}k)"
    relpath=${INSTIMGPATH#$TOPDESTPATH/}
    echo "mainimage = ${relpath}/${imagename}.img" >> $TOPDESTPATH/.treeinfo

    rm $mmi_tmpimage
}

makeSecondStage() {
    echo "[stage2]" >> $TOPDESTPATH/.treeinfo
    echo "Building install.img"
    makemainimage "install" "squashfs"
    [ $? = 0 ] || exit 1
}

doPostImages() {
   /bin/true
}

# this gets overloaded if we're on an EFI-capable arch (... with grub)
makeEfiImages()
{
    echo "Not on an EFI capable machine; skipping EFI images."
    /bin/true
}

# source the architecture specific mk-images file so we can call functions
# in it
if [ ${BUILDARCH} = s390x ]; then
    # FIXME: this is a bad hack for s390, but better than copying for now
    source $TOPDIR/mk-images.s390
elif [ ${BUILDARCH} = ppc64 ]; then
    # ... and similar for ppc64
    source $TOPDIR/mk-images.ppc
elif [ ${BUILDARCH} = "x86_64" -o ${BUILDARCH} = "i386" ]; then
    source $TOPDIR/mk-images.x86
    source $TOPDIR/mk-images.efi
elif [ ${BUILDARCH} = "sparc64" -o ${BUILDARCH} = "sparcv9" ]; then
    source $TOPDIR/mk-images.sparc
else
    source $TOPDIR/mk-images.${BUILDARCH}
fi

# Find the kernel, unpack it, and verify it
kerneltags="kernel"
efiarch=""
arches="$BUILDARCH"
if [ "$BUILDARCH" = "ppc" ]; then
    arches="ppc64 ppc"
elif [ "$BUILDARCH" = "i386" ]; then
    arches="i586"
    efiarch="ia32"
    kerneltags="kernel kernel-PAE"
    kernelxen="kernel-PAE"
elif [ "$BUILDARCH" = "x86_64" ]; then
    kerneltags="kernel"
    efiarch="x64"
elif [ "$BUILDARCH" = "ia64" ]; then
    kerneltags="kernel"
    efiarch="ia64"
elif [ "$BUILDARCH" = "sparc" -o "$BUILDARCH" = "sparcv9" -o "$BUILDARCH" = "sparc64" ]; then
    arches="sparc64"
fi

foundakernel=""
for KERNELARCH in $arches; do
    for kernelvers in $kerneltags; do
        kpackage=$(findPackage $kernelvers)
        if [ "$KERNELARCH" = "i586" -a -z "$kpackage" ]; then
            echo "No i586 kernel, trying i686..."
            KERNELARCH="i686"
            kpackage=$(findPackage $kernelvers)
        fi

        if [ -z "$kpackage" ]; then
            echo "Unable to find kernel package $kernelvers"
            continue
        fi

        yumdownloader -c $yumconf --archlist=$KERNELARCH $kpackage
        kpackage="$kpackage.rpm"
        if [ ! -f "$kpackage" ]; then
            echo "kernel ($kernelvers) doesn't exist for $KERNELARCH.  skipping"
            continue
        fi

        KERNELROOT=$KERNELBASE/$KERNELARCH
        mkdir -p $KERNELROOT

        foundakernel="yes"

        if [ "$BUILDARCH" = "ia64" ]; then
            vmlinuz=$(rpm --nodigest --nosignature -qpl $kpackage |grep ^/boot/efi/EFI/redhat/vmlinuz | head -n 1)
            version=${vmlinuz##/boot/efi/EFI/redhat/vmlinuz-}
        else
            vmlinuz=$(rpm --nodigest --nosignature -qpl $kpackage |grep ^/boot/vmlinuz | head -n 1)
            version=${vmlinuz##/boot/vmlinuz-}
        fi
        arch=$(rpm --nodigest --nosignature --qf '%{ARCH}\n' -qp $kpackage)

        rpm2cpio $kpackage | (cd $KERNELROOT; cpio --quiet -iumd)
        rm -f $kpackage
        # expand out any available firmware too
        for p in $(repoquery -c $yumconf '*firmware*') ; do
            yumdownloader -c $yumconf $p
            rpm2cpio *firmware*.rpm | (cd $KERNELROOT; cpio --quiet -iumd)
            rm -f *firmware*.rpm
        done

        if [ ! -d "$KERNELROOT/lib/modules/$version" ]; then
            echo "$KERNELROOT/lib/modules/$version is not a valid modules directory" 2>&1
            exit 1
        fi

        if [ ! -f "$KERNELROOT/$KERNELDIR/${KERNELNAME}-$version" ]; then
            echo "$KERNELROOT/$KERNELDIR/${KERNELNAME}-$version does not exist"
            exit 1
        fi

        allmods=$(find $KERNELROOT/lib/modules/$version -name *.ko)

        rundepmod $KERNELROOT
        $GENMODINFO $KERNELROOT/lib/modules/$version > $MODINFO

        # make the boot images
        makeBootImages

        makeEfiImages $yumconf
    done
done

if [ -n "$foundakernel" ]; then
    makeSecondStage
    rm -rf $KERNELBASE
fi

doPostImages

cd $TOPDIR