From b98abcc049dae54dc0ec556341ca4d985cc2a5bf Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Tue, 21 Nov 2017 16:05:59 +0100 Subject: [PATCH] Allow editing of mirror archive url This is needed in case a mirror has moved or is down and need to move to new mirror. --- bash_completion.d/aptly | 2 +- cmd/mirror_edit.go | 19 ++++++++++++++++++- man/aptly.1 | 14 +++++++++++++- system/t04_mirror/EditMirror10Test_gold | 2 ++ system/t04_mirror/edit.py | 12 ++++++++++-- 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 system/t04_mirror/EditMirror10Test_gold diff --git a/bash_completion.d/aptly b/bash_completion.d/aptly index cb9d9d5d..7baa7fc9 100644 --- a/bash_completion.d/aptly +++ b/bash_completion.d/aptly @@ -164,7 +164,7 @@ _aptly() "edit") if [[ $numargs -eq 0 ]]; then if [[ "$cur" == -* ]]; then - COMPREPLY=($(compgen -W "-filter= -filter-with-deps -with-sources -with-udebs" -- ${cur})) + COMPREPLY=($(compgen -W "-archive-url= -filter= -filter-with-deps -ignore-signatures -keyring= -with-sources -with-udebs" -- ${cur})) else COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur})) fi diff --git a/cmd/mirror_edit.go b/cmd/mirror_edit.go index 2d31d77f..2b19c774 100644 --- a/cmd/mirror_edit.go +++ b/cmd/mirror_edit.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" + "github.com/smira/aptly/pgp" "github.com/smira/aptly/query" "github.com/smira/commander" "github.com/smira/flag" @@ -25,6 +26,7 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to edit: %s", err) } + fetchMirror := false context.Flags().Visit(func(flag *flag.Flag) { switch flag.Name { case "filter": @@ -35,6 +37,9 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error { repo.DownloadSources = flag.Value.Get().(bool) case "with-udebs": repo.DownloadUdebs = flag.Value.Get().(bool) + case "archive-url": + repo.ArchiveRoot = flag.Value.String() + fetchMirror = true } }) @@ -51,8 +56,17 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error { if context.GlobalFlags().Lookup("architectures").Value.String() != "" { repo.Architectures = context.ArchitecturesList() + fetchMirror = true + } - err = repo.Fetch(context.Downloader(), nil) + if fetchMirror { + var verifier pgp.Verifier + verifier, err = getVerifier(context.Flags()) + if err != nil { + return fmt.Errorf("unable to initialize GPG verifier: %s", err) + } + + err = repo.Fetch(context.Downloader(), verifier) if err != nil { return fmt.Errorf("unable to edit: %s", err) } @@ -83,10 +97,13 @@ Example: Flag: *flag.NewFlagSet("aptly-mirror-edit", flag.ExitOnError), } + cmd.Flag.String("archive-url", "", "archive url is the root of archive") cmd.Flag.String("filter", "", "filter packages in mirror") cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well") + cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures") cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages") cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)") + cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") return cmd } diff --git a/man/aptly.1 b/man/aptly.1 index 179aa667..f855b80b 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "APTLY" "1" "September 2017" "" "" +.TH "APTLY" "1" "November 2017" "" "" . .SH "NAME" \fBaptly\fR \- Debian repository management tool @@ -617,6 +617,10 @@ $ aptly mirror edit \-filter=nginx \-filter\-with\-deps some\-mirror Options: . .TP +\-\fBarchive\-url\fR= +archive url is the root of archive +. +.TP \-\fBfilter\fR= filter packages in mirror . @@ -625,6 +629,14 @@ filter packages in mirror when filtering, include dependencies of matching packages as well . .TP +\-\fBignore\-signatures\fR +disable verification of Release file signatures +. +.TP +\-\fBkeyring\fR= +gpg keyring to use when verifying Release file (could be specified multiple times) +. +.TP \-\fBwith\-sources\fR download source packages in addition to binary packages . diff --git a/system/t04_mirror/EditMirror10Test_gold b/system/t04_mirror/EditMirror10Test_gold new file mode 100644 index 00000000..b1e4e197 --- /dev/null +++ b/system/t04_mirror/EditMirror10Test_gold @@ -0,0 +1,2 @@ +Downloading ftp://ftp.ru.debian.org/debian/dists/wheezy/Release... +Mirror [mirror10]: ftp://ftp.ch.debian.org/debian wheezy successfully updated. diff --git a/system/t04_mirror/edit.py b/system/t04_mirror/edit.py index 53b36cbf..13a2e824 100644 --- a/system/t04_mirror/edit.py +++ b/system/t04_mirror/edit.py @@ -65,7 +65,7 @@ class EditMirror6Test(BaseTest): edit mirror: change architectures """ fixtureDB = True - runCmd = "aptly mirror edit -architectures=amd64,s390 wheezy-main" + runCmd = "aptly mirror edit -ignore-signatures -architectures=amd64,s390 wheezy-main" def check(self): self.check_output() @@ -77,7 +77,7 @@ class EditMirror7Test(BaseTest): edit mirror: change architectures to missing archs """ fixtureDB = True - runCmd = "aptly mirror edit -architectures=amd64,x56 wheezy-main" + runCmd = "aptly mirror edit -ignore-signatures -architectures=amd64,x56 wheezy-main" expectedCode = 1 @@ -101,3 +101,11 @@ class EditMirror9Test(BaseTest): fixtureGpg = True runCmd = "aptly mirror edit -with-udebs mirror9" expectedCode = 1 + + +class EditMirror10Test(BaseTest): + """ + edit mirror: change archive url + """ + fixtureCmds = ["aptly mirror create -ignore-signatures mirror10 ftp://ftp.ru.debian.org/debian wheezy main"] + runCmd = "aptly mirror edit -ignore-signatures -archive-url ftp://ftp.ch.debian.org/debian mirror10"