-
Notifications
You must be signed in to change notification settings - Fork 6
/
update.go
59 lines (47 loc) · 1.85 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"os"
"path/filepath"
cp "github.com/otiai10/copy"
)
func updateIfExists(binaryName string) {
if fileExists("./updates") && fileExists("./updates/web/") && fileExists("./updates/system") {
//All component exists. Update it
newArozBinary, err := getUpdateBinaryFilename()
if err != nil {
fmt.Println("[LAUNCHER] Unable to access update files: ", err.Error())
} else {
//Binary file got. Update it
//Backup the current executables and system files
fmt.Println("[LAUNCHER] Starting system backup process (to ./arozos.old)")
os.MkdirAll("./arozos.old", 0775)
copy(binaryName, filepath.Join("./arozos.old", filepath.Base(binaryName)))
//Backup the start.sh script and start.bat script if exists
if fileExists("./start.sh") {
copy("./start.sh", "./arozos.old/start.sh")
}
if fileExists("./start.bat") {
copy("./start.bat", "./arozos.old/start.bat")
}
//Backup the important system files
fmt.Println("[LAUNCHER] Backing up system files")
cp.Copy("./system", "./arozos.old/system/")
fmt.Println("[LAUNCHER] Backing up web server")
cp.Copy("./web", "./arozos.old/web/")
//Success. Continue binary replacement
fmt.Println("[LAUNCHER] Copying updates to runtime environment")
copy(newArozBinary, binaryName)
cp.Copy("./updates/system", "./system/")
cp.Copy("./updates/web", "./web/")
//Restore the configs from the arozos.old
fmt.Println("[LAUNCHER] Restoring previous configurations")
restoreConfigs()
fmt.Println("[LAUNCHER] Update Completed. Removing the update files")
os.RemoveAll("./updates/")
}
} else if fileExists("./updates") && (!fileExists("./updates/web/") || !fileExists("./updates/system")) {
//Update folder exists but some components is broken
fmt.Println("[LAUNCHER] Detected damaged / incomplete update package. Skipping update process")
}
}