From a7f730c1bc76d079558c9d2b3377413bc358eabe Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 24 Apr 2018 12:45:40 +0100
Subject: [PATCH] Use "--" argument separator if available

I recently added that to bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel-wrap | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/pressure-vessel-wrap b/pressure-vessel-wrap
index 3b2a35830..73104d942 100755
--- a/pressure-vessel-wrap
+++ b/pressure-vessel-wrap
@@ -146,14 +146,27 @@ if [ "$#" -eq 0 ]; then
     exit 2
 fi
 
-# bwrap doesn't support the -- syntax
-case "$1" in
-    (-*)
-        command="$1"
-        shift
-        set -- "./$command" "$@"
-        ;;
-esac
+if "$BWRAP" --help | grep -F '[--]' 2>/dev/null; then
+    bwrap_end_of_options="--"
+else
+    # bwrap doesn't support the -- syntax
+    bwrap_end_of_options=""
+    case "$1" in
+        (-*)
+            case "$1" in
+                (*=*)
+                    # env would interpret this as an environment variable
+                    echo "$me: Cannot execute command '$1' with bubblewrap < 0.2.2">&2
+                    exit 1
+                    ;;
+                (*)
+                    # Emulate it via env(1)
+                    bwrap_end_of_options="env"
+                    ;;
+            esac
+            ;;
+    esac
+fi
 
 if [ -n "$interactive" ]; then
     exec </dev/tty
@@ -285,6 +298,6 @@ fi
 
 # Replace this process with bwrap, which replaces itself with the
 # desired command (unless exec fails)
-exec "$BWRAP" "$@" || e=$?
+exec "$BWRAP" $bwrap_end_of_options "$@" || e=$?
 echo "$me: failed to execute '$BWRAP $*': exec status $?" >&2
 exit $?
-- 
GitLab