Commit 425b35e9 authored by Paul John King's avatar Paul John King

Fixed OPTIND bug and tidied up --

The shell initialises global variable OPTIND to 1 on start up. In order to use
getopts in functions, OPTIND must be reinitialised before calling getopts. In
bash, it suffices to make OPTIND local, but in busybox, OPTIND must also be set
to 1.

I also fixed a few formatting slips.
parent 9eb10d67
......@@ -79,7 +79,7 @@ create_pool(){
</pool>
__END_OF_STDIN__
}
} ;
destroy_pool(){
......@@ -95,7 +95,7 @@ destroy_pool(){
virsh -q pool-destroy "${_NAME}" &&
virsh -q pool-undefine "${_NAME}" ;
}
} ;
print_volume_usage_message(){
......@@ -146,7 +146,7 @@ create_volume(){
</volume>
__END_OF_STDIN__
}
} ;
destroy_volume(){
......@@ -162,7 +162,7 @@ destroy_volume(){
virsh -q vol-delete "${_NAME}" --pool "${_POOL}" ;
}
} ;
print_domain_usage_message(){
......@@ -189,21 +189,21 @@ print_domain_usage_message(){
create_domain(){
local OPTIND ;
local _mac_address="" ;
while getopts ":m:" OPTION ;
do
case "${OPTION}" in
"m")
_mac_address="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
;;
esac ;
done ;
local OPTIND=1 ;
local _mac_address="" ;
while getopts ":m:" OPTION ;
do
case "${OPTION}" in
"m")
_mac_address="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
;;
esac ;
done ;
shift $(( OPTIND - 1 )) ;
if test $# != 5 ;
......@@ -265,7 +265,7 @@ create_domain(){
</domain>
__END_OF_STDIN__
}
} ;
destroy_domain(){
......@@ -280,7 +280,7 @@ destroy_domain(){
virsh -q undefine "${_DOMAIN}" --managed-save --snapshots-metadata ;
}
} ;
print_machine_usage_message(){
......@@ -315,21 +315,21 @@ print_machine_usage_message(){
create_machine(){
local OPTIND ;
local _ipv4_address="" ;
while getopts ":i:" OPTION ;
do
case "${OPTION}" in
"i")
_ipv4_address="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
;;
esac ;
done ;
local OPTIND=1 ;
local _ipv4_address="" ;
while getopts ":i:" OPTION ;
do
case "${OPTION}" in
"i")
_ipv4_address="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
;;
esac ;
done ;
shift $(( OPTIND - 1 )) ;
if test $# != 5 ;
......@@ -350,7 +350,6 @@ create_machine(){
create_volume "${_NAME}" "default" "${_PATH}" &&
_path=$(get_image_path "${_NAME}" "default") &&
create_domain${_ipv4_address:+ -m $(get_mac_address "${_ipv4_address}")} "${_NAME}" "${_CPU_COUNT}" "${_RAM}" "${_path}" "${_BRIDGE}" ;
#create_domain "${_NAME}" "${_CPU_COUNT}" "${_RAM}" "${_path}" "${_BRIDGE}" ;
}
......@@ -368,7 +367,7 @@ destroy_machine(){
destroy_domain "${_NAME}" &&
destroy_volume "${_NAME}" "default" ;
}
} ;
print_get_image_path_usage_message(){
......@@ -397,7 +396,7 @@ get_image_path(){
virsh -q vol-path "${_NAME}" --pool "${_POOL}" ;
}
} ;
print_get_mac_address_usage_message(){
......@@ -414,7 +413,7 @@ print_get_mac_address_usage_message(){
then the MAC address is
e2:9f:w':x':y':z'
e2:9f:W:X:Y:Z
where
......@@ -430,13 +429,13 @@ print_get_mac_address_usage_message(){
and
w' is the hexadecimal representation of w,
W is the hexadecimal representation of w,
x' is the hexadecimal representation of x,
X is the hexadecimal representation of x,
y' is the hexadecimal representation of y, and
Y is the hexadecimal representation of y, and
z' is the hexadecimal representation of z.
Z is the hexadecimal representation of z.
__END_OF_STDIN__
} ;
......@@ -534,17 +533,17 @@ get_mac_address(){
return 0 ;
}
} ;
case "${1} ${2} ${3} ${4}" in
"get image path help"|"destroy pool help")
shift 3 ;
shift 4 ;
print_get_image_path_usage_message ;
exit 0 ;
;;
"get mac address help"|"destroy pool help")
shift 3 ;
shift 4 ;
print_get_mac_address_usage_message ;
exit 0 ;
;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment