Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add big bear as default app store source #205

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading