]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-setcap: use POSIX shell instead of bash
authorNatanael Copa <ncopa@alpinelinux.org>
Mon, 26 Nov 2012 21:37:33 +0000 (22:37 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 27 Nov 2012 15:10:49 +0000 (10:10 -0500)
Avoid getopt --longoptions

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc-setcap.in

index 7fd390c0051f56d8f52a9d7e143f8c66d9b4627f..02c1e0916d69e36d74b293dc4a291c5e87c27113 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -81,32 +81,40 @@ lxc_dropcaps()
     chmod 0755 @LXCPATH@
 }
 
-shortoptions='hd'
-longoptions='help'
-
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
+usage_err() {
+    [ -n "$1" ] && echo "$1" >&2
     usage
     exit 1
-fi
+}
 
-eval set -- "$getopt"
+optarg_check() {
+    if [ -z "$2" ]; then
+        usage_err "option '$1' requires an argument"
+    fi
+}
 
-while true; do
-    case "$1" in
+while [ $# -gt 0 ]; do
+    opt="$1"
+    shift
+    case "$opt" in
        -d)
            LXC_DROP_CAPS="yes"
-           shift
            ;;
        -h|--help)
            help
            exit 0
            ;;
        --)
-           shift
            break
            ;;
-       *)
+        -?)
+            usage_err "unknown option '$opt'"
+            ;;
+        -*)
+            # split opts -abc into -a -b -c
+            set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+            ;;
+         *)
            usage
            exit 1
            ;;