Skip to content

Commit

Permalink
Fixed command issues due to shellescape in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Dec 30, 2022
1 parent caef97f commit 2e5bf94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ build:
-o ./build/sentinelcli-${VERSION}-darwin-amd64 main.go
GOOS=linux GOARCH=amd64 go build -mod=readonly -tags="${BUILD_TAGS}" -ldflags="${LD_FLAGS}" \
-o ./build/sentinelcli-${VERSION}-linux-amd64 main.go
GOOS=windows GOARCH=amd64 go build -mod=readonly -tags="${BUILD_TAGS}" -ldflags="${LD_FLAGS}" \
-o ./build/sentinelcli-${VERSION}-windows-amd64.exe main.go

.PHONY: install
install:
Expand Down
5 changes: 4 additions & 1 deletion services/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func (w *WireGuard) IsUp() bool {
if err != nil {
return false
}
if strings.Contains(string(output), "No such device") {
return false
}

return strings.Contains(string(output), "No such device")
return true
}

func (w *WireGuard) PreUp() error {
Expand Down
17 changes: 9 additions & 8 deletions services/wireguard/wireguard_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/alessio/shellescape"
)

func (w *WireGuard) RealInterface() (string, error) {
return w.cfg.Name, nil
}

func (w *WireGuard) ExecFile(name string) string {
return filepath.Join(w.Home(), "WireGuard", name)
return ".\\" + filepath.Join("WireGuard", name)
}

func (w *WireGuard) Up() error {
var (
cfgFilePath = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
cmd = exec.Command(w.ExecFile("wireguard.exe"), strings.Split(
fmt.Sprintf("/installtunnelservice %s", shellescape.Quote(cfgFilePath)), " ")...)
cmd = exec.Command(
w.ExecFile("wireguard.exe"),
"/installtunnelservice", cfgFilePath,
)
)

cmd.Stdout = os.Stdout
Expand All @@ -36,8 +35,10 @@ func (w *WireGuard) Down() error {
return err
}

cmd := exec.Command(w.ExecFile("wireguard.exe"), strings.Split(
fmt.Sprintf("/uninstalltunnelservice %s", shellescape.Quote(iFace)), " ")...)
cmd := exec.Command(
w.ExecFile("wireguard.exe"),
"/uninstalltunnelservice", iFace,
)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 2e5bf94

Please sign in to comment.