381fb85b1d
* add send notify function * add shell script * add system notiry * remove disk and test common package * update http status * add share function to common * remove temp path * remove /DATA directory initialization - moved to local-storage (#578) * update goreleaser configuration * wip * change service type to notify for systemd so its status is OK only when service is initialized successfully * update CasaOS-Common to fix runtime error * wip * add send notify function * add shell script * add system notiry * remove disk and test common package * update http status * add share function to common * remove temp path * remove /DATA directory initialization - moved to local-storage (#578) * update goreleaser configuration * wip * change service type to notify for systemd so its status is OK only when service is initialized successfully * update CasaOS-Common to fix runtime error * wip * wip * wip * wip * wip * Utilization interface to supplement disk information * fix upload file * wip * wip * add update url * wip * wip * add change log * update changelog Co-authored-by: LinkLeong <a624669980@163.com>
120 lines
2.4 KiB
Go
120 lines
2.4 KiB
Go
/*
|
|
* @Author: LinkLeong link@icewhale.org
|
|
* @Date: 2022-08-23 18:09:11
|
|
* @LastEditors: LinkLeong
|
|
* @LastEditTime: 2022-08-31 14:17:51
|
|
* @FilePath: /CasaOS/cmd/migration-tool/main.go
|
|
* @Description:
|
|
* @Website: https://www.casaos.io
|
|
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
interfaces "github.com/IceWhaleTech/CasaOS-Common"
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
|
|
"github.com/IceWhaleTech/CasaOS-Gateway/common"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
|
"github.com/IceWhaleTech/CasaOS/service"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const (
|
|
casaosServiceName = "casaos.service"
|
|
)
|
|
|
|
var (
|
|
_logger *Logger
|
|
sqliteDB *gorm.DB
|
|
)
|
|
|
|
var (
|
|
configFlag = ""
|
|
dbFlag = ""
|
|
)
|
|
|
|
func init() {
|
|
config.InitSetup(configFlag)
|
|
|
|
if len(dbFlag) == 0 {
|
|
dbFlag = config.AppInfo.DBPath + "/db"
|
|
}
|
|
|
|
sqliteDB = sqlite.GetDb(dbFlag)
|
|
// gredis.GetRedisConn(config.RedisInfo),
|
|
|
|
service.MyService = service.NewService(sqliteDB, "")
|
|
}
|
|
|
|
func main() {
|
|
versionFlag := flag.Bool("v", false, "version")
|
|
debugFlag := flag.Bool("d", true, "debug")
|
|
forceFlag := flag.Bool("f", true, "force")
|
|
flag.Parse()
|
|
_logger = NewLogger()
|
|
if *versionFlag {
|
|
fmt.Println(common.Version)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if os.Getuid() != 0 {
|
|
os.Exit(1)
|
|
}
|
|
|
|
if *debugFlag {
|
|
_logger.DebugMode = true
|
|
}
|
|
|
|
if !*forceFlag {
|
|
serviceEnabled, err := systemctl.IsServiceEnabled(casaosServiceName)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if serviceEnabled {
|
|
_logger.Info("%s is already enabled. If migration is still needed, try with -f.", casaosServiceName)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
migrationTools := []interfaces.MigrationTool{
|
|
// nothing to migrate from last version
|
|
}
|
|
|
|
var selectedMigrationTool interfaces.MigrationTool
|
|
|
|
// look for the right migration tool matching current version
|
|
for _, tool := range migrationTools {
|
|
migrationNeeded, err := tool.IsMigrationNeeded()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if migrationNeeded {
|
|
selectedMigrationTool = tool
|
|
break
|
|
}
|
|
}
|
|
|
|
if selectedMigrationTool == nil {
|
|
_logger.Error("selectedMigrationTool is null")
|
|
return
|
|
}
|
|
|
|
if err := selectedMigrationTool.PreMigrate(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err := selectedMigrationTool.Migrate(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err := selectedMigrationTool.PostMigrate(); err != nil {
|
|
_logger.Error("Migration succeeded, but post-migration failed: %s", err)
|
|
}
|
|
}
|