fix(qemu_template): Replace getopts with simple pattern matching.

The use of getopts was leading to conflicts between this script's short
options and qemu's long options. For example -serial was getting
interpreted as -s -- erial which is not very helpful.
This commit is contained in:
Michael Marineau 2014-04-03 19:03:11 -07:00
parent c50e68f9d3
commit 0d0c7c7578

View File

@ -11,6 +11,7 @@ VM_CDROM=
VM_NCPUS="`grep -c ^processor /proc/cpuinfo`" VM_NCPUS="`grep -c ^processor /proc/cpuinfo`"
SSH_PORT=2222 SSH_PORT=2222
SSH_KEYS="" SSH_KEYS=""
SAFE_ARGS=0
USAGE="Usage: $0 [-a authorized_keys] [--] [qemu options...] USAGE="Usage: $0 [-a authorized_keys] [--] [qemu options...]
Options: Options:
-a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub] -a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub]
@ -29,24 +30,31 @@ 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. used as an explicit separator. See the qemu(1) man page for more details.
" "
safe_args=0 while [ $# -ge 1 ]; do
script_args=1 case "$1" in
while getopts ":a:p:svh" OPTION -a|-authorized-keys)
do SSH_KEYS="$2"
case $OPTION in shift 2 ;;
a) SSH_KEYS="$OPTARG" ;; -p|-ssh-port)
p) SSH_PORT="$OPTARG" ;; SSH_PORT="$2"
s) safe_args=1 ;; shift 2 ;;
v) set -x ;; -s|-safe)
h) echo "$USAGE"; exit ;; SAFE_ARGS=1
?) break ;; shift ;;
-v|-verbose)
set -x
shift ;;
-h|-help|--help)
echo "$USAGE"
exit ;;
--)
shift
break ;;
*)
break ;;
esac esac
script_args=$OPTIND
done done
shift $((script_args - 1))
[ "$1" = "--" ] && shift
METADATA=$(mktemp -t -d coreos-meta-data.XXXXXXXXXX) METADATA=$(mktemp -t -d coreos-meta-data.XXXXXXXXXX)
if [ $? -ne 0 ] || [ ! -d "$METADATA" ]; then if [ $? -ne 0 ] || [ ! -d "$METADATA" ]; then
@ -79,7 +87,7 @@ else
fi fi
# Start assembling our default command line arguments # Start assembling our default command line arguments
if [ "${safe_args}" -eq 1 ]; then if [ "${SAFE_ARGS}" -eq 1 ]; then
disk_type="ide" disk_type="ide"
else else
disk_type="virtio" disk_type="virtio"