Skip to content

CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.

wip

Tiger Wang0f3d3e82f56d
diff --git a/build/scripts/migration/script.d/03-migrate-casaos.sh b/build/scripts/migration/script.d/03-migrate-casaos.sh
index a48c437..719ff60 100644
--- a/build/scripts/migration/script.d/03-migrate-casaos.sh
+++ b/build/scripts/migration/script.d/03-migrate-casaos.sh
@@ -60,8 +60,6 @@ BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
SOURCE_ROOT=${BUILD_PATH}/sysroot
APP_NAME="casaos"
-APP_NAME_FORMAL="CasaOS"
-#APP_NAME_FORMAL="casaos-alpha"
# check if migration is needed
SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin
@@ -85,6 +83,25 @@ if [ "${NEED_MIGRATION}" = "false" ]; then
exit 0
fi
+ARCH="unknown"
+
+case $(uname -m) in
+ x86_64)
+ ARCH="amd64"
+ ;;
+ aarch64)
+ ARCH="arm64"
+ ;;
+ armv7l)
+ ARCH="arm-7"
+ ;;
+ *)
+ __error "Unsupported architecture"
+ ;;
+esac
+
+__info "ARCH: ${ARCH}"
+
MIGRATION_SERVICE_DIR=${1}
if [ -z "${MIGRATION_SERVICE_DIR}" ]; then
@@ -95,10 +112,10 @@ MIGRATION_PATH=()
CURRENT_VERSION_FOUND="false"
-# a VERSION_PAIR looks like "v0.3.5 v0.3.6-alpha2"
+# a VERSION_PAIR looks like "v0.3.5 <url>"
#
# - "v0.3.5" is the current version installed on this host
-# - "v0.3.6-alpha2" is the version of the migration tool from GitHub
+# - "<url>" is the url of the migration tool
while read -r VERSION_PAIR; do
if [ -z "${VERSION_PAIR}" ]; then
continue
@@ -107,15 +124,15 @@ while read -r VERSION_PAIR; do
# obtain "v0.3.5" from "v0.3.5 v0.3.6-alpha2"
VER1=$(echo "${VERSION_PAIR}" | cut -d' ' -f1)
- # obtain "v0.3.6-alpha2" from "v0.3.5 v0.3.6-alpha2"
- VER2=$(echo "${VERSION_PAIR}" | cut -d' ' -f2)
+ # obtain "<url>" from "v0.3.5 <url>"
+ URL=$(eval echo "${VERSION_PAIR}" | cut -d' ' -f2)
if [ "${CURRENT_VERSION}" = "${VER1// /}" ] || [ "${CURRENT_VERSION}" = "LEGACY_WITHOUT_VERSION" ]; then
CURRENT_VERSION_FOUND="true"
fi
if [ "${CURRENT_VERSION_FOUND}" = "true" ]; then
- MIGRATION_PATH+=("${VER2// /}")
+ MIGRATION_PATH+=("${URL// /}")
fi
done < "${MIGRATION_LIST_FILE}"
@@ -124,39 +141,18 @@ if [ ${#MIGRATION_PATH[@]} -eq 0 ]; then
exit 0
fi
-ARCH="unknown"
-
-case $(uname -m) in
- x86_64)
- ARCH="amd64"
- ;;
- aarch64)
- ARCH="arm64"
- ;;
- armv7l)
- ARCH="arm-7"
- ;;
- *)
- __error "Unsupported architecture"
- ;;
-esac
-
pushd "${MIGRATION_SERVICE_DIR}"
-{ for VER2 in "${MIGRATION_PATH[@]}"; do
-
-
- MIGRATION_TOOL_FILE=linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
+{ for URL in "${MIGRATION_PATH[@]}"; do
+ MIGRATION_TOOL_FILE=$(basename "${URL}")
if [ -f "${MIGRATION_TOOL_FILE}" ]; then
__info "Migration tool ${MIGRATION_TOOL_FILE} exists. Skip downloading."
continue
fi
- # MIGRATION_TOOL_URL=http://192.168.2.197:8000/v1/package/migration?type=release&name="${APP_NAME_FORMAL}"&version=${VER2}&arch=${ARCH}
- MIGRATION_TOOL_URL=https://github.com/IceWhaleTech/"${APP_NAME_FORMAL}"/releases/download/"${VER2}"/linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
- echo "Dowloading ${MIGRATION_TOOL_URL}..."
- curl -sL -O "${MIGRATION_TOOL_URL}"
+ __info "Dowloading ${URL}..."
+ curl -fsSL -o "${MIGRATION_TOOL_FILE}" -O "${URL}"
done
} || {
popd
@@ -164,8 +160,8 @@ pushd "${MIGRATION_SERVICE_DIR}"
}
{
- for VER2 in "${MIGRATION_PATH[@]}"; do
- MIGRATION_TOOL_FILE=linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
+ for URL in "${MIGRATION_PATH[@]}"; do
+ MIGRATION_TOOL_FILE=$(basename "${URL}")
__info "Extracting ${MIGRATION_TOOL_FILE}..."
tar zxvf "${MIGRATION_TOOL_FILE}" || __error "Failed to extract ${MIGRATION_TOOL_FILE}"
diff --git a/build/scripts/migration/service.d/casaos/migration.list b/build/scripts/migration/service.d/casaos/migration.list
index d3ce03f..c780280 100644
--- a/build/scripts/migration/service.d/casaos/migration.list
+++ b/build/scripts/migration/service.d/casaos/migration.list
@@ -1,4 +1,3 @@
-LEGACY_WITHOUT_VERSION v0.3.6
-v0.3.5 v0.3.6
-v0.3.5.1 v0.3.6
-v0.3.6 v0.3.7
+LEGACY_WITHOUT_VERSION https://github.com/IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
+v0.3.5 https://github.com/IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
+v0.3.5.1 https://github.com/IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
diff --git a/cmd/migration-tool/main.go b/cmd/migration-tool/main.go
index 93b065d..d28663c0 100644
--- a/cmd/migration-tool/main.go
+++ b/cmd/migration-tool/main.go
@@ -83,8 +83,7 @@ func main() {
}
migrationTools := []interfaces.MigrationTool{
- NewMigrationToolFor_035(),
- NewMigrationToolFor_036(),
+ // nothing to migrate from last version
}
var selectedMigrationTool interfaces.MigrationTool
@@ -115,8 +114,7 @@ func main() {
panic(err)
}
- selectedMigrationTool.PostMigrate()
- _logger.Info("casaos migration ok")
- // panic(err)
-
+ if err := selectedMigrationTool.PostMigrate(); err != nil {
+ _logger.Error("Migration succeeded, but post-migration failed: %s", err)
+ }
}
diff --git a/cmd/migration-tool/migration-034-035.go b/cmd/migration-tool/migration-034-035.go
deleted file mode 100644
index 3dfed60..0000000
--- a/cmd/migration-tool/migration-034-035.go
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * @Author: LinkLeong [email protected]
- * @Date: 2022-08-24 17:36:00
- * @LastEditors: LinkLeong
- * @LastEditTime: 2022-09-05 11:24:27
- * @FilePath: /CasaOS/cmd/migration-tool/migration-034-035.go
- * @Description:
- * @Website: https://www.casaos.io
- * Copyright (c) 2022 by icewhale, All Rights Reserved.
- */
-package main
-
-import (
- "io"
- "io/ioutil"
- "os"
- "path"
- "strings"
-
- interfaces "github.com/IceWhaleTech/CasaOS-Common"
- "github.com/IceWhaleTech/CasaOS-Common/utils/version"
- "github.com/IceWhaleTech/CasaOS/pkg/config"
- "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
- "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
- "github.com/IceWhaleTech/CasaOS/service"
-)
-
-type migrationTool036 struct{}
-
-func (u *migrationTool036) IsMigrationNeeded() (bool, error) {
-
- majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
- if err != nil {
- if err == version.ErrLegacyVersionNotFound {
- return false, nil
- }
-
- return false, err
- }
-
- if majorVersion > 0 {
- return false, nil
- }
-
- if minorVersion > 3 {
- return false, nil
- }
-
- if minorVersion == 3 && patchVersion > 5 {
- return false, nil
- }
-
- _logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
- return true, nil
-
-}
-
-func (u *migrationTool036) PreMigrate() error {
-
- return nil
-}
-
-func (u *migrationTool036) Migrate() error {
-
- if service.MyService.System().GetSysInfo().KernelArch == "aarch64" && config.ServerInfo.USBAutoMount != "True" && strings.Contains(service.MyService.System().GetDeviceTree(), "Raspberry Pi") {
- service.MyService.System().UpdateUSBAutoMount("False")
- service.MyService.System().ExecUSBAutoMountShell("False")
- }
- newAPIUrl := "https://api.casaos.io/casaos-api"
- if config.ServerInfo.ServerApi == "https://api.casaos.zimaboard.com" {
- config.ServerInfo.ServerApi = newAPIUrl
- config.Cfg.Section("server").Key("ServerApi").SetValue(newAPIUrl)
- config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
- }
- command.OnlyExec("curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/assist.sh | bash")
- if !file.CheckNotExist("/casaOS") {
- command.OnlyExec("source /casaOS/server/shell/update.sh ;")
- command.OnlyExec("source " + config.AppInfo.ShellPath + "/delete-old-service.sh ;")
- }
-
- service.MyService.App().ImportApplications(true)
-
- src := "/casaOS/server/conf/conf.ini"
- if file.Exists(src) {
- dst := "/etc/casaos/casaos.conf"
- source, err := os.Open(src)
- if err != nil {
- return err
- }
- defer source.Close()
-
- destination, err := os.Create(dst)
- if err != nil {
- return err
- }
- defer destination.Close()
- _, err = io.Copy(destination, source)
- if err != nil {
- return err
- }
-
- }
-
- if file.Exists("/casaOS/server/db") {
- var fds []os.FileInfo
- var err error
- to := "/var/lib/casaos/db"
- file.IsNotExistMkDir(to)
- from := "/casaOS/server/db"
- if fds, err = ioutil.ReadDir(from); err != nil {
- return err
- }
-
- for _, fd := range fds {
- srcfp := path.Join(from, fd.Name())
- dstfp := path.Join(to, fd.Name())
- source, err := os.Open(srcfp)
- if err != nil {
- return err
- }
- defer source.Close()
-
- destination, err := os.Create(dstfp)
- if err != nil {
- return err
- }
- defer destination.Close()
- _, err = io.Copy(destination, source)
- if err != nil {
- return err
- }
- }
-
- }
-
- if file.Exists("/casaOS/server/conf") {
- var fds []os.FileInfo
- var err error
- to := "/var/lib/casaos/conf"
- file.IsNotExistMkDir(to)
- from := "/casaOS/server/conf"
- if fds, err = ioutil.ReadDir(from); err != nil {
- return err
- }
-
- for _, fd := range fds {
- fExt := path.Ext(fd.Name())
- if fExt != ".json" {
- continue
- }
- srcfp := path.Join(from, fd.Name())
- dstfp := path.Join(to, fd.Name())
- source, err := os.Open(srcfp)
- if err != nil {
- return err
- }
- defer source.Close()
-
- destination, err := os.Create(dstfp)
- if err != nil {
- return err
- }
- defer destination.Close()
- _, err = io.Copy(destination, source)
- if err != nil {
- return err
- }
- }
-
- }
-
- _logger.Info("update done")
- return nil
-}
-
-func (u *migrationTool036) PostMigrate() error {
- return nil
-}
-
-func NewMigrationToolFor_035() interfaces.MigrationTool {
- return &migrationTool{}
-}
diff --git a/cmd/migration-tool/migration-036.go b/cmd/migration-tool/migration-036.go
deleted file mode 100644
index b6d5410..0000000
--- a/cmd/migration-tool/migration-036.go
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * @Author: LinkLeong [email protected]
- * @Date: 2022-08-24 17:36:00
- * @LastEditors: LinkLeong
- * @LastEditTime: 2022-09-05 11:24:27
- * @FilePath: /CasaOS/cmd/migration-tool/migration-034-035.go
- * @Description:
- * @Website: https://www.casaos.io
- * Copyright (c) 2022 by icewhale, All Rights Reserved.
- */
-package main
-
-import (
- "strings"
-
- interfaces "github.com/IceWhaleTech/CasaOS-Common"
- "github.com/IceWhaleTech/CasaOS-Common/utils/version"
- "github.com/IceWhaleTech/CasaOS/pkg/config"
- "github.com/IceWhaleTech/CasaOS/service"
-)
-
-type migrationTool struct{}
-
-func (u *migrationTool) IsMigrationNeeded() (bool, error) {
-
- majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
- if err != nil {
- if err == version.ErrLegacyVersionNotFound {
- return false, nil
- }
-
- return false, err
- }
-
- if majorVersion > 0 {
- return false, nil
- }
-
- if minorVersion > 3 {
- return false, nil
- }
-
- if minorVersion == 3 && patchVersion > 5 {
- return false, nil
- }
-
- _logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
- return true, nil
-
-}
-
-func (u *migrationTool) PreMigrate() error {
-
- return nil
-}
-
-func (u *migrationTool) Migrate() error {
-
- if service.MyService.System().GetSysInfo().KernelArch == "aarch64" && config.ServerInfo.USBAutoMount != "True" && strings.Contains(service.MyService.System().GetDeviceTree(), "Raspberry Pi") {
- service.MyService.System().UpdateUSBAutoMount("False")
- service.MyService.System().ExecUSBAutoMountShell("False")
- }
-
- _logger.Info("update done")
- return nil
-}
-
-func (u *migrationTool) PostMigrate() error {
- return nil
-}
-
-func NewMigrationToolFor_036() interfaces.MigrationTool {
- return &migrationTool{}
-}