mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-06 13:27:43 +08:00
fix: The version upgrade adds internationalization processing (#8621)
This commit is contained in:
parent
300680d08e
commit
6ecfb1f239
3 changed files with 40 additions and 8 deletions
|
@ -173,6 +173,17 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
|||
return
|
||||
}
|
||||
|
||||
if err := files.CopyItem(true, true, path.Join(tmpDir, "lang"), "/usr/local/bin"); err != nil {
|
||||
global.LOG.Errorf("Update language files failed: %v", err)
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
u.handleRollback(originalDir, 4)
|
||||
}
|
||||
if err := files.CopyItem(false, true, path.Join(tmpDir, "GeoIP.mmdb"), path.Join(global.CONF.Base.InstallDir, "1panel/geo")); err != nil {
|
||||
global.LOG.Warnf("Update GeoIP database failed: %v", err)
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
u.handleRollback(originalDir, 4)
|
||||
}
|
||||
|
||||
global.LOG.Info("upgrade successful!")
|
||||
go writeLogs(req.Version)
|
||||
_ = settingRepo.Update("SystemVersion", req.Version)
|
||||
|
@ -207,6 +218,9 @@ func (u *UpgradeService) handleBackup(originalDir string) error {
|
|||
if err := files.CopyItem(false, true, "/usr/local/bin/1pctl", originalDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyItem(true, true, "/usr/local/bin/lang", originalDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyItem(false, true, "/etc/systemd/system/1panel-core.service", originalDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -216,13 +230,16 @@ func (u *UpgradeService) handleBackup(originalDir string) error {
|
|||
if err := files.CopyItem(true, true, path.Join(global.CONF.Base.InstallDir, "1panel/db"), originalDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyItem(false, true, path.Join(global.CONF.Base.InstallDir, "1panel/geo/GeoIP.mmdb"), originalDir); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UpgradeService) handleRollback(originalDir string, errStep int) {
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
|
||||
dbPath := path.Join(global.CONF.Base.InstallDir, "1panel/db")
|
||||
dbPath := path.Join(global.CONF.Base.InstallDir, "1panel")
|
||||
if _, err := os.Stat(path.Join(originalDir, "db")); err == nil {
|
||||
if err := files.CopyItem(true, true, path.Join(originalDir, "db"), dbPath); err != nil {
|
||||
global.LOG.Errorf("rollback 1panel db failed, err: %v", err)
|
||||
|
@ -249,6 +266,15 @@ func (u *UpgradeService) handleRollback(originalDir string, errStep int) {
|
|||
if err := files.CopyItem(false, true, path.Join(originalDir, "1panel-agent.service"), "/etc/systemd/system"); err != nil {
|
||||
global.LOG.Errorf("rollback 1panel-agent.service failed, err: %v", err)
|
||||
}
|
||||
if errStep == 3 {
|
||||
return
|
||||
}
|
||||
if err := files.CopyItem(true, true, path.Join(originalDir, "lang"), "/usr/local/bin"); err != nil {
|
||||
global.LOG.Errorf("rollback language files failed, err: %v", err)
|
||||
}
|
||||
if err := files.CopyItem(false, true, path.Join(originalDir, "GeoIP.mmdb"), path.Join(global.CONF.Base.InstallDir, "1panel/geo")); err != nil {
|
||||
global.LOG.Errorf("rollback GeoIP database failed, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UpgradeService) loadVersionByMode(developer, currentVersion string) (string, string, string) {
|
||||
|
|
|
@ -46,17 +46,23 @@ var restoreCmd = &cobra.Command{
|
|||
tmpPath = path.Join(upgradeDir, tmpPath, "original")
|
||||
|
||||
fmt.Println(i18n.GetMsgWithMapForCmd("RestoreStep1", map[string]interface{}{"name": tmpPath}))
|
||||
if err := files.CopyFile(path.Join(tmpPath, "1panel-agent"), "/usr/local/bin/1panel-agent", true); err != nil {
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "1panel-agent"), "/usr/local/bin"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyFile(path.Join(tmpPath, "1panel-core"), "/usr/local/bin/1panel-core", true); err != nil {
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "1panel-core"), "/usr/local/bin"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyItem(true, true, path.Join(tmpPath, "lang"), "/usr/local/bin"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "GeoIP.mmdb"), path.Join(baseDir, "1panel/geo")); err != nil {
|
||||
return err
|
||||
}
|
||||
sudo := cmdUtils.SudoHandleCmd()
|
||||
_, _ = cmdUtils.RunDefaultWithStdoutBashCf("%s chmod 755 /usr/local/bin/1panel-agent /usr/local/bin/1panel-core", sudo)
|
||||
|
||||
fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep2"))
|
||||
if err := files.CopyFile(path.Join(tmpPath, "1pctl"), "/usr/local/bin/1pctl", true); err != nil {
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "1pctl"), "/usr/local/bin"); err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = cmdUtils.RunDefaultWithStdoutBashCf("%s chmod 755 /usr/local/bin/1pctl", sudo)
|
||||
|
@ -65,10 +71,10 @@ var restoreCmd = &cobra.Command{
|
|||
_, _ = cmdUtils.RunDefaultWithStdoutBashCf("mkdir %s && cp %s %s/", geoPath, path.Join(tmpPath, "GeoIP.mmdb"), geoPath)
|
||||
|
||||
fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep3"))
|
||||
if err := files.CopyFile(path.Join(tmpPath, "1panel-core.service"), "/etc/systemd/system/1panel-core.service", true); err != nil {
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "1panel-core.service"), "/etc/systemd/system"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := files.CopyFile(path.Join(tmpPath, "1panel-agent.service"), "/etc/systemd/system/1panel-agent.service", true); err != nil {
|
||||
if err := files.CopyItem(false, true, path.Join(tmpPath, "1panel-agent.service"), "/etc/systemd/system"); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep4"))
|
||||
|
|
|
@ -57,9 +57,9 @@ func CopyItem(isDir, withName bool, src, dst string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(path.Dir(dst)); err != nil {
|
||||
if _, err := os.Stat(dst); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
_ = os.MkdirAll(path.Dir(dst), srcInfo.Mode())
|
||||
_ = os.MkdirAll(dst, srcInfo.Mode())
|
||||
}
|
||||
}
|
||||
cmdStr := fmt.Sprintf(`cp -rf %s %s`, src, dst+"/")
|
||||
|
|
Loading…
Add table
Reference in a new issue