migration-036.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * @Author: LinkLeong link@icewhale.org
  3. * @Date: 2022-08-24 17:36:00
  4. * @LastEditors: LinkLeong
  5. * @LastEditTime: 2022-09-05 11:24:27
  6. * @FilePath: /CasaOS/cmd/migration-tool/migration-034-035.go
  7. * @Description:
  8. * @Website: https://www.casaos.io
  9. * Copyright (c) 2022 by icewhale, All Rights Reserved.
  10. */
  11. package main
  12. import (
  13. "strings"
  14. interfaces "github.com/IceWhaleTech/CasaOS-Common"
  15. "github.com/IceWhaleTech/CasaOS-Common/utils/version"
  16. "github.com/IceWhaleTech/CasaOS/pkg/config"
  17. "github.com/IceWhaleTech/CasaOS/service"
  18. )
  19. type migrationTool struct{}
  20. func (u *migrationTool) IsMigrationNeeded() (bool, error) {
  21. majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
  22. if err != nil {
  23. if err == version.ErrLegacyVersionNotFound {
  24. return false, nil
  25. }
  26. return false, err
  27. }
  28. if majorVersion > 0 {
  29. return false, nil
  30. }
  31. if minorVersion > 3 {
  32. return false, nil
  33. }
  34. if minorVersion == 3 && patchVersion > 5 {
  35. return false, nil
  36. }
  37. _logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
  38. return true, nil
  39. }
  40. func (u *migrationTool) PreMigrate() error {
  41. return nil
  42. }
  43. func (u *migrationTool) Migrate() error {
  44. if service.MyService.System().GetSysInfo().KernelArch == "aarch64" && config.ServerInfo.USBAutoMount != "True" && strings.Contains(service.MyService.System().GetDeviceTree(), "Raspberry Pi") {
  45. service.MyService.System().UpdateUSBAutoMount("False")
  46. service.MyService.System().ExecUSBAutoMountShell("False")
  47. }
  48. _logger.Info("update done")
  49. return nil
  50. }
  51. func (u *migrationTool) PostMigrate() error {
  52. return nil
  53. }
  54. func NewMigrationToolFor_036() interfaces.MigrationTool {
  55. return &migrationTool{}
  56. }