1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package main
- import (
- "fmt"
- "net/http"
- "os"
- "os/exec"
- "time"
- )
- /*
- ArozOS Launcher
- For auto update and future extension purpose
- Author: tobychui
- */
- const (
- launcherVersion = "1.0"
- )
- var (
- arozosRunning bool = false
- )
- func main() {
- //Print basic information
- fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
- binaryName := autoDetectExecutable()
- fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
- //Check if updates exists. If yes, overwrite it
- updateIfExists(binaryName)
- //Register the binary start path
- cmd := exec.Command(binaryName, os.Args[1:]...)
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- //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
- }
- }
|