From 873170c6d1a609eb6fb5fed05088bae789465cab Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 20 Apr 2021 23:26:57 +0200 Subject: [PATCH] fix auto update --- CHANGELOG.md | 6 ++++++ RELEASE.md | 12 ++++++------ internal/bins/bins.go | 17 ++++++++++++----- internal/config.go | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfa7650..e9c915b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.3] - 2021-04-20 + +### Fixed + +- Auto upgrade script was not working on linux as linux does not support writing to the binary that is being executed + ## [1.0.2] - 2021-04-20 ### Added diff --git a/RELEASE.md b/RELEASE.md index 51d3c74..20c3278 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,9 +1,9 @@ # Releasing -Releases are handled by the CD server with includes checksums for each binary. +Releases are automatically built by the github workflow and uploaded to the release. -```bash -git tag 0.x -git push -git push origin --tags -``` +1. Bump `VERSION` in `internal/config.go`. +2. Update `CHANGELOG.md` +3. Commit to master +4. Create a new release with the `v1.2.3` tag and mark as draft. +5. The Github action will build the binaries, upload and mark the release as ready when done. diff --git a/internal/bins/bins.go b/internal/bins/bins.go index d6c2134..ac40d2a 100644 --- a/internal/bins/bins.go +++ b/internal/bins/bins.go @@ -72,14 +72,21 @@ func downloadAndInstallAsset(body GithubRelease, name string) error { // Uncompress bz := bzip2.NewReader(resp.Body) - // Save binary - file, err := os.Create(path.Join(INSTALL_PATH, name)) + // Save to tmp + // Linux does not support overwriting the file that is currently being overwritten, but it can be deleted and a new one moved in its place. + tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-") if err != nil { return err } - file.Chmod(0755) - defer file.Close() - io.Copy(file, bz) + defer tmp.Close() + tmp.Chmod(0755) + io.Copy(tmp, bz) + + to := path.Join(INSTALL_PATH, name) + os.Remove(to) // Delete if current, ignore error if file does not exits. + if err := os.Rename(tmp.Name(), to); err != nil { + return nil + } colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH) return nil diff --git a/internal/config.go b/internal/config.go index 421ca40..4f0fcdf 100644 --- a/internal/config.go +++ b/internal/config.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.0.2" +const VERSION = "1.0.3" var CI bool = false var VERBOSE bool = false