From: Victor Lowther Date: Sat, 15 Aug 2009 03:51:25 +0000 (-0500) Subject: Update dracut-catimages to make it much more robust in the face of X-Git-Tag: 001~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2790d5b2ed6993c01158e96aea24404cd40eb0c0;p=thirdparty%2Fdracut.git 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. --- diff --git a/dracut-catimages b/dracut-catimages index 66b03fe68..b19f20ae6 100755 --- a/dracut-catimages +++ b/dracut-catimages @@ -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"