]> wimlib.net Git - wimlib/blobdiff - programs/mkwinpeimg.in
mkwinpeimg: Support writing ISO image to stdout
[wimlib] / programs / mkwinpeimg.in
index 5316efa8f79fa44ba31a047ca6c0c5b763588643..48ffebb3442dbf2346ada080ce44bdf482fc84ab 100755 (executable)
@@ -116,7 +116,7 @@ EOF
 }
 
 version() {
-       echo "$script_name (wimlib $WIMLIB_VERSION)"
+       echo "$script_name (distributed with wimlib $WIMLIB_VERSION)"
        exit 0
 }
 
@@ -256,7 +256,7 @@ EOF
 
 check_needed_programs() {
        if [ -z "$waik_dir" -o -n "$modify_wim" ]; then
-               if ! type -P @IMAGEX_PROGNAME@ &> /dev/null ; then
+               if ! type -P "$imagex" &> /dev/null ; then
                        cat << EOF
 ERROR: To make a customized image of Windows PE, we need the "$imagex" program
 from "wimlib" so that we can modify the boot.wim file.  However, "$imagex"
@@ -446,7 +446,7 @@ make_iso_img() {
 
        mkisofs -sysid ""  -A ""  -V "Microsoft Windows PE ($arch)"  -d -N \
                -b etfsboot.com  -no-emul-boot   -c boot.cat  -hide etfsboot.com  \
-               -hide boot.cat -quiet -o "$image" "$tmp_dir" || stat_fail
+               -hide boot.cat -quiet -o "$image" "$tmp_dir" 1>&4 || stat_fail
 
        stat_done
 }
@@ -473,11 +473,26 @@ make_disk_img() {
 
        export MTOOLSRC="$mtool_conf"
 
-       mformat -h 255 -s 63 -T $(( image_size / 512)) s:
-       mcopy -s "$tmp_dir"/* s:
+       mformat -h 255 -s 63 -T $(( image_size / 512)) s: || stat_fail
+       mcopy -s "$tmp_dir"/* s: || stat_fail
 
        syslinux --install "$image"
-       mcopy /usr/lib/syslinux/chain.c32 s:
+
+       syslinuxdir="/usr/lib/syslinux"
+
+       if [ -d "$syslinuxdir/bios" ]; then
+               biosdir="$syslinuxdir/bios"
+       else
+               biosdir="$syslinuxdir"
+       fi
+
+       mcopy "$biosdir/chain.c32" s: || stat_fail
+       if [ -e "$biosdir/libcom32.c32" ]; then
+               mcopy "$biosdir/libcom32.c32" s:
+       fi
+       if [ -e "$biosdir/libutil.c32" ]; then
+               mcopy "$biosdir/libutil.c32" s:
+       fi
        mcopy - 's:syslinux.cfg' <<- EOF
                DEFAULT winpe
                LABEL   winpe
@@ -491,6 +506,22 @@ make_disk_img() {
 calc_columns
 tmp_dir="$(mktemp -d)"
 process_command_line "$@"
+
+if [ "$image" = "-" ] ; then
+       # Writing image to standard output
+       if [ "$make" != iso ]; then
+               echo "ERROR: Writing image to standard output is only supported in --iso mode!"
+               exit 1
+       fi
+       # We can't print anything to standard output except the ISO image
+       # itself.  Play with the file descriptors.
+
+       exec 4>&1  # 4 is now the original standard output.
+       exec 1>&2  # Anything that goes to standard output now, by default,
+                  # actually goes to standard error.
+else
+       exec 4>&1  # 4 is now a copy of standard output
+fi
 if [ -z "$waik_dir" ]; then
        find_windows_dir
 fi
@@ -523,4 +554,6 @@ elif [ $make = disk ]; then
        make_disk_img "$image"
 fi
 
-echo "The image ($image) is $(stat -c %s "$image") bytes."
+if [ "$image" != "-" ]; then
+       echo "The image ($image) is $(stat -c %s "$image") bytes."
+fi