From c6f20655db80a20687caa3747d4f515d06889eaf Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Tue, 8 Oct 2013 13:35:10 -0700 Subject: [PATCH] fix(qemu_template): Fix getopts usage in qemu wrapper script. Previously shifts were added into the getopts loop to work around differences between different sh implementations but that causes getopts to end the loop early. Instead use an intermediate variable to work around inconsistent OPTIND behavior and explicitly check for the -- separator. Tested in bash, dash, and ash. --- build_library/qemu_template.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/build_library/qemu_template.sh b/build_library/qemu_template.sh index a1d25b01f4..b04917a99c 100755 --- a/build_library/qemu_template.sh +++ b/build_library/qemu_template.sh @@ -25,17 +25,22 @@ Any arguments after -a and -p will be passed through to qemu, -- may be used as an explicit separator. See the qemu(1) man page for more details. " +script_args=1 while getopts ":a:p:vh" OPTION do case $OPTION in - a) SSH_KEYS="$OPTARG"; shift 2 ;; - p) SSH_PORT="$OPTARG"; shift 2 ;; - v) set -x; shift ;; + a) SSH_KEYS="$OPTARG" ;; + p) SSH_PORT="$OPTARG" ;; + v) set -x ;; h) echo "$USAGE"; exit ;; ?) break ;; esac + script_args=$OPTIND done +shift $((script_args - 1)) +[ "$1" == "--" ] && shift + METADATA=$(mktemp -t -d coreos-meta-data.XXXXXXXXXX) if [ $? -ne 0 ] || [ ! -d "$METADATA" ]; then