Skip to content

Commit 581c978

Browse files
committed
initial commit
0 parents  commit 581c978

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sh

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
go build sh.go

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Go bash wrapper
2+
3+
- Forwards CLI arguments to `/bin/bash`
4+
- Fails if there is `GO_SH_WRAPPER` variable defined as recursion
5+
control variable
6+
7+
## But, why?
8+
9+
Amazon ssm-agent by default runs with 'sh' command and such does
10+
not load full bash shell, and does not process user home-directory
11+
startup files like `~/.bashrc`
12+
13+
Replace standard `/bin/sh` with `sh` file produce by running `make build`
14+
15+
[Relevant discussion](https://github.com/aws/amazon-ssm-agent/pull/171)

sh.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
func main() {
10+
_, set := os.LookupEnv("GO_SH_WRAPPER")
11+
if set {
12+
os.Exit(0)
13+
}
14+
env := append(os.Environ(),"GO_SH_WRAPPER=1")
15+
args := os.Args[1:]
16+
cmd := exec.Command("/bin/bash", args...)
17+
cmd.Env = env
18+
cmd.Stderr = os.Stderr
19+
cmd.Stdin = os.Stdin
20+
cmd.Stdout = os.Stdout
21+
if err := cmd.Run(); err != nil {
22+
log.Fatal(err)
23+
}
24+
}

0 commit comments

Comments
 (0)