Add mixer repo set-url capability

'mixer repo set-url' allows the user to set the url of a RPM repo to the
url they provide. This is helpful when users want to build mixes off a
mirror of upstream Clear Linux instead of the CDN when the CDN is slow.

mixer repo set-url clear <mirror-url>

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
This commit is contained in:
Matthew Johnson
2018-05-03 15:07:54 -07:00
parent d5114b6010
commit b67ab4e608
2 changed files with 58 additions and 6 deletions
+32 -5
View File
@@ -1663,14 +1663,14 @@ gpgcheck=0
priority=1
`
// AddRepo adds and enables a repo configuration named repoInfo[0] pointing at
// URL repoInfo[1]. It calls b.NewDNFConfIfNeeded() to create the DNF config if it
// AddRepo adds and enables a repo configuration named <name> pointing at
// URL <url>. It calls b.NewDNFConfIfNeeded() to create the DNF config if it
// does not exist and performs a check to see if the repo passed has already
// been configured.
func (b *Builder) AddRepo(repoInfo []string) error {
func (b *Builder) AddRepo(name, url string) error {
repo := dnfRepoConf{
RepoName: repoInfo[0],
RepoURL: repoInfo[1],
RepoName: name,
RepoURL: url,
}
if err := b.NewDNFConfIfNeeded(); err != nil {
@@ -1708,6 +1708,33 @@ func (b *Builder) AddRepo(repoInfo []string) error {
return nil
}
// SetURLRepo sets the URL for the repo <name> to <url>. If <name> does not exist it is
// created.
func (b *Builder) SetURLRepo(name, url string) error {
if err := b.NewDNFConfIfNeeded(); err != nil {
return err
}
DNFConf, err := ini.Load(b.Config.Builder.DNFConf)
if err != nil {
return err
}
s, err := DNFConf.GetSection(name)
if err != nil {
// the section doesn't exist, just add a new one
return b.AddRepo(name, url)
}
k, err := s.GetKey("baseurl")
if err != nil {
return err
}
k.SetValue(url)
return DNFConf.SaveTo(b.Config.Builder.DNFConf)
}
// RemoveRepo removes a configured repo <name> if it exists in the DNF configuration.
// This will fail if a DNF conf has not yet been generated.
func (b *Builder) RemoveRepo(name string) error {
+26 -1
View File
@@ -57,11 +57,19 @@ var initRepoCmd = &cobra.Command{
Run: runInitRepo,
}
var setURLRepoCmd = &cobra.Command{
Use: "set-url <name> <url>",
Short: "Sets the URL for repo <name> to <url>",
Long: `Sets the URL, for repo <name> to <url>. If <name> does not exist the repo will be added to the configuration.`,
Run: runSetURLRepo,
}
var repoCmds = []*cobra.Command{
addRepoCmd,
removeRepoCmd,
listReposCmd,
initRepoCmd,
setURLRepoCmd,
}
func init() {
@@ -82,7 +90,7 @@ func runAddRepo(cmd *cobra.Command, args []string) {
fail(err)
}
err = b.AddRepo(args)
err = b.AddRepo(args[0], args[1])
if err != nil {
fail(err)
}
@@ -128,3 +136,20 @@ func runInitRepo(cmd *cobra.Command, args []string) {
fail(err)
}
}
func runSetURLRepo(cmd *cobra.Command, args []string) {
if len(args) != 2 {
fail(errors.New("set-url requires two arguments: <name> <url>"))
}
b, err := builder.NewFromConfig(config)
if err != nil {
fail(err)
}
err = b.SetURLRepo(args[0], args[1])
if err != nil {
fail(err)
}
fmt.Printf("Set %s baseurl to %s.\n", args[0], args[1])
}