Skip to content

Commit

Permalink
[Auto Updating] Fix Linux Auto Updates in 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius authored Jan 18, 2022
1 parent bd42d37 commit 66ac4c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.6.1]

### Linux Auto Updates

* Linux auto updates should properly work from this release (1.6.1) and on.

## [1.6.0]

### Updated Spell Animations!
Expand Down
22 changes: 18 additions & 4 deletions internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (s UpdaterService) CheckForUpdates() {
executablePath := filepath.Dir(ex)

// check if a .old version exists, delete it if does
oldExecutable := fmt.Sprintf("%s\\%s.old", executablePath, executableName)
oldExecutable := fmt.Sprintf("%s\\%s.old", executablePath, executableName)
if runtime.GOOS == "linux" {
oldExecutable = fmt.Sprintf("%s/%s.old", executablePath, executableName)
}
if _, err := os.Stat(oldExecutable); err == nil {
e := os.Remove(oldExecutable)
if e != nil {
Expand All @@ -72,7 +75,7 @@ func (s UpdaterService) CheckForUpdates() {
}

// if being ran from go run main.go
if executableName == "main.exe" {
if executableName == "main.exe" || executableName == "main" {
fmt.Println("[Update] Running as go run main.go, ignoring...")
return
}
Expand Down Expand Up @@ -131,6 +134,7 @@ func (s UpdaterService) CheckForUpdates() {

// linux
if runtime.GOOS == "linux" {

// unzip
tempFileZipped := fmt.Sprintf("%s/%s", os.TempDir(), targetFileNameZipped)
uz := unzip.New(tempFileZipped, os.TempDir())
Expand All @@ -139,14 +143,24 @@ func (s UpdaterService) CheckForUpdates() {
log.Println(err)
}

// rename running process to .old
err := os.Rename(
fmt.Sprintf("%s/%s", executablePath, executableName),
fmt.Sprintf("%s/%s.old", executablePath, executableName),
)
if err != nil {
log.Fatal(err)
}

// relink
tempFile := fmt.Sprintf("%s/%s", os.TempDir(), targetFileName)
err := moveFile(tempFile, "spire")
newExecutable := fmt.Sprintf("%s/%s", executablePath, executableName)
err = moveFile(tempFile, newExecutable)
if err != nil {
log.Println(err)
}

err = os.Chmod("spire", 0755)
err = os.Chmod(newExecutable, 0755)
if err != nil {
log.Println(err)
}
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"name": "spire",
"version": "1.6.0",
"version": "1.6.1",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
},
"dependencies": {
"vue-color": "^2.8.1"
}
}

0 comments on commit 66ac4c1

Please sign in to comment.