main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "os/exec"
  6. "path/filepath"
  7. cp "github.com/otiai10/copy"
  8. )
  9. /*
  10. ArozOS Launcher
  11. For auto update and future extension purpose
  12. Author: tobychui
  13. */
  14. const (
  15. launcherVersion = "1.0"
  16. )
  17. func main() {
  18. //Print basic information
  19. fmt.Println("[LAUNCHER] ArozOS Launcher ver " + launcherVersion)
  20. binaryName := autoDetectExecutable()
  21. fmt.Println("[LAUNCHER] Choosing binary executable: " + binaryName)
  22. //Check if updates exists. If yes, overwrite it
  23. if fileExists("./updates") && fileExists("./updates/web/") && fileExists("./updates/system") {
  24. //All component exists. Update it
  25. newArozBinary, err := getUpdateBinaryFilename()
  26. if err != nil {
  27. fmt.Println("[LAUNCHER] Unable to access update files: ", err.Error())
  28. } else {
  29. //Binary file got. Update it
  30. //Backup the current executables and system files
  31. fmt.Println("[LAUNCHER] Starting system backup process (to ./arozos.old)")
  32. os.MkdirAll("./arozos.old", 0775)
  33. copy(binaryName, filepath.Join("./arozos.old", filepath.Base(binaryName)))
  34. cp.Copy("./system", "./arozos.old/system/")
  35. cp.Copy("./web", "./arozos.old/web/")
  36. //Success. Continue binary replacement
  37. fmt.Println("[LAUNCHER] Copying updates to runtime environment")
  38. copy(newArozBinary, binaryName)
  39. cp.Copy("./updates/system", "./system/")
  40. cp.Copy("./updates/web", "./web/")
  41. fmt.Println("[LAUNCHER] Update Completed. Removing the update files")
  42. os.RemoveAll("./updates/")
  43. }
  44. } else if fileExists("./updates") && (!fileExists("./updates/web/") || !fileExists("./updates/system")) {
  45. //Update folder exists but some components is broken
  46. fmt.Println("[LAUNCHER] Detected damaged / incomplete update package. Skipping update process")
  47. }
  48. cmd := exec.Command(binaryName, os.Args[1:]...)
  49. cmd.Stdout = os.Stdout
  50. cmd.Stderr = os.Stderr
  51. cmd.Run()
  52. }