2020-01-12 22:32:36 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
// Daniele Rondina <geaaru@sabayonlinux.org>
|
2021-12-18 15:31:53 +00:00
|
|
|
// Copyright © 2021 Ettore Di Giacinto <mudler@mocaccino.org>
|
2020-01-12 22:32:36 +00:00
|
|
|
//
|
|
|
|
// 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_repo
|
|
|
|
|
|
|
|
import (
|
2021-10-20 22:13:02 +00:00
|
|
|
"github.com/mudler/luet/cmd/util"
|
2020-01-12 22:32:36 +00:00
|
|
|
installer "github.com/mudler/luet/pkg/installer"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewRepoUpdateCommand() *cobra.Command {
|
2021-12-18 15:31:53 +00:00
|
|
|
var repoUpdate = &cobra.Command{
|
2020-01-12 22:32:36 +00:00
|
|
|
Use: "update [repo1] [repo2] [OPTIONS]",
|
|
|
|
Short: "Update a specific cached repository or all cached repositories.",
|
|
|
|
Example: `
|
|
|
|
# Update all cached repositories:
|
|
|
|
$> luet repo update
|
|
|
|
|
|
|
|
# Update only repo1 and repo2
|
|
|
|
$> luet repo update repo1 repo2
|
|
|
|
`,
|
2020-05-10 18:24:08 +00:00
|
|
|
Aliases: []string{"up"},
|
2020-01-12 22:32:36 +00:00
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
ignore, _ := cmd.Flags().GetBool("ignore-errors")
|
|
|
|
force, _ := cmd.Flags().GetBool("force")
|
|
|
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
for _, rname := range args {
|
2021-10-20 22:13:02 +00:00
|
|
|
repo, err := util.DefaultContext.Config.GetSystemRepository(rname)
|
2020-01-12 22:32:36 +00:00
|
|
|
if err != nil && !ignore {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal(err.Error())
|
2020-01-12 22:32:36 +00:00
|
|
|
} else if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
r := installer.NewSystemRepository(*repo)
|
2021-10-20 22:13:02 +00:00
|
|
|
_, err = r.Sync(util.DefaultContext, force)
|
2020-01-12 22:32:36 +00:00
|
|
|
if err != nil && !ignore {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error on sync repository " + rname + ": " + err.Error())
|
2020-01-12 22:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2021-10-20 22:13:02 +00:00
|
|
|
for _, repo := range util.DefaultContext.Config.SystemRepositories {
|
2020-03-23 22:40:27 +00:00
|
|
|
if repo.Cached && repo.Enable {
|
2020-01-12 22:32:36 +00:00
|
|
|
r := installer.NewSystemRepository(repo)
|
2021-10-20 22:13:02 +00:00
|
|
|
_, err := r.Sync(util.DefaultContext, force)
|
2020-01-12 22:32:36 +00:00
|
|
|
if err != nil && !ignore {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Error on sync repository " + r.GetName() + ": " + err.Error())
|
2020-01-12 22:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-12-18 15:31:53 +00:00
|
|
|
repoUpdate.Flags().BoolP("ignore-errors", "i", false, "Ignore errors on sync repositories.")
|
|
|
|
repoUpdate.Flags().BoolP("force", "f", true, "Force resync.")
|
2020-01-12 22:32:36 +00:00
|
|
|
|
2021-12-18 15:31:53 +00:00
|
|
|
return repoUpdate
|
2020-01-12 22:32:36 +00:00
|
|
|
}
|