#!/bin/bash --norc
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Copyright 2009 Red Hat, Inc. All rights reserved.
#
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
dwarning() {
- echo "Warning: $@" >&2
+ echo "Warning: $*" >&2
}
dinfo() {
}
derror() {
- echo "Error: $@" >&2
+ echo "Error: $*" >&2
}
usage() {
-# 80x25 linebreak here ^
+ # 80x25 linebreak here ^
cat << EOF
Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
Creates initial ramdisk image by concatenating several images from the command
EOF
}
-
imagedir=/boot/dracut/
overlay=/var/lib/dracut/overlay
while (($# > 0)); do
case $1 in
- -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;;
+ -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) export debug="yes" ;;
+ -v | --verbose) beverbose="yes" ;;
+ -*)
+ printf "\nUnknown option: %s\n\n" "$1" >&2
+ usage
+ exit 1
+ ;;
*) break ;;
esac
shift
done
-outfile=$1; shift
+outfile=$1
+shift
if [[ -z $outfile ]]; then
derror "No output file specified."
exit 1
fi
-baseimage=$1; shift
+baseimage=$1
+shift
if [[ -z $baseimage ]]; then
derror "No base image specified."
if [[ ! $no_overlay ]]; then
ofile="$imagedir/90-overlay.img"
dinfo "Creating image $ofile from directory $overlay"
- type pigz &>/dev/null && gzip=pigz || gzip=gzip
- ( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
+ type pigz &> /dev/null && gzip=pigz || gzip=gzip
+ (
+ cd "$overlay" || return 1
+ find . | cpio --quiet -H newc -o | $gzip -9 > "$ofile"
+ )
fi
if [[ ! $no_imagedir ]]; then
done
fi
-images+=($@)
+images+=("$@")
dinfo "Using base image $baseimage"
-cat "$baseimage" > "$outfile"
+cat -- "$baseimage" > "$outfile"
for i in "${images[@]}"; do
dinfo "Appending $i"
- cat "$i" >> "$outfile"
+ cat -- "$i" >> "$outfile"
done
dinfo "Created $outfile"