[lxc-devel] [PATCH 1/4] lxc-destroy: use posix shell instead of bash
Stéphane Graber
stgraber at ubuntu.com
Tue Dec 25 16:35:13 UTC 2012
On 12/25/2012 05:08 PM, Natanael Copa wrote:
> - avoid use getopt --longoptions
>
> Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
Pushed to staging. Thanks.
> ---
> src/lxc/lxc-destroy.in | 41 +++++++++++++++++++++++++----------------
> 1 file changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
> index 1527495..0c27e4a 100644
> --- a/src/lxc/lxc-destroy.in
> +++ b/src/lxc/lxc-destroy.in
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/bin/sh
>
> #
> # lxc: linux Container library
> @@ -39,38 +39,47 @@ help() {
> echo " -f stop the container if it is running (rather than abort)" >&2
> }
>
> -shortoptions='hn:f'
> -longoptions='help,name:'
> -lxc_path=@LXCPATH@
> -force=0
> -
> -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
> -if [ $? != 0 ]; then
> +usage_err() {
> + [ -n "$1" ] && echo "$1" >&2
> usage
> - exit 1;
> -fi
> + exit 1
> +}
>
> -eval set -- "$getopt"
> +optarg_check() {
> + if [ -z "$2" ]; then
> + usage_err "option '$1' requires an argument"
> + fi
> +}
>
> -while true; do
> - case "$1" in
> +lxc_path=@LXCPATH@
> +force=0
> +
> +while [ $# -gt 0 ]; do
> + opt="$1"
> + shift
> + case "$opt" in
> -h|--help)
> help
> exit 1
> ;;
> -n|--name)
> - shift
> + optarg_check "$opt" "$1"
> lxc_name=$1
> shift
> ;;
> -f)
> force=1
> - shift
> ;;
> --)
> - shift
> break
> ;;
> + -?)
> + usage_err "unknown option '$opt'"
> + ;;
> + -*)
> + # split opts -abc into -a -b -c
> + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
> + ;;
> *)
> usage
> exit 1
>
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121225/35b2574b/attachment.pgp>
More information about the lxc-devel
mailing list