diff --git a/build/sysroot/etc/casaos/app-management.conf.sample b/build/sysroot/etc/casaos/app-management.conf.sample index aeaae92d..54452f73 100644 --- a/build/sysroot/etc/casaos/app-management.conf.sample +++ b/build/sysroot/etc/casaos/app-management.conf.sample @@ -10,3 +10,4 @@ AppsPath = /var/lib/casaos/apps [server] appstore = https://casaos.app/store/main.zip +appstore = https://github.com/bigbeartechworld/big-bear-casaos/archive/refs/heads/master.zip \ No newline at end of file diff --git a/cmd/migration-tool/main.go b/cmd/migration-tool/main.go index 4d697176..4ba5a43b 100644 --- a/cmd/migration-tool/main.go +++ b/cmd/migration-tool/main.go @@ -70,6 +70,7 @@ func main() { migrationTools := []interfaces.MigrationTool{ // NewMigrationDummy(), NewMigration044AndOlder(), + NewMigration0412AndOlder(), } var selectedMigrationTool interfaces.MigrationTool diff --git a/cmd/migration-tool/migration_0412_and_older.go b/cmd/migration-tool/migration_0412_and_older.go new file mode 100644 index 00000000..e39e1375 --- /dev/null +++ b/cmd/migration-tool/migration_0412_and_older.go @@ -0,0 +1,77 @@ +package main + +import ( + "fmt" + "io" + "os" + "strings" + + interfaces "github.com/IceWhaleTech/CasaOS-Common" + + "github.com/IceWhaleTech/CasaOS-AppManagement/pkg/config" +) + +type migrationTool0412AndOlder struct{} + +const bigBearAppStoreUrl = "https://github.com/bigbeartechworld/big-bear-casaos/archive/refs/heads/master.zip" + +func (u *migrationTool0412AndOlder) IsMigrationNeeded() (bool, error) { + _logger.Info("Checking if migration is needed...") + + // read string from AppManagementConfigFilePath + file, err := os.Open(config.AppManagementConfigFilePath) + if err != nil { + _logger.Error("failed to detect app management config file: %s", err) + return false, err + } + defer file.Close() + content, err := io.ReadAll(file) + if err != nil { + _logger.Error("failed to read app management config file: %s", err) + return false, err + } + + if strings.Contains(string(content), bigBearAppStoreUrl) { + _logger.Info("Migration is add big bear app store. it is not needed.") + return false, nil + } + return true, nil +} + +func (u *migrationTool0412AndOlder) PreMigrate() error { + return nil +} + +func (u *migrationTool0412AndOlder) Migrate() error { + // add big bear app store + file, err := os.OpenFile(config.AppManagementConfigFilePath, os.O_RDWR, 0644) + if err != nil { + _logger.Error("failed to open app management config file: %s", err) + return err + } + defer file.Close() + content, err := io.ReadAll(file) + if err != nil { + _logger.Error("failed to read app management config file: %s", err) + return err + } + + newContent := string(content) + newContent += fmt.Sprintf("\nappstore = %s", bigBearAppStoreUrl) + + _, err = file.WriteString(newContent) + if err != nil { + _logger.Error("failed to write app management config file: %s", err) + return err + } + + return nil +} + +func (u *migrationTool0412AndOlder) PostMigrate() error { + return nil +} + +func NewMigration0412AndOlder() interfaces.MigrationTool { + return &migrationTool0412AndOlder{} +} diff --git a/pkg/config/init.go b/pkg/config/init.go index 9f6d6ff3..7d3eeb25 100644 --- a/pkg/config/init.go +++ b/pkg/config/init.go @@ -41,6 +41,18 @@ var ( GlobalEnvFilePath string ) +func ReloadConfig() { + var err error + Cfg, err = ini.LoadSources(ini.LoadOptions{Insensitive: true, AllowShadows: true}, ConfigFilePath) + if err != nil { + fmt.Println("failed to reload config", err) + } else { + mapTo("common", CommonInfo) + mapTo("app", AppInfo) + mapTo("server", ServerInfo) + } +} + func InitSetup(config string, sample string) { ConfigFilePath = AppManagementConfigFilePath if len(config) > 0 { diff --git a/service/appstore_management.go b/service/appstore_management.go index e3151097..494fc14f 100644 --- a/service/appstore_management.go +++ b/service/appstore_management.go @@ -423,6 +423,10 @@ func (a *AppStoreManagement) Catalog() (map[string]*ComposeApp, error) { } func (a *AppStoreManagement) UpdateCatalog() error { + // reload config. + // the appstore may be change in runtime. + config.ReloadConfig() + appStoreMap, err := a.AppStoreMap() if err != nil { return err