2019-11-24 17:28:39 +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 (
|
2020-05-23 06:51:33 +00:00
|
|
|
helpers "github.com/mudler/luet/cmd/helpers"
|
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-24 17:28:39 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2021-10-19 20:26:23 +00:00
|
|
|
"github.com/spf13/viper"
|
2019-11-24 17:28:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var uninstallCmd = &cobra.Command{
|
2020-05-10 18:24:08 +00:00
|
|
|
Use: "uninstall <pkg> <pkg2> ...",
|
|
|
|
Short: "Uninstall a package or a list of packages",
|
|
|
|
Long: `Uninstall packages`,
|
|
|
|
Aliases: []string{"rm", "un"},
|
2019-11-25 18:55:30 +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("nodeps", cmd.Flags().Lookup("nodeps"))
|
|
|
|
viper.BindPFlag("force", cmd.Flags().Lookup("force"))
|
|
|
|
viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
2019-11-25 18:55:30 +00:00
|
|
|
},
|
2019-11-24 17:28:39 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2022-01-06 22:57:56 +00:00
|
|
|
toRemove := []*types.Package{}
|
2019-12-27 14:20:10 +00:00
|
|
|
for _, a := range args {
|
2020-02-21 20:56:32 +00:00
|
|
|
|
|
|
|
pack, err := helpers.ParsePackageStr(a)
|
2019-12-27 14:20:10 +00:00
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Invalid package string ", a, ": ", err.Error())
|
2019-12-27 14:20:10 +00:00
|
|
|
}
|
2020-12-19 16:16:53 +00:00
|
|
|
toRemove = append(toRemove, pack)
|
|
|
|
}
|
2019-11-24 17:28:39 +00:00
|
|
|
|
2021-10-19 20:26:23 +00:00
|
|
|
force := viper.GetBool("force")
|
2020-12-19 16:16:53 +00:00
|
|
|
nodeps, _ := cmd.Flags().GetBool("nodeps")
|
|
|
|
full, _ := cmd.Flags().GetBool("full")
|
|
|
|
checkconflicts, _ := cmd.Flags().GetBool("conflictscheck")
|
|
|
|
fullClean, _ := cmd.Flags().GetBool("full-clean")
|
2021-10-19 20:26:23 +00:00
|
|
|
yes := viper.GetBool("yes")
|
2021-07-11 08:21:35 +00:00
|
|
|
keepProtected, _ := cmd.Flags().GetBool("keep-protected-files")
|
2021-03-06 09:21:49 +00:00
|
|
|
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Config.ConfigProtectSkip = !keepProtected
|
2021-10-09 15:58:10 +00:00
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
util.DefaultContext.Config.Solver.Implementation = types.SolverSingleCoreSimple
|
2021-10-09 15:58:10 +00:00
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
util.DefaultContext.Debug("Solver", util.DefaultContext.Config.Solver.CompactString())
|
2020-11-06 22:30:08 +00:00
|
|
|
|
2020-12-19 16:16:53 +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-19 16:16:53 +00:00
|
|
|
NoDeps: nodeps,
|
|
|
|
Force: force,
|
|
|
|
FullUninstall: full,
|
|
|
|
FullCleanUninstall: fullClean,
|
|
|
|
CheckConflicts: checkconflicts,
|
|
|
|
Ask: !yes,
|
|
|
|
PreserveSystemEssentialData: true,
|
2021-10-20 22:13:02 +00:00
|
|
|
Context: util.DefaultContext,
|
2020-12-19 16:16:53 +00:00
|
|
|
})
|
2019-11-24 17:28:39 +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-12-19 16:16:53 +00:00
|
|
|
|
|
|
|
if err := inst.Uninstall(system, toRemove...); err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error: " + err.Error())
|
2019-11-24 17:28:39 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-03-06 09:21:49 +00:00
|
|
|
|
2020-05-03 10:16:45 +00:00
|
|
|
uninstallCmd.Flags().Bool("nodeps", false, "Don't consider package dependencies (harmful! overrides checkconflicts and full!)")
|
2020-02-18 17:37:56 +00:00
|
|
|
uninstallCmd.Flags().Bool("force", false, "Force uninstall")
|
2020-05-03 10:16:45 +00:00
|
|
|
uninstallCmd.Flags().Bool("full", false, "Attempts to remove as much packages as possible which aren't required (slow)")
|
|
|
|
uninstallCmd.Flags().Bool("conflictscheck", true, "Check if the package marked for deletion is required by other packages")
|
2020-05-22 18:45:28 +00:00
|
|
|
uninstallCmd.Flags().Bool("full-clean", false, "(experimental) Uninstall packages and all the other deps/revdeps of it.")
|
2020-10-25 17:43:35 +00:00
|
|
|
uninstallCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)")
|
2020-11-22 19:16:04 +00:00
|
|
|
uninstallCmd.Flags().BoolP("yes", "y", false, "Don't ask questions")
|
2021-07-11 08:21:35 +00:00
|
|
|
uninstallCmd.Flags().BoolP("keep-protected-files", "k", false, "Keep package protected files around")
|
2020-02-18 17:37:56 +00:00
|
|
|
|
2019-11-24 17:28:39 +00:00
|
|
|
RootCmd.AddCommand(uninstallCmd)
|
|
|
|
}
|