Skip to content

Commit

Permalink
feat: add big bear as default app store source (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Sep 25, 2024
1 parent fba013f commit 135f8ba
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/sysroot/etc/casaos/app-management.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions cmd/migration-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func main() {
migrationTools := []interfaces.MigrationTool{
// NewMigrationDummy(),
NewMigration044AndOlder(),
NewMigration0412AndOlder(),
}

var selectedMigrationTool interfaces.MigrationTool
Expand Down
77 changes: 77 additions & 0 deletions cmd/migration-tool/migration_0412_and_older.go
Original file line number Diff line number Diff line change
@@ -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{}
}
12 changes: 12 additions & 0 deletions pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions service/appstore_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 135f8ba

Please sign in to comment.