|
@@ -2,11 +2,10 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "net/http"
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
- "path/filepath"
|
|
|
|
-
|
|
|
|
- cp "github.com/otiai10/copy"
|
|
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -21,6 +20,10 @@ const (
|
|
launcherVersion = "1.0"
|
|
launcherVersion = "1.0"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+var (
|
|
|
|
+ arozosRunning bool = false
|
|
|
|
+)
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
//Print basic information
|
|
//Print basic information
|
|
fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
|
|
fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
|
|
@@ -28,38 +31,38 @@ func main() {
|
|
fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
|
|
fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
|
|
|
|
|
|
//Check if updates exists. If yes, overwrite it
|
|
//Check if updates exists. If yes, overwrite it
|
|
- 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)))
|
|
|
|
- cp.Copy("./system", "./arozos.old/system/")
|
|
|
|
- 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/")
|
|
|
|
-
|
|
|
|
- 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")
|
|
|
|
- }
|
|
|
|
|
|
+ updateIfExists(binaryName)
|
|
|
|
|
|
|
|
+ //Register the binary start path
|
|
cmd := exec.Command(binaryName, os.Args[1:]...)
|
|
cmd := exec.Command(binaryName, os.Args[1:]...)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Stderr = os.Stderr
|
|
- cmd.Run()
|
|
|
|
|
|
+
|
|
|
|
+ //Register the http server to notify ArozOS there is a launcher will handle the update
|
|
|
|
+ go func() {
|
|
|
|
+ http.HandleFunc("/chk", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ w.Write([]byte("LauncherA v" + launcherVersion))
|
|
|
|
+ fmt.Println("[LAUNCHER] CHK RECV - DONE")
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ http.ListenAndServe("127.0.0.1:25576", nil)
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ for {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Start the cmd
|
|
|
|
+ for {
|
|
|
|
+ cmd.Run()
|
|
|
|
+ fmt.Println("[LAUNCHER] ArozOS Exited. Restarting in 3 seconds... ")
|
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
|
+ updateIfExists(binaryName)
|
|
|
|
+
|
|
|
|
+ //Rebuild the start paramters
|
|
|
|
+ cmd = exec.Command(binaryName, os.Args[1:]...)
|
|
|
|
+ cmd.Stdout = os.Stdout
|
|
|
|
+ cmd.Stderr = os.Stderr
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|