2021-12-05 22:04:47 +00:00
|
|
|
// Copyright © 2021 Ettore Di Giacinto <mudler@mocaccino.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 (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
2021-12-05 22:04:47 +00:00
|
|
|
installer "github.com/mudler/luet/pkg/installer"
|
|
|
|
|
|
|
|
"github.com/mudler/luet/cmd/util"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var osCheckCmd = &cobra.Command{
|
|
|
|
Use: "oscheck",
|
|
|
|
Short: "Checks packages integrity",
|
|
|
|
Long: `List packages that are installed in the system which files are missing in the system.
|
|
|
|
|
|
|
|
$ luet oscheck
|
|
|
|
|
|
|
|
To reinstall packages in the list:
|
|
|
|
|
|
|
|
$ luet oscheck --reinstall
|
|
|
|
`,
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps"))
|
|
|
|
viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps"))
|
|
|
|
viper.BindPFlag("force", cmd.Flags().Lookup("force"))
|
|
|
|
viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
force := viper.GetBool("force")
|
|
|
|
onlydeps := viper.GetBool("onlydeps")
|
|
|
|
yes := viper.GetBool("yes")
|
|
|
|
|
|
|
|
downloadOnly, _ := cmd.Flags().GetBool("download-only")
|
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
system := &installer.System{
|
2022-01-06 22:57:56 +00:00
|
|
|
Database: util.SystemDB(util.DefaultContext.Config),
|
2021-12-17 14:21:03 +00:00
|
|
|
Target: util.DefaultContext.Config.System.Rootfs,
|
|
|
|
}
|
2021-12-24 11:07:08 +00:00
|
|
|
packs := system.OSCheck(util.DefaultContext)
|
2021-12-05 22:04:47 +00:00
|
|
|
if !util.DefaultContext.Config.General.Quiet {
|
|
|
|
if len(packs) == 0 {
|
|
|
|
util.DefaultContext.Success("All good!")
|
|
|
|
os.Exit(0)
|
|
|
|
} else {
|
|
|
|
util.DefaultContext.Info("Following packages are missing files or are incomplete:")
|
|
|
|
for _, p := range packs {
|
|
|
|
util.DefaultContext.Info(p.HumanReadableString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var s []string
|
|
|
|
for _, p := range packs {
|
|
|
|
s = append(s, p.HumanReadableString())
|
|
|
|
}
|
|
|
|
fmt.Println(strings.Join(s, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
reinstall, _ := cmd.Flags().GetBool("reinstall")
|
|
|
|
if reinstall {
|
|
|
|
|
|
|
|
// Strip version for reinstall
|
2022-01-06 22:57:56 +00:00
|
|
|
toInstall := types.Packages{}
|
2021-12-05 22:04:47 +00:00
|
|
|
for _, p := range packs {
|
|
|
|
new := p.Clone()
|
|
|
|
new.SetVersion(">=0")
|
|
|
|
toInstall = append(toInstall, new)
|
|
|
|
}
|
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
util.DefaultContext.Debug("Solver", util.DefaultContext.Config.Solver.CompactString())
|
2021-12-05 22:04:47 +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,
|
2021-12-05 22:04:47 +00:00
|
|
|
NoDeps: true,
|
|
|
|
Force: force,
|
|
|
|
OnlyDeps: onlydeps,
|
|
|
|
PreserveSystemEssentialData: true,
|
|
|
|
Ask: !yes,
|
|
|
|
DownloadOnly: downloadOnly,
|
|
|
|
Context: util.DefaultContext,
|
|
|
|
PackageRepositories: util.DefaultContext.Config.SystemRepositories,
|
|
|
|
})
|
|
|
|
|
|
|
|
err := inst.Swap(packs, toInstall, system)
|
|
|
|
if err != nil {
|
|
|
|
util.DefaultContext.Fatal("Error: " + err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-12-17 14:21:03 +00:00
|
|
|
|
2021-12-05 22:04:47 +00:00
|
|
|
osCheckCmd.Flags().Bool("reinstall", false, "reinstall")
|
|
|
|
|
|
|
|
osCheckCmd.Flags().Bool("onlydeps", false, "Consider **only** package dependencies")
|
|
|
|
osCheckCmd.Flags().Bool("force", false, "Skip errors and keep going (potentially harmful)")
|
|
|
|
osCheckCmd.Flags().BoolP("yes", "y", false, "Don't ask questions")
|
|
|
|
osCheckCmd.Flags().Bool("download-only", false, "Download only")
|
|
|
|
|
|
|
|
RootCmd.AddCommand(osCheckCmd)
|
|
|
|
}
|