2019-11-29 18:01:58 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-08-03 14:48:29 +00:00
|
|
|
"github.com/mudler/luet/cmd/util"
|
2022-01-06 22:57:56 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
2020-01-02 17:31:25 +00:00
|
|
|
installer "github.com/mudler/luet/pkg/installer"
|
2019-11-29 18:01:58 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2021-10-19 20:26:23 +00:00
|
|
|
"github.com/spf13/viper"
|
2019-11-29 18:01:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var upgradeCmd = &cobra.Command{
|
2020-05-10 18:24:08 +00:00
|
|
|
Use: "upgrade",
|
|
|
|
Short: "Upgrades the system",
|
|
|
|
Aliases: []string{"u"},
|
2019-11-29 18:01:58 +00:00
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
2021-12-17 14:21:03 +00:00
|
|
|
|
2021-10-19 20:26:23 +00:00
|
|
|
viper.BindPFlag("force", cmd.Flags().Lookup("force"))
|
|
|
|
viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
2019-11-29 18:01:58 +00:00
|
|
|
},
|
|
|
|
Long: `Upgrades packages in parallel`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
2021-10-19 20:26:23 +00:00
|
|
|
force := viper.GetBool("force")
|
2020-05-20 21:24:32 +00:00
|
|
|
nodeps, _ := cmd.Flags().GetBool("nodeps")
|
|
|
|
full, _ := cmd.Flags().GetBool("full")
|
2020-05-22 18:45:28 +00:00
|
|
|
universe, _ := cmd.Flags().GetBool("universe")
|
|
|
|
clean, _ := cmd.Flags().GetBool("clean")
|
2020-07-12 13:27:50 +00:00
|
|
|
sync, _ := cmd.Flags().GetBool("sync")
|
2021-12-12 09:42:51 +00:00
|
|
|
osCheck, _ := cmd.Flags().GetBool("oscheck")
|
|
|
|
|
2021-10-19 20:26:23 +00:00
|
|
|
yes := viper.GetBool("yes")
|
2021-03-07 10:39:19 +00:00
|
|
|
downloadOnly, _ := cmd.Flags().GetBool("download-only")
|
2020-02-12 11:24:07 +00:00
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
util.DefaultContext.Config.Solver.Implementation = types.SolverSingleCoreSimple
|
2020-02-12 11:24:07 +00:00
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
util.DefaultContext.Debug("Solver", util.DefaultContext.GetConfig().Solver)
|
2020-11-06 22:30:08 +00:00
|
|
|
|
2020-02-18 17:37:56 +00:00
|
|
|
inst := installer.NewLuetInstaller(installer.LuetInstallerOptions{
|
2021-12-17 14:21:03 +00:00
|
|
|
Concurrency: util.DefaultContext.Config.General.Concurrency,
|
|
|
|
SolverOptions: util.DefaultContext.Config.Solver,
|
2020-12-09 20:07:50 +00:00
|
|
|
Force: force,
|
|
|
|
FullUninstall: full,
|
|
|
|
NoDeps: nodeps,
|
|
|
|
SolverUpgrade: universe,
|
|
|
|
RemoveUnavailableOnUpgrade: clean,
|
|
|
|
UpgradeNewRevisions: sync,
|
|
|
|
PreserveSystemEssentialData: true,
|
|
|
|
Ask: !yes,
|
2021-12-12 09:42:51 +00:00
|
|
|
AutoOSCheck: osCheck,
|
2021-03-07 10:39:19 +00:00
|
|
|
DownloadOnly: downloadOnly,
|
2021-10-20 22:13:02 +00:00
|
|
|
PackageRepositories: util.DefaultContext.Config.SystemRepositories,
|
|
|
|
Context: util.DefaultContext,
|
2020-02-18 17:37:56 +00:00
|
|
|
})
|
2019-11-29 18:01:58 +00:00
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
system := &installer.System{Database: util.SystemDB(util.DefaultContext.Config), Target: util.DefaultContext.Config.System.Rootfs}
|
2020-11-23 17:20:30 +00:00
|
|
|
if err := inst.Upgrade(system); err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error: " + err.Error())
|
2019-11-29 18:01:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-02-18 17:37:56 +00:00
|
|
|
upgradeCmd.Flags().Bool("force", false, "Force upgrade by ignoring errors")
|
2020-05-20 21:24:32 +00:00
|
|
|
upgradeCmd.Flags().Bool("nodeps", false, "Don't consider package dependencies (harmful! overrides checkconflicts and full!)")
|
2020-12-06 23:48:28 +00:00
|
|
|
upgradeCmd.Flags().Bool("full", false, "Attempts to remove as much packages as possible which aren't required (slow)")
|
2020-05-22 18:45:28 +00:00
|
|
|
upgradeCmd.Flags().Bool("universe", false, "Use ONLY the SAT solver to compute upgrades (experimental)")
|
|
|
|
upgradeCmd.Flags().Bool("clean", false, "Try to drop removed packages (experimental, only when --universe is enabled)")
|
2020-07-12 13:27:50 +00:00
|
|
|
upgradeCmd.Flags().Bool("sync", false, "Upgrade packages with new revisions (experimental)")
|
2020-10-25 17:43:35 +00:00
|
|
|
upgradeCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)")
|
2020-11-22 19:16:04 +00:00
|
|
|
upgradeCmd.Flags().BoolP("yes", "y", false, "Don't ask questions")
|
2021-03-07 10:39:19 +00:00
|
|
|
upgradeCmd.Flags().Bool("download-only", false, "Download only")
|
2021-12-12 09:42:51 +00:00
|
|
|
upgradeCmd.Flags().Bool("oscheck", false, "Perform automatically oschecks after upgrades")
|
2020-02-18 17:37:56 +00:00
|
|
|
|
2019-11-29 18:01:58 +00:00
|
|
|
RootCmd.AddCommand(upgradeCmd)
|
|
|
|
}
|