Skip to content

Commit

Permalink
Fixes self install
Browse files Browse the repository at this point in the history
  • Loading branch information
leucos committed Aug 18, 2020
1 parent 42e154a commit 96587a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ linux: fmt lint $(BIN) ; $(info $(M) building static executable for Linux……)
$Q env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build \
-tags release -a \
-ldflags '-w -extldflags "-static" -X github.com/devops-works/binenv/cmd.Version=$(VERSION) -X github.com/devops-works/binenv/cmd.BuildDate=$(DATE)' \
-o $(BIN)/$(PACKAGE)-linux-amd64-$(VERSION)
-o $(BIN)/$(PACKAGE)-linux-amd64

darwin: fmt lint $(BIN) ; $(info $(M) building static executable for MacOS…) @ ## Build program binary
$Q env GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GO) build \
-tags release -a \
-ldflags '-w -extldflags "-static" -X github.com/devops-works/binenv/cmd.Version=$(VERSION) -X github.com/devops-works/binenv/cmd.BuildDate=$(DATE)' \
-o $(BIN)/$(PACKAGE)-darwin-amd64-$(VERSION)
-o $(BIN)/$(PACKAGE)-darwin-amd64

windows: fmt lint clean $(BIN) ; $(info $(M) building static executable for Windoze…) @ ## Build program binary
$Q env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GO) build \
-tags release -a \
-ldflags '-w -extldflags "-static" -X github.com/devops-works/binenv/cmd.Version=$(VERSION) -X github.com/devops-works/binenv/cmd.BuildDate=$(DATE)' \
-o $(BIN)/$(PACKAGE)-win-amd64-$(VERSION)
-o $(BIN)/$(PACKAGE)-win-amd64

release: windows darwin linux ; $(info $(M) stripping release executable for Linux…) @ ## Build program binary
$Q strip $(BIN)/$(PACKAGE)-linux-amd64-$(VERSION)
$Q strip $(BIN)/$(PACKAGE)-linux-amd64
$Q (cd bin && sha256sum * > SHA256SUMS)
$Q cp $(BIN)/$(PACKAGE)-linux-amd64-$(VERSION) $(BIN)/$(PACKAGE)
# $Q gzip $(BIN)/$(PACKAGE)-linux-amd64-$(VERSION)
# $Q gzip $(BIN)/$(PACKAGE)-darwin-amd64-$(VERSION)
# $Q gzip $(BIN)/$(PACKAGE)-win-amd64-$(VERSION)
$Q cp $(BIN)/$(PACKAGE)-linux-amd64 $(BIN)/$(PACKAGE)
# $Q gzip $(BIN)/$(PACKAGE)-linux-amd64
# $Q gzip $(BIN)/$(PACKAGE)-darwin-amd64
# $Q gzip $(BIN)/$(PACKAGE)-win-amd64
$Q $(BIN)/$(PACKAGE) version


Expand Down
2 changes: 1 addition & 1 deletion distributions/distributions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sources:
type: github-releases
url: https://api.github.com/repos/devops-works/binenv/releases
fetch:
url: https://github.com/devops-works/binenv/releases/download/v{{ .Version }}/binenv-{{ .OS }}-{{ .Arch }}-v{{ .Version }}
url: https://github.com/devops-works/binenv/releases/download/v{{ .Version }}/binenv-{{ .OS }}-{{ .Arch }}
install:
type: direct

Expand Down
11 changes: 10 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,15 @@ func (a *App) selfInstall() error {
}
defer from.Close()

to, err := os.OpenFile(filepath.Join(a.bindir, "/shim"), os.O_RDWR|os.O_CREATE, 0750)
shim := filepath.Join(a.bindir, "/shim")
shimnew := shim + ".new"

if _, err := os.Stat(shim); os.IsExist(err) {
shimold := shim + ".old"
os.Rename(shim, shimold)
}

to, err := os.OpenFile(shimnew, os.O_RDWR|os.O_CREATE, 0750)
if err != nil {
return err
}
Expand All @@ -506,6 +514,7 @@ func (a *App) selfInstall() error {
if err != nil {
return err
}
os.Rename(shimnew, shim)

return nil
}
Expand Down

0 comments on commit 96587a6

Please sign in to comment.