Skip to content

Commit

Permalink
dockerd-rootless.sh: Fix variable not double quotes cause unexpected …
Browse files Browse the repository at this point in the history
…behavior

```
$ cat test.sh

echo "orign value=$XDG_RUNTIME_DIR"

echo "1. with [ ] not quote ..."
[ -w $XDG_RUNTIME_DIR ]
echo "get 1 ret_code: $?"

echo "2. with [ ] and quote ..."
[ -w "$XDG_RUNTIME_DIR" ]
echo "get 2 ret_code: $?"

$ sh ./test.sh
orign value=
1. with [ ] not quote ...
get 1 ret_code: 0
2. with [ ] and quote ...
get 2 ret_code: 1

$ bash ./test.sh
orign value=
1. with [ ] not quote ...
get 1 ret_code: 0
2. with [ ] and quote ...
get 2 ret_code: 1
```

Signed-off-by: Chenyang Yan <memory.yancy@gmail.com>
(cherry picked from commit a8ce4d4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
uddmorningsun authored and thaJeztah committed Oct 21, 2021
1 parent 2c6aa5a commit 59d2a2c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contrib/dockerd-rootless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ case "$1" in
exit 1
;;
esac
if ! [ -w $XDG_RUNTIME_DIR ]; then
if ! [ -w "$XDG_RUNTIME_DIR" ]; then
echo "XDG_RUNTIME_DIR needs to be set and writable"
exit 1
fi
if ! [ -d $HOME ]; then
if ! [ -d "$HOME" ]; then
echo "HOME needs to be set and exist."
exit 1
fi
Expand All @@ -40,7 +40,7 @@ for f in docker-rootlesskit rootlesskit; do
break
fi
done
if [ -z $rootlesskit ]; then
if [ -z "$rootlesskit" ]; then
echo "rootlesskit needs to be installed"
exit 1
fi
Expand All @@ -52,19 +52,19 @@ fi
: "${DOCKERD_ROOTLESS_ROOTLESSKIT_SLIRP4NETNS_SECCOMP:=auto}"
net=$DOCKERD_ROOTLESS_ROOTLESSKIT_NET
mtu=$DOCKERD_ROOTLESS_ROOTLESSKIT_MTU
if [ -z $net ]; then
if [ -z "$net" ]; then
if command -v slirp4netns > /dev/null 2>&1; then
# If --netns-type is present in --help, slirp4netns is >= v0.4.0.
if slirp4netns --help | grep -qw -- --netns-type; then
net=slirp4netns
if [ -z $mtu ]; then
if [ -z "$mtu" ]; then
mtu=65520
fi
else
echo "slirp4netns found but seems older than v0.4.0. Falling back to VPNKit."
fi
fi
if [ -z $net ]; then
if [ -z "$net" ]; then
if command -v vpnkit > /dev/null 2>&1; then
net=vpnkit
else
Expand All @@ -73,11 +73,11 @@ if [ -z $net ]; then
fi
fi
fi
if [ -z $mtu ]; then
if [ -z "$mtu" ]; then
mtu=1500
fi

if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
if [ -z "$_DOCKERD_ROOTLESS_CHILD" ]; then
_DOCKERD_ROOTLESS_CHILD=1
export _DOCKERD_ROOTLESS_CHILD
if [ "$(id -u)" = "0" ]; then
Expand Down Expand Up @@ -107,7 +107,7 @@ if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
$DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS \
$0 $@
else
[ $_DOCKERD_ROOTLESS_CHILD = 1 ]
[ "$_DOCKERD_ROOTLESS_CHILD" = 1 ]
# remove the symlinks for the existing files in the parent namespace if any,
# so that we can create our own files in our mount namespace.
rm -f /run/docker /run/containerd /run/xtables.lock
Expand Down

0 comments on commit 59d2a2c

Please sign in to comment.