From 07a9281fc1bc3152fa553b774b0de9bc9f18e08a Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 19 May 2023 16:26:12 +0200 Subject: [PATCH] Added SH_WORD_SPLIT to inject script Signed-off-by: Thomas Kosiewski --- cmd/agent/workspace/up.go | 9 ++------- pkg/inject/inject.go | 5 ----- pkg/inject/inject.sh | 12 ++++++++---- scripts/scripts.go | 11 +---------- scripts/wrapper.go | 22 ---------------------- scripts/wrapper.sh | 9 --------- 6 files changed, 11 insertions(+), 57 deletions(-) delete mode 100644 scripts/wrapper.go delete mode 100644 scripts/wrapper.sh diff --git a/cmd/agent/workspace/up.go b/cmd/agent/workspace/up.go index eee870b46..5b5aa98ec 100644 --- a/cmd/agent/workspace/up.go +++ b/cmd/agent/workspace/up.go @@ -474,15 +474,10 @@ func InstallDocker(log log.Logger) error { log.Debug("Installing Docker...") - script, err := scripts.InstallDocker() - if err != nil { - return err - } - - shellCommand := exec.Command("sh", "-c", script) + shellCommand := exec.Command("sh", "-c", scripts.InstallDocker) shellCommand.Stdout = writer shellCommand.Stderr = writer - err = shellCommand.Run() + err := shellCommand.Run() if err != nil { return err } diff --git a/pkg/inject/inject.go b/pkg/inject/inject.go index 560b5bfcf..a4dc3421d 100644 --- a/pkg/inject/inject.go +++ b/pkg/inject/inject.go @@ -15,7 +15,6 @@ import ( "github.com/loft-sh/devpod/pkg/log" "github.com/loft-sh/devpod/pkg/template" - "github.com/loft-sh/devpod/scripts" perrors "github.com/pkg/errors" ) @@ -63,10 +62,6 @@ func InjectAndExecute( return true, err } - t, err = scripts.WrapScript(t) - if err != nil { - return true, err - } log.Debugf("execute inject script") defer log.Debugf("done injecting") diff --git a/pkg/inject/inject.sh b/pkg/inject/inject.sh index ca1b20dc4..29545557a 100644 --- a/pkg/inject/inject.sh +++ b/pkg/inject/inject.sh @@ -1,6 +1,10 @@ #!/bin/sh set -e +if [ "$SHELL" != "${SHELL%"/zsh"*}" ]; then + setopt SH_WORD_SPLIT +fi + INSTALL_DIR="{{ .InstallDir }}" INSTALL_FILENAME="{{ .InstallFilename }}" @@ -51,19 +55,19 @@ download() { fi while :; do - status="" + cmd_status="" if command_exists curl; then $sh_c "curl -fsSL $DOWNLOAD_URL -o $INSTALL_PATH" && break - status=$? + cmd_status=$? elif command_exists wget; then $sh_c "wget -q $DOWNLOAD_URL -O $INSTALL_PATH" && break - status=$? + cmd_status=$? else echo "error: no download tool found, please install curl or wget" exit 127 fi >&2 echo "error: failed to download devpod" - >&2 echo " command returned: ${status}" + >&2 echo " command returned: ${cmd_status}" >&2 echo "Trying again in 10 seconds..." sleep 10 done diff --git a/scripts/scripts.go b/scripts/scripts.go index dadcf6081..fc2caabd7 100644 --- a/scripts/scripts.go +++ b/scripts/scripts.go @@ -3,13 +3,4 @@ package scripts import _ "embed" //go:embed install_docker.sh -var installDocker string - -func InstallDocker() (string, error) { - script, err := WrapScript(installDocker) - if err != nil { - return "", err - } - - return script, nil -} +var InstallDocker string diff --git a/scripts/wrapper.go b/scripts/wrapper.go deleted file mode 100644 index 8f26c49a0..000000000 --- a/scripts/wrapper.go +++ /dev/null @@ -1,22 +0,0 @@ -package scripts - -import ( - _ "embed" - - "github.com/loft-sh/devpod/pkg/template" -) - -//go:embed wrapper.sh -var scriptWrapper string - -func WrapScript(script string) (string, error) { - // generate script - t, err := template.FillTemplate(scriptWrapper, map[string]string{ - "Script": script, - }) - if err != nil { - return "", err - } - - return t, nil -} diff --git a/scripts/wrapper.sh b/scripts/wrapper.sh deleted file mode 100644 index 2b6a6a864..000000000 --- a/scripts/wrapper.sh +++ /dev/null @@ -1,9 +0,0 @@ -tmpfile=$(mktemp) - -cat > $tmpfile <<'EOL' -{{ .Script }} -EOL - -chmod +x $tmpfile -$tmpfile -rm $tmpfile