2009-07-24 15:14:52 +04:00
#!/bin/bash --norc
2010-09-10 17:23:06 +04:00
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
2009-07-24 15:14:52 +04:00
# Copyright 2009 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/>.
#
dwarning( ) {
echo " Warning: $@ " >& 2
}
dinfo( ) {
[ [ $beverbose ] ] && echo " $@ " >& 2
}
derror( ) {
echo " Error: $@ " >& 2
}
usage( ) {
# 80x25 linebreak here ^
2010-09-10 17:23:06 +04:00
cat << EOF
Usage: $0 [ OPTION] ... <initramfs> <base image> [ <image>...]
2009-07-24 15:14:52 +04:00
Creates initial ramdisk image by concatenating several images from the command
line and /boot/dracut/
-f, --force Overwrite existing initramfs file.
2011-05-10 13:39:10 +04:00
-i, --imagedir Directory with additional images to add
2009-07-24 15:14:52 +04:00
( default: /boot/dracut/)
-o, --overlaydir Overlay directory, which contains files that
will be used to create an additional image
--nooverlay Do not use the overlay directory
--noimagedir Do not use the additional image directory
-h, --help This message
--debug Output debug information of the build process
-v, --verbose Verbose output during the build process
2010-09-10 17:23:06 +04:00
EOF
2009-07-24 15:14:52 +04:00
}
imagedir = /boot/dracut/
overlay = /var/lib/dracut/overlay
while ( ( $# > 0) ) ; do
case $1 in
2010-09-10 17:23:06 +04:00
-f| --force) force = yes; ;
-i| --imagedir) imagedir = $2 ; shift; ;
-o| --overlaydir) overlay = $2 ; shift; ;
--nooverlay) no_overlay = yes; shift; ;
--noimagedir) no_imagedir = yes; shift; ;
-h| --help) usage; exit 1 ; ;
--debug) debug = "yes" ; ;
-v| --verbose) beverbose = "yes" ; ;
-*) printf "\nUnknown option: %s\n\n" " $1 " >& 2; usage; exit 1; ;
*) break ; ;
2009-07-24 15:14:52 +04:00
esac
shift
done
outfile = $1 ; shift
2009-08-15 07:51:25 +04:00
if [ [ -z $outfile ] ] ; then
2009-07-24 15:14:52 +04:00
derror "No output file specified."
usage
exit 1
fi
baseimage = $1 ; shift
2009-08-15 07:51:25 +04:00
if [ [ -z $baseimage ] ] ; then
2009-07-24 15:14:52 +04:00
derror "No base image specified."
usage
exit 1
fi
2009-08-15 07:51:25 +04:00
if [ [ -f $outfile && ! $force ] ] ; then
2009-07-24 15:14:52 +04:00
derror " Will not override existing initramfs ( $outfile ) without --force "
exit 1
fi
2009-08-15 07:51:25 +04:00
if [ [ ! $no_imagedir && ! -d $imagedir ] ] ; then
2009-07-24 15:14:52 +04:00
derror " Image directory $overlay is not a directory "
exit 1
fi
2009-08-15 07:51:25 +04:00
if [ [ ! $no_overlay && ! -d $overlay ] ] ; then
2009-07-24 15:14:52 +04:00
derror " Overlay $overlay is not a directory "
exit 1
fi
2009-08-15 07:51:25 +04:00
if [ [ ! $no_overlay ] ] ; then
2009-07-24 15:14:52 +04:00
ofile = " $imagedir /90-overlay.img "
dinfo " Creating image $ofile from directory $overlay "
2010-03-18 22:41:22 +03:00
type pigz & >/dev/null && gzip = pigz || gzip = gzip
( cd " $overlay " ; find . | cpio --quiet -H newc -o | $gzip -9 > " $ofile " ; )
2009-07-24 15:14:52 +04:00
fi
2009-08-15 07:51:25 +04:00
if [ [ ! $no_imagedir ] ] ; then
for i in " $imagedir / " *.img; do
2010-09-10 17:23:06 +04:00
[ [ -f $i ] ] && images += ( " $i " )
2009-08-15 07:51:25 +04:00
done
2009-07-24 15:14:52 +04:00
fi
2009-08-15 07:51:25 +04:00
images += ( $@ )
2009-07-24 15:14:52 +04:00
dinfo " Using base image $baseimage "
2009-08-15 07:51:25 +04:00
cat " $baseimage " > " $outfile "
2009-07-24 15:14:52 +04:00
2011-05-10 13:39:10 +04:00
for i in " ${ images [@] } " ; do
2009-07-24 15:14:52 +04:00
dinfo " Appending $i "
2009-08-15 07:51:25 +04:00
cat " $i " >> " $outfile "
2009-07-24 15:14:52 +04:00
done
dinfo " Created $outfile "
exit 0