From a59cad6f206cfbd05eb28fe8c4769f63f7e8316c Mon Sep 17 00:00:00 2001 From: Steven Stone Date: Wed, 30 Oct 2019 18:43:57 -0400 Subject: [PATCH] Enable the ability to pass in a custom codename While testing out Aptly, the `apt-get` client complains with the following error, since the `codename` was switched from the InRelease files that are baked out by Aptly: ``` E: Repository 'http://debianrepo.example.com/bionic testing InRelease' changed its 'Codename' value from '' to 'testing' ``` --- AUTHORS | 1 + cmd/publish_repo.go | 1 + cmd/publish_snapshot.go | 2 ++ completion.d/_aptly | 1 + completion.d/aptly | 2 +- deb/publish.go | 17 ++++++++++++++++- man/aptly.1 | 8 ++++++++ .../PublishSnapshot1Test_release_amd64 | 1 + .../PublishSnapshot1Test_release_i386 | 1 + .../PublishSnapshot35Test_release_udeb_i386 | 1 + system/t12_api/publish.py | 10 ++++++++++ 11 files changed, 43 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 00bc4557..6b9285fa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -49,3 +49,4 @@ List of contributors, in chronological order: * Samuel Mutel (https://github.com/smutel) * Russell Greene (https://github.com/russelltg) * Wade Simmons (https://github.com/wadey) +* Steven Stone (https://github.com/smstone) diff --git a/cmd/publish_repo.go b/cmd/publish_repo.go index 3e357cb8..f2f30472 100644 --- a/cmd/publish_repo.go +++ b/cmd/publish_repo.go @@ -48,6 +48,7 @@ Example: cmd.Flag.String("butautomaticupgrades", "", "set value for ButAutomaticUpgrades field") cmd.Flag.String("label", "", "label to publish") cmd.Flag.String("suite", "", "suite to publish (defaults to distribution)") + cmd.Flag.String("codename", "", "codename to publish (defaults to distribution)") cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch") cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash") diff --git a/cmd/publish_snapshot.go b/cmd/publish_snapshot.go index 5b02a6be..322479aa 100644 --- a/cmd/publish_snapshot.go +++ b/cmd/publish_snapshot.go @@ -132,6 +132,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error { } published.Label = context.Flags().Lookup("label").Value.String() published.Suite = context.Flags().Lookup("suite").Value.String() + published.Codename = context.Flags().Lookup("codename").Value.String() published.SkipContents = context.Config().SkipContentsPublishing @@ -239,6 +240,7 @@ Example: cmd.Flag.String("butautomaticupgrades", "", "overwrite value for ButAutomaticUpgrades field") cmd.Flag.String("label", "", "label to publish") cmd.Flag.String("suite", "", "suite to publish (defaults to distribution)") + cmd.Flag.String("codename", "", "codename to publish (defaults to distribution)") cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch") cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash") diff --git a/completion.d/_aptly b/completion.d/_aptly index 505c0609..8e8d2bbd 100644 --- a/completion.d/_aptly +++ b/completion.d/_aptly @@ -457,6 +457,7 @@ local keyring="*-keyring=[gpg keyring to use when verifying Release file (could "-distribution=[distribution name to publish]:distribution:($dists)" "-label=[label to publish]:label: " "-suite=[suite to publish]:suite: " + "-codename=[codename to publish]:codename: " "-notautomatic=[set value for NotAutomatic field]:notautomatic: " "-origin=[origin name to publish]:origin: " ${components_options[@]} diff --git a/completion.d/aptly b/completion.d/aptly index afddd63d..7043efbc 100644 --- a/completion.d/aptly +++ b/completion.d/aptly @@ -503,7 +503,7 @@ _aptly() "snapshot"|"repo") if [[ $numargs -eq 0 ]]; then if [[ "$cur" == -* ]]; then - COMPREPLY=($(compgen -W "-acquire-by-hash -batch -butautomaticupgrades= -component= -distribution= -force-overwrite -gpg-key= -keyring= -label= -suite= -notautomatic= -origin= -passphrase= -passphrase-file= -secret-keyring= -skip-contents -skip-bz2 -skip-signing" -- ${cur})) + COMPREPLY=($(compgen -W "-acquire-by-hash -batch -butautomaticupgrades= -component= -distribution= -force-overwrite -gpg-key= -keyring= -label= -suite= -codename= -notautomatic= -origin= -passphrase= -passphrase-file= -secret-keyring= -skip-contents -skip-signing" -- ${cur})) else if [[ "$subcmd" == "snapshot" ]]; then COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur})) diff --git a/deb/publish.go b/deb/publish.go index 7a7bab88..8798cc69 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -44,6 +44,7 @@ type PublishedRepo struct { ButAutomaticUpgrades string Label string Suite string + Codename string // Architectures is a list of all architectures published Architectures []string // SourceKind is "local"/"repo" @@ -312,6 +313,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) { "Label": p.Label, "Origin": p.Origin, "Suite": p.Suite, + "Codename": p.Codename, "NotAutomatic": p.NotAutomatic, "ButAutomaticUpgrades": p.ButAutomaticUpgrades, "Prefix": p.Prefix, @@ -366,6 +368,10 @@ func (p *PublishedRepo) String() string { extras = append(extras, fmt.Sprintf("suite: %s", p.Suite)) } + if p.Codename != "" { + extras = append(extras, fmt.Sprintf("codename: %s", p.Codename)) + } + extra = strings.Join(extras, ", ") if extra != "" { @@ -513,6 +519,14 @@ func (p *PublishedRepo) GetSuite() string { return p.Suite } +// GetCodename returns default or manual Codename: +func (p *PublishedRepo) GetCodename() string { + if p.Codename == "" { + return p.Distribution + } + return p.Codename +} + // Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageProvider aptly.PublishedStorageProvider, collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite bool) error { @@ -735,6 +749,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP release["Origin"] = p.GetOrigin() release["Label"] = p.GetLabel() release["Suite"] = p.GetSuite() + release["Codename"] = p.GetCodename() if p.AcquireByHash { release["Acquire-By-Hash"] = "yes" } @@ -793,7 +808,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP } release["Label"] = p.GetLabel() release["Suite"] = p.GetSuite() - release["Codename"] = p.Distribution + release["Codename"] = p.GetCodename() release["Date"] = time.Now().UTC().Format("Mon, 2 Jan 2006 15:04:05 MST") release["Architectures"] = strings.Join(utils.StrSlicesSubstract(p.Architectures, []string{ArchitectureSource}), " ") if p.AcquireByHash { diff --git a/man/aptly.1 b/man/aptly.1 index 4cc042a4..03c8e8a1 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -1500,6 +1500,10 @@ don\(cqt sign Release files with GPG \-\fBsuite\fR= suite to publish (defaults to distribution) . +.TP +\-\fBcodename\fR= +codename to publish (defaults to distribution) +. .SH "PUBLISH SNAPSHOT" \fBaptly\fR \fBpublish\fR \fBsnapshot\fR \fIname\fR [[\fIendpoint\fR:]\fIprefix\fR] . @@ -1603,6 +1607,10 @@ don\(cqt sign Release files with GPG \-\fBsuite\fR= suite to publish (defaults to distribution) . +.TP +\-\fBcodename\fR= +codename to publish (defaults to distribution) +. .SH "UPDATE PUBLISHED REPOSITORY BY SWITCHING TO NEW SNAPSHOT" \fBaptly\fR \fBpublish\fR \fBswitch\fR \fIdistribution\fR [[\fIendpoint\fR:]\fIprefix\fR] \fInew\-snapshot\fR . diff --git a/system/t06_publish/PublishSnapshot1Test_release_amd64 b/system/t06_publish/PublishSnapshot1Test_release_amd64 index b69b5727..08216879 100644 --- a/system/t06_publish/PublishSnapshot1Test_release_amd64 +++ b/system/t06_publish/PublishSnapshot1Test_release_amd64 @@ -2,5 +2,6 @@ Origin: LP-PPA-gladky-anton-gnuplot Label: . maverick Archive: maverick Suite: maverick +Codename: maverick Architecture: amd64 Component: main diff --git a/system/t06_publish/PublishSnapshot1Test_release_i386 b/system/t06_publish/PublishSnapshot1Test_release_i386 index 484aabc6..c776b4bc 100644 --- a/system/t06_publish/PublishSnapshot1Test_release_i386 +++ b/system/t06_publish/PublishSnapshot1Test_release_i386 @@ -2,5 +2,6 @@ Origin: LP-PPA-gladky-anton-gnuplot Label: . maverick Archive: maverick Suite: maverick +Codename: maverick Architecture: i386 Component: main diff --git a/system/t06_publish/PublishSnapshot35Test_release_udeb_i386 b/system/t06_publish/PublishSnapshot35Test_release_udeb_i386 index e93dcfe6..d50da52d 100644 --- a/system/t06_publish/PublishSnapshot35Test_release_udeb_i386 +++ b/system/t06_publish/PublishSnapshot35Test_release_udeb_i386 @@ -2,5 +2,6 @@ Origin: Debian Label: . stretch Archive: stretch Suite: stretch +Codename: stretch Architecture: i386 Component: main diff --git a/system/t12_api/publish.py b/system/t12_api/publish.py index 99f339ed..1567de34 100644 --- a/system/t12_api/publish.py +++ b/system/t12_api/publish.py @@ -41,6 +41,7 @@ class PublishAPITestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'Origin': '', @@ -86,6 +87,7 @@ class PublishAPITestRepo(APITest): repo2_expected = { 'AcquireByHash': False, 'Architectures': ['amd64', 'i386'], + 'Codename': '', 'Distribution': distribution, 'Label': '', 'Origin': '', @@ -164,6 +166,7 @@ class PublishSnapshotAPITest(APITest): repo_expected = { 'AcquireByHash': True, 'Architectures': ['i386'], + 'Codename': '', 'Distribution': 'squeeze', 'Label': 'fun', 'Origin': 'earth', @@ -249,6 +252,7 @@ class PublishUpdateAPITestRepo(APITest): repo_expected = { 'AcquireByHash': True, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'Origin': '', @@ -343,6 +347,7 @@ class PublishUpdateSkipCleanupAPITestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'Origin': '', @@ -406,6 +411,7 @@ class PublishSwitchAPITestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'NotAutomatic': '', @@ -449,6 +455,7 @@ class PublishSwitchAPITestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'Origin': '', @@ -510,6 +517,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'NotAutomatic': '', @@ -546,6 +554,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'otherdist', 'Label': '', 'NotAutomatic': '', @@ -584,6 +593,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest): repo_expected = { 'AcquireByHash': False, 'Architectures': ['i386', 'source'], + 'Codename': '', 'Distribution': 'wheezy', 'Label': '', 'Origin': '',