update.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. cp "github.com/otiai10/copy"
  7. )
  8. func updateIfExists(binaryName string) {
  9. if fileExists("./updates") && fileExists("./updates/web/") && fileExists("./updates/system") {
  10. //All component exists. Update it
  11. newArozBinary, err := getUpdateBinaryFilename()
  12. if err != nil {
  13. fmt.Println("[LAUNCHER] Unable to access update files: ", err.Error())
  14. } else {
  15. //Binary file got. Update it
  16. //Backup the current executables and system files
  17. fmt.Println("[LAUNCHER] Starting system backup process (to ./arozos.old)")
  18. os.MkdirAll("./arozos.old", 0775)
  19. copy(binaryName, filepath.Join("./arozos.old", filepath.Base(binaryName)))
  20. cp.Copy("./system", "./arozos.old/system/")
  21. cp.Copy("./web", "./arozos.old/web/")
  22. //Success. Continue binary replacement
  23. fmt.Println("[LAUNCHER] Copying updates to runtime environment")
  24. copy(newArozBinary, binaryName)
  25. cp.Copy("./updates/system", "./system/")
  26. cp.Copy("./updates/web", "./web/")
  27. //Restore the configs from the arozos.old
  28. fmt.Println("[LAUNCHER] Restoring previous configurations")
  29. restoreConfigs()
  30. fmt.Println("[LAUNCHER] Update Completed. Removing the update files")
  31. os.RemoveAll("./updates/")
  32. }
  33. } else if fileExists("./updates") && (!fileExists("./updates/web/") || !fileExists("./updates/system")) {
  34. //Update folder exists but some components is broken
  35. fmt.Println("[LAUNCHER] Detected damaged / incomplete update package. Skipping update process")
  36. }
  37. }