Update dracut-catimages to make it much more robust in the face of

image filenames with spaces, carriage returns, and other such nasty
characters in them.  Bash arrays are very useful for these sorts of things.
master
Victor Lowther 2009-08-14 22:51:25 -05:00
parent 98adb06ea3
commit 2790d5b2ed
1 changed files with 14 additions and 12 deletions

View File

@ -70,7 +70,7 @@ done

outfile=$1; shift

if [ -z "$outfile" ]; then
if [[ -z $outfile ]]; then
derror "No output file specified."
usage
exit 1
@ -78,45 +78,47 @@ fi

baseimage=$1; shift

if [ -z "$baseimage" ]; then
if [[ -z $baseimage ]]; then
derror "No base image specified."
usage
exit 1
fi

if [ -f $outfile -a -z "$force" ]; then
if [[ -f $outfile && ! $force ]]; then
derror "Will not override existing initramfs ($outfile) without --force"
exit 1
fi

if [ -z "$no_imagedir" -a ! -d "$imagedir" ]; then
if [[ ! $no_imagedir && ! -d $imagedir ]]; then
derror "Image directory $overlay is not a directory"
exit 1
fi

if [ -z "$no_overlay" -a ! -d "$overlay" ]; then
if [[ ! $no_overlay && ! -d $overlay ]]; then
derror "Overlay $overlay is not a directory"
exit 1
fi

if [ -z "$no_overlay" ]; then
if [[ ! $no_overlay ]]; then
ofile="$imagedir/90-overlay.img"
dinfo "Creating image $ofile from directory $overlay"
( cd "$overlay"; find . |cpio --quiet -H newc -o |gzip -9 > "$ofile"; )
fi

if [ -z "$no_imagedir" ]; then
images=$(for i in $imagedir/*.img;do [ -f $i ] || continue; echo $i; done)
if [[ ! $no_imagedir ]]; then
for i in "$imagedir/"*.img; do
[[ -f $i ]] && images+=("$i")
done
fi

images="$images $@"
images+=($@)

dinfo "Using base image $baseimage"
cat $baseimage > $outfile
cat "$baseimage" > "$outfile"

for i in $images; do
for i in "${images[@]}"; do
dinfo "Appending $i"
cat $i >> $outfile
cat "$i" >> "$outfile"
done

dinfo "Created $outfile"