Skip to content

Commit c89b06d

Browse files
committed
chore: Replace hardcoded paths in scripts with env lookup
Change-Id: Id159eea95ce16be1881fb290f5958d505222cb83 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent d52008c commit c89b06d

File tree

30 files changed

+44
-44
lines changed

30 files changed

+44
-44
lines changed

agent/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ func TestAgent_ScriptLogging(t *testing.T) {
22432243
{
22442244
LogSourceID: lsStart,
22452245
RunOnStart: true,
2246-
Script: `#!/bin/sh
2246+
Script: `#!/usr/bin/env sh
22472247
i=0
22482248
while [ $i -ne 5 ]
22492249
do
@@ -2255,7 +2255,7 @@ done
22552255
{
22562256
LogSourceID: lsStop,
22572257
RunOnStop: true,
2258-
Script: `#!/bin/sh
2258+
Script: `#!/usr/bin/env sh
22592259
i=0
22602260
while [ $i -ne 3000 ]
22612261
do

agent/agentssh/agentssh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestNewServer_ExecuteShebang(t *testing.T) {
8686

8787
t.Run("Basic", func(t *testing.T) {
8888
t.Parallel()
89-
cmd, err := s.CreateCommand(ctx, `#!/bin/bash
89+
cmd, err := s.CreateCommand(ctx, `#!/usr/bin/env bash
9090
echo test`, nil)
9191
require.NoError(t, err)
9292
output, err := cmd.AsExec().CombinedOutput()

agent/reaper/reaper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestReap(t *testing.T) {
3535
err := reaper.ForkReap(
3636
reaper.WithPIDCallback(pids),
3737
// Provide some argument that immediately exits.
38-
reaper.WithExecArgs("/bin/sh", "-c", "exit 0"),
38+
reaper.WithExecArgs("/usr/bin/env sh", "-c", "exit 0"),
3939
)
4040
require.NoError(t, err)
4141

@@ -89,7 +89,7 @@ func TestReapInterrupt(t *testing.T) {
8989
reaper.WithCatchSignals(os.Interrupt),
9090
// Signal propagation does not extend to children of children, so
9191
// we create a little bash script to ensure sleep is interrupted.
92-
reaper.WithExecArgs("/bin/sh", "-c", fmt.Sprintf("pid=0; trap 'kill -USR2 %d; kill -TERM $pid' INT; sleep 10 &\npid=$!; kill -USR1 %d; wait", os.Getpid(), os.Getpid())),
92+
reaper.WithExecArgs("/usr/bin/env", "sh", "-c", fmt.Sprintf("pid=0; trap 'kill -USR2 %d; kill -TERM $pid' INT; sleep 10 &\npid=$!; kill -USR1 %d; wait", os.Getpid(), os.Getpid())),
9393
)
9494
}()
9595

cli/configssh_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func Test_sshConfigExecEscape(t *testing.T) {
167167
err := os.MkdirAll(dir, 0o755)
168168
require.NoError(t, err)
169169
bin := filepath.Join(dir, "coder")
170-
contents := []byte("#!/bin/sh\necho yay\n")
170+
contents := []byte("#!/usr/bin/env sh\necho yay\n")
171171
err = os.WriteFile(bin, contents, 0o755) //nolint:gosec
172172
require.NoError(t, err)
173173

@@ -178,7 +178,7 @@ func Test_sshConfigExecEscape(t *testing.T) {
178178
}
179179
require.NoError(t, err)
180180

181-
b, err := exec.Command("/bin/sh", "-c", escaped).CombinedOutput() //nolint:gosec
181+
b, err := exec.Command("/usr/bin/env", "sh", "-c", escaped).CombinedOutput() //nolint:gosec
182182
require.NoError(t, err)
183183
got := strings.TrimSpace(string(b))
184184
require.Equal(t, "yay", got)

cli/dotfiles_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestDotfiles(t *testing.T) {
121121
testRepo := testGitRepo(t, root)
122122

123123
// nolint:gosec
124-
err := os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
124+
err := os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/usr/bin/env bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
125125
require.NoError(t, err)
126126

127127
c := exec.Command("git", "add", "install.sh")
@@ -155,7 +155,7 @@ func TestDotfiles(t *testing.T) {
155155
err := os.MkdirAll(filepath.Join(testRepo, "script"), 0o750)
156156
require.NoError(t, err)
157157
// nolint:gosec
158-
err = os.WriteFile(filepath.Join(testRepo, scriptPath), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
158+
err = os.WriteFile(filepath.Join(testRepo, scriptPath), []byte("#!/usr/bin/env bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
159159
require.NoError(t, err)
160160

161161
c := exec.Command("git", "add", scriptPath)
@@ -192,7 +192,7 @@ func TestDotfiles(t *testing.T) {
192192
require.NoError(t, err)
193193

194194
// nolint:gosec
195-
err = os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
195+
err = os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/usr/bin/env bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
196196
require.NoError(t, err)
197197

198198
c = exec.Command("git", "checkout", "-b", "other_branch")

docs/admin/templates/extending-templates/docker-in-workspaces.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resource "coder_agent" "main" {
3838
arch = data.coder_provisioner.me.arch
3939
os = "linux"
4040
startup_script = <<EOF
41-
#!/bin/sh
41+
#!/usr/bin/env sh
4242
4343
# Start Docker
4444
sudo dockerd &
@@ -79,7 +79,7 @@ resource "coder_agent" "main" {
7979
arch = "amd64"
8080
dir = "/home/coder"
8181
startup_script = <<EOF
82-
#!/bin/sh
82+
#!/usr/bin/env sh
8383
8484
# Start Docker
8585
sudo dockerd &

docs/admin/templates/extending-templates/modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module "coder-base" {
2323
resource "coder_agent" "dev" {
2424
# Modules can provide outputs, such as helper scripts
2525
startup_script=<<EOF
26-
#!/bin/sh
26+
#!/usr/bin/env sh
2727
${module.coder-base.code_server_install_command}
2828
EOF
2929
}

docs/admin/templates/extending-templates/web-ides.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ resource "coder_agent" "main" {
4040
arch = "amd64"
4141
os = "linux"
4242
startup_script = <<EOF
43-
#!/bin/sh
43+
#!/usr/bin/env sh
4444
# install code-server
4545
# add '-s -- --version x.x.x' to install a specific code-server version
4646
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server
@@ -121,7 +121,7 @@ command. To add VS Code web as a web IDE, you have two options.
121121
arch = "amd64"
122122
os = "linux"
123123
startup_script = <<EOF
124-
#!/bin/sh
124+
#!/usr/bin/env sh
125125
# install VS Code
126126
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz
127127
mkdir -p /tmp/vscode-cli
@@ -231,7 +231,7 @@ resource "coder_agent" "coder" {
231231
arch = "amd64"
232232
dir = "/home/coder"
233233
startup_script = <<EOT
234-
#!/bin/bash
234+
#!/usr/bin/env bash
235235
# start rstudio
236236
/usr/lib/rstudio-server/bin/rserver --server-daemonize=1 --auth-none=1 &
237237
EOT
@@ -278,7 +278,7 @@ resource "coder_agent" "coder" {
278278
arch = "amd64"
279279
dir = "/home/coder"
280280
startup_script = <<EOT
281-
#!/bin/bash
281+
#!/usr/bin/env bash
282282
# install and start airflow
283283
pip3 install apache-airflow
284284
/home/coder/.local/bin/airflow standalone &
@@ -329,7 +329,7 @@ resource "coder_agent" "coder" {
329329
arch = "amd64"
330330
dir = "/home/coder"
331331
startup_script = <<EOT
332-
#!/bin/bash
332+
#!/usr/bin/env bash
333333
334334
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
335335
filebrowser --noauth --root /home/coder --port 13339 >/tmp/filebrowser.log 2>&1 &

docs/reference/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ activity.
8787
long-running machine learning job).
8888

8989
```shell
90-
#!/bin/bash
90+
#!/usr/bin/env bash
9191
# Send workspace activity as long as the job is still running
9292

9393
while true

docs/tutorials/reverse-proxy-apache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
3. And add this code:
165165

166166
```shell
167-
#!/bin/sh
167+
#!/usr/bin/env sh
168168
sudo certbot renew -q
169169
```
170170

0 commit comments

Comments
 (0)