deb-s3-x 0.7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +126 -0
- data/bin/deb-s3 +9 -0
- data/lib/deb/s3.rb +6 -0
- data/lib/deb/s3/cli.rb +531 -0
- data/lib/deb/s3/manifest.rb +125 -0
- data/lib/deb/s3/package.rb +303 -0
- data/lib/deb/s3/release.rb +151 -0
- data/lib/deb/s3/templates/package.erb +66 -0
- data/lib/deb/s3/templates/release.erb +20 -0
- data/lib/deb/s3/utils.rb +92 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTljYmMxOWI3NDE1YmQ0YTg5ODZlZWJhNmYwMDlkODgyNDQyYWU3NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmRmY2YxYmIxMTAwZTIxMDBmYWRiMWJmYmZkZDJkZGE1MzI1Y2I4Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmM3MDgzODllYTk5NGRkMjUyYjlmOWU4NTQxNWZjNjFjOGQ5NTg3YmNjMWJj
|
10
|
+
MTZmYmYwYWI3YzgxNTUzNWQyMzA3NmUxMzQzZDY2MDc0ZmM5Y2YyZjU4ZGRk
|
11
|
+
ODJhOTc0NWY5YWVlYzVlZjFjNzg3NjFjNWRjODU3NjAyZWFlY2M=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGY5MmE0ZjRmN2U5MGQ1NWY5MTMxODUxNmU4YTlhNWY2NmExYjU0Y2IwZDk5
|
14
|
+
ODA3ODY2YWM1MDVkNjk2NDcxMzRhOTc4ODc1YTEzMDk4MmFiOTEyZjA5Nzkz
|
15
|
+
ZmEzYTYyOWZlNDRlMTZhNmUxNzA5MDVjYjU2ZDlmZTNlYWRkYTU=
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# deb-s3
|
2
|
+
|
3
|
+
[](https://travis-ci.org/krobertson/deb-s3)
|
4
|
+
|
5
|
+
`deb-s3` is a simple utility to make creating and managing APT repositories on
|
6
|
+
S3.
|
7
|
+
|
8
|
+
Most existing existing guides on using S3 to host an APT repository have you
|
9
|
+
using something like [reprepro](http://mirrorer.alioth.debian.org/) to generate
|
10
|
+
the repository file structure, and then [s3cmd](http://s3tools.org/s3cmd) to
|
11
|
+
sync the files to S3.
|
12
|
+
|
13
|
+
The annoying thing about this process is it requires you to maintain a local
|
14
|
+
copy of the file tree for regenerating and syncing the next time. Personally,
|
15
|
+
my process is to use one-off virtual machines with
|
16
|
+
[Vagrant](http://vagrantup.com), script out the build process, and then would
|
17
|
+
prefer to just upload the final `.deb` from my Mac.
|
18
|
+
|
19
|
+
With `deb-s3`, there is no need for this. `deb-s3` features:
|
20
|
+
|
21
|
+
* Downloads the existing package manifest and parses it.
|
22
|
+
* Updates it with the new package, replacing the existing entry if already
|
23
|
+
there or adding a new one if not.
|
24
|
+
* Uploads the package itself, the Packages manifest, and the Packages.gz
|
25
|
+
manifest. It will skip the uploading if the package is already there.
|
26
|
+
* Updates the Release file with the new hashes and file sizes.
|
27
|
+
|
28
|
+
## Getting Started
|
29
|
+
|
30
|
+
You can simply install it from rubygems:
|
31
|
+
|
32
|
+
```console
|
33
|
+
$ gem install deb-s3
|
34
|
+
```
|
35
|
+
|
36
|
+
Or to run the code directly, just check out the repo and run Bundler to ensure
|
37
|
+
all dependencies are installed:
|
38
|
+
|
39
|
+
```console
|
40
|
+
$ git clone https://github.com/krobertson/deb-s3.git
|
41
|
+
$ cd deb-s3
|
42
|
+
$ bundle install
|
43
|
+
```
|
44
|
+
|
45
|
+
Now to upload a package, simply use:
|
46
|
+
|
47
|
+
```console
|
48
|
+
$ deb-s3 upload --bucket my-bucket my-deb-package-1.0.0_amd64.deb
|
49
|
+
>> Examining package file my-deb-package-1.0.0_amd64.deb
|
50
|
+
>> Retrieving existing package manifest
|
51
|
+
>> Uploading package and new manifests to S3
|
52
|
+
-- Transferring pool/m/my/my-deb-package-1.0.0_amd64.deb
|
53
|
+
-- Transferring dists/stable/main/binary-amd64/Packages
|
54
|
+
-- Transferring dists/stable/main/binary-amd64/Packages.gz
|
55
|
+
-- Transferring dists/stable/Release
|
56
|
+
>> Update complete.
|
57
|
+
```
|
58
|
+
|
59
|
+
```
|
60
|
+
Usage:
|
61
|
+
deb-s3 upload FILES
|
62
|
+
|
63
|
+
Options:
|
64
|
+
-a, [--arch=ARCH] # The architecture of the package in the APT repository.
|
65
|
+
[--sign=SIGN] # Sign the Release file. Use --sign with your key ID to use a specific key.
|
66
|
+
-p, [--preserve-versions] # Whether to preserve other versions of a package in the repository when uploading one.
|
67
|
+
-b, [--bucket=BUCKET] # The name of the S3 bucket to upload to.
|
68
|
+
-c, [--codename=CODENAME] # The codename of the APT repository.
|
69
|
+
# Default: stable
|
70
|
+
-m, [--component=COMPONENT] # The component of the APT repository.
|
71
|
+
# Default: main
|
72
|
+
[--access-key-id=ACCESS_KEY] # The access key for connecting to S3.
|
73
|
+
[--secret-access-key=SECRET_KEY] # The secret key for connecting to S3.
|
74
|
+
-v, [--visibility=VISIBILITY] # The access policy for the uploaded files. Can be public, private, or authenticated.
|
75
|
+
# Default: public
|
76
|
+
|
77
|
+
Uploads the given files to a S3 bucket as an APT repository.
|
78
|
+
```
|
79
|
+
|
80
|
+
You can also delete packages from the APT repository. Please keep in mind that
|
81
|
+
this does NOT delete the .deb file itself, it only removes it from the list of
|
82
|
+
packages in the specified component, codename and architecture.
|
83
|
+
|
84
|
+
Now to delete the package:
|
85
|
+
```console
|
86
|
+
$ deb-s3 delete --arch amd64 --bucket my-bucket --versions 1.0.0 my-deb-package
|
87
|
+
>> Retrieving existing manifests
|
88
|
+
-- Deleting my-deb-package version 1.0.0
|
89
|
+
>> Uploading new manifests to S3
|
90
|
+
-- Transferring dists/stable/main/binary-amd64/Packages
|
91
|
+
-- Transferring dists/stable/main/binary-amd64/Packages.gz
|
92
|
+
-- Transferring dists/stable/Release
|
93
|
+
>> Update complete.
|
94
|
+
|
95
|
+
````
|
96
|
+
|
97
|
+
You can also verify an existing APT repository on S3 using the `verify` command:
|
98
|
+
|
99
|
+
```console
|
100
|
+
deb-s3 verify -b my-bucket
|
101
|
+
>> Retrieving existing manifests
|
102
|
+
>> Checking for missing packages in: stable/main i386
|
103
|
+
>> Checking for missing packages in: stable/main amd64
|
104
|
+
>> Checking for missing packages in: stable/main all
|
105
|
+
```
|
106
|
+
|
107
|
+
```
|
108
|
+
Usage:
|
109
|
+
deb-s3 verify
|
110
|
+
|
111
|
+
Options:
|
112
|
+
-f, [--fix-manifests] # Whether to fix problems in manifests when verifying.
|
113
|
+
[--sign=SIGN] # Sign the Release file. Use --sign with your key ID to use a specific key.
|
114
|
+
-b, [--bucket=BUCKET] # The name of the S3 bucket to upload to.
|
115
|
+
-c, [--codename=CODENAME] # The codename of the APT repository.
|
116
|
+
# Default: stable
|
117
|
+
-m, [--component=COMPONENT] # The component of the APT repository.
|
118
|
+
# Default: main
|
119
|
+
[--access-key-id=ACCESS_KEY] # The access key for connecting to S3.
|
120
|
+
[--secret-access-key=SECRET_KEY] # The secret key for connecting to S3.
|
121
|
+
-v, [--visibility=VISIBILITY] # The access policy for the uploaded files. Can be public, private, or authenticated.
|
122
|
+
# Default: public
|
123
|
+
|
124
|
+
Verifies that the files in the package manifests exist
|
125
|
+
```
|
126
|
+
|
data/bin/deb-s3
ADDED
data/lib/deb/s3.rb
ADDED
data/lib/deb/s3/cli.rb
ADDED
@@ -0,0 +1,531 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require "aws"
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
# Hack: aws requires this!
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
require "deb/s3"
|
9
|
+
require "deb/s3/utils"
|
10
|
+
require "deb/s3/manifest"
|
11
|
+
require "deb/s3/package"
|
12
|
+
require "deb/s3/release"
|
13
|
+
|
14
|
+
class Deb::S3::CLI < Thor
|
15
|
+
class_option :bucket,
|
16
|
+
:type => :string,
|
17
|
+
:aliases => "-b",
|
18
|
+
:desc => "The name of the S3 bucket to upload to."
|
19
|
+
|
20
|
+
class_option :prefix,
|
21
|
+
:type => :string,
|
22
|
+
:desc => "The path prefix to use when storing on S3."
|
23
|
+
|
24
|
+
class_option :origin,
|
25
|
+
:type => :string,
|
26
|
+
:aliases => "-o",
|
27
|
+
:desc => "The origin to use in the repository Release file."
|
28
|
+
|
29
|
+
class_option :suite,
|
30
|
+
:type => :string,
|
31
|
+
:desc => "The suite to use in the repository Release file."
|
32
|
+
|
33
|
+
class_option :codename,
|
34
|
+
:default => "stable",
|
35
|
+
:type => :string,
|
36
|
+
:aliases => "-c",
|
37
|
+
:desc => "The codename of the APT repository."
|
38
|
+
|
39
|
+
class_option :component,
|
40
|
+
:default => "main",
|
41
|
+
:type => :string,
|
42
|
+
:aliases => "-m",
|
43
|
+
:desc => "The component of the APT repository."
|
44
|
+
|
45
|
+
class_option :section,
|
46
|
+
:type => :string,
|
47
|
+
:aliases => "-s",
|
48
|
+
:hide => true
|
49
|
+
|
50
|
+
class_option :access_key_id,
|
51
|
+
:type => :string,
|
52
|
+
:desc => "The access key for connecting to S3."
|
53
|
+
|
54
|
+
class_option :secret_access_key,
|
55
|
+
:type => :string,
|
56
|
+
:desc => "The secret key for connecting to S3."
|
57
|
+
|
58
|
+
class_option :endpoint,
|
59
|
+
:type => :string,
|
60
|
+
:desc => "The region endpoint for connecting to S3.",
|
61
|
+
:default => "s3.amazonaws.com"
|
62
|
+
|
63
|
+
class_option :proxy_uri,
|
64
|
+
:type => :string,
|
65
|
+
:desc => "The URI of the proxy to send service requests through."
|
66
|
+
|
67
|
+
class_option :use_ssl,
|
68
|
+
:default => true,
|
69
|
+
:type => :boolean,
|
70
|
+
:desc => "Whether to use HTTP or HTTPS for request transport."
|
71
|
+
|
72
|
+
class_option :visibility,
|
73
|
+
:default => "public",
|
74
|
+
:type => :string,
|
75
|
+
:aliases => "-v",
|
76
|
+
:desc => "The access policy for the uploaded files. " +
|
77
|
+
"Can be public, private, or authenticated."
|
78
|
+
|
79
|
+
class_option :sign,
|
80
|
+
:type => :string,
|
81
|
+
:desc => "Sign the Release file when uploading a package," +
|
82
|
+
"or when verifying it after removing a package." +
|
83
|
+
"Use --sign with your key ID to use a specific key."
|
84
|
+
|
85
|
+
class_option :gpg_options,
|
86
|
+
:default => "",
|
87
|
+
:type => :string,
|
88
|
+
:desc => "Additional command line options to pass to GPG when signing"
|
89
|
+
|
90
|
+
class_option :encryption,
|
91
|
+
:default => false,
|
92
|
+
:type => :boolean,
|
93
|
+
:aliases => "-e",
|
94
|
+
:desc => "Use S3 server side encryption"
|
95
|
+
|
96
|
+
class_option :quiet,
|
97
|
+
:type => :boolean,
|
98
|
+
:aliases => "-q",
|
99
|
+
:desc => "Doesn't output information, just returns status appropriately."
|
100
|
+
|
101
|
+
class_option :cache_control,
|
102
|
+
:type => :string,
|
103
|
+
:aliases => "-C",
|
104
|
+
:desc => "Add cache-control headers to S3 objects"
|
105
|
+
|
106
|
+
desc "upload FILES",
|
107
|
+
"Uploads the given files to a S3 bucket as an APT repository."
|
108
|
+
|
109
|
+
option :arch,
|
110
|
+
:type => :string,
|
111
|
+
:aliases => "-a",
|
112
|
+
:desc => "The architecture of the package in the APT repository."
|
113
|
+
|
114
|
+
option :preserve_versions,
|
115
|
+
:default => false,
|
116
|
+
:type => :boolean,
|
117
|
+
:aliases => "-p",
|
118
|
+
:desc => "Whether to preserve other versions of a package " +
|
119
|
+
"in the repository when uploading one."
|
120
|
+
|
121
|
+
def upload(*files)
|
122
|
+
if files.nil? || files.empty?
|
123
|
+
error("You must specify at least one file to upload")
|
124
|
+
end
|
125
|
+
|
126
|
+
# make sure all the files exists
|
127
|
+
if missing_file = files.find { |pattern| Dir.glob(pattern).empty? }
|
128
|
+
error("File '#{missing_file}' doesn't exist")
|
129
|
+
end
|
130
|
+
|
131
|
+
# configure AWS::S3
|
132
|
+
configure_s3_client
|
133
|
+
|
134
|
+
# retrieve the existing manifests
|
135
|
+
log("Retrieving existing manifests")
|
136
|
+
release = Deb::S3::Release.retrieve(options[:codename], options[:origin], options[:suite], options[:cache_control])
|
137
|
+
manifests = {}
|
138
|
+
release.architectures.each do |arch|
|
139
|
+
manifests[arch] = Deb::S3::Manifest.retrieve(options[:codename], component, arch, options[:cache_control])
|
140
|
+
end
|
141
|
+
|
142
|
+
packages_arch_all = []
|
143
|
+
|
144
|
+
# examine all the files
|
145
|
+
files.collect { |f| Dir.glob(f) }.flatten.each do |file|
|
146
|
+
log("Examining package file #{File.basename(file)}")
|
147
|
+
pkg = Deb::S3::Package.parse_file(file)
|
148
|
+
url_filename = "#{pkg.name}-#{pkg.full_version}_#{pkg.architecture}.deb"
|
149
|
+
pkg.url_filename = "pool/#{options[:codename]}/#{component}/#{pkg.name[0]}/#{pkg.name[0..1]}/#{url_filename}"
|
150
|
+
|
151
|
+
# copy over some options if they weren't given
|
152
|
+
arch = options[:arch] || pkg.architecture
|
153
|
+
|
154
|
+
# validate we have them
|
155
|
+
error("No architcture given and unable to determine one for #{file}. " +
|
156
|
+
"Please specify one with --arch [i386|amd64].") unless arch
|
157
|
+
|
158
|
+
# If the arch is all and the list of existing manifests is none, then
|
159
|
+
# throw an error. This is mainly the case when initializing a brand new
|
160
|
+
# repository. With "all", we won't know which architectures they're using.
|
161
|
+
if arch == "all" && manifests.count == 0
|
162
|
+
error("Package #{File.basename(file)} had architecture \"all\", " +
|
163
|
+
"however noexisting package lists exist. This can often happen " +
|
164
|
+
"if the first package you are add to a new repository is an " +
|
165
|
+
"\"all\" architecture file. Please use --arch [i386|amd64] or " +
|
166
|
+
"another platform type to upload the file.")
|
167
|
+
end
|
168
|
+
|
169
|
+
# retrieve the manifest for the arch if we don't have it already
|
170
|
+
manifests[arch] ||= Deb::S3::Manifest.retrieve(options[:codename], component, arch, options[:cache_control])
|
171
|
+
|
172
|
+
# add package in manifests
|
173
|
+
manifests[arch].add(pkg, options[:preserve_versions])
|
174
|
+
|
175
|
+
# If arch is all, we must add this package in all arch available
|
176
|
+
if arch == 'all'
|
177
|
+
packages_arch_all << pkg
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
manifests.each do |arch, manifest|
|
182
|
+
next if arch == 'all'
|
183
|
+
packages_arch_all.each do |pkg|
|
184
|
+
manifest.add(pkg, options[:preserve_versions], false)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# upload the manifest
|
189
|
+
log("Uploading packages and new manifests to S3")
|
190
|
+
manifests.each_value do |manifest|
|
191
|
+
manifest.write_to_s3 { |f| sublog("Transferring #{f}") }
|
192
|
+
release.update_manifest(manifest)
|
193
|
+
end
|
194
|
+
release.write_to_s3 { |f| sublog("Transferring #{f}") }
|
195
|
+
|
196
|
+
log("Update complete.")
|
197
|
+
end
|
198
|
+
|
199
|
+
desc "list", "Lists packages in given codename, component, and optionally architecture"
|
200
|
+
|
201
|
+
option :long,
|
202
|
+
:type => :boolean,
|
203
|
+
:aliases => '-l',
|
204
|
+
:desc => "Shows all package information in original format",
|
205
|
+
:default => false
|
206
|
+
|
207
|
+
option :arch,
|
208
|
+
:type => :string,
|
209
|
+
:aliases => "-a",
|
210
|
+
:desc => "The architecture of the package in the APT repository."
|
211
|
+
|
212
|
+
def list
|
213
|
+
configure_s3_client
|
214
|
+
|
215
|
+
release = Deb::S3::Release.retrieve(options[:codename])
|
216
|
+
archs = release.architectures
|
217
|
+
archs &= [options[:arch]] if options[:arch] && options[:arch] != "all"
|
218
|
+
widths = [0, 0]
|
219
|
+
rows = archs.map { |arch|
|
220
|
+
manifest = Deb::S3::Manifest.retrieve(options[:codename], component,
|
221
|
+
arch, options[:cache_control])
|
222
|
+
manifest.packages.map do |package|
|
223
|
+
if options[:long]
|
224
|
+
package.generate
|
225
|
+
else
|
226
|
+
[package.name, package.full_version, package.architecture].tap do |row|
|
227
|
+
row.each_with_index do |col, i|
|
228
|
+
widths[i] = [widths[i], col.size].max if widths[i]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
}.flatten(1)
|
234
|
+
|
235
|
+
if options[:long]
|
236
|
+
$stdout.puts rows.join("\n")
|
237
|
+
else
|
238
|
+
rows.each do |row|
|
239
|
+
$stdout.puts "% -#{widths[0]}s % -#{widths[1]}s %s" % row
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
desc "show PACKAGE VERSION ARCH", "Shows information about a package."
|
245
|
+
|
246
|
+
def show(package_name, version, arch)
|
247
|
+
if version.nil?
|
248
|
+
error "You must specify the name of the package to show."
|
249
|
+
end
|
250
|
+
if version.nil?
|
251
|
+
error "You must specify the version of the package to show."
|
252
|
+
end
|
253
|
+
if arch.nil?
|
254
|
+
error "You must specify the architecture of the package to show."
|
255
|
+
end
|
256
|
+
|
257
|
+
configure_s3_client
|
258
|
+
|
259
|
+
# retrieve the existing manifests
|
260
|
+
manifest = Deb::S3::Manifest.retrieve(options[:codename], component, arch,
|
261
|
+
options[:cache_control])
|
262
|
+
package = manifest.packages.detect { |p|
|
263
|
+
p.name == package_name && p.full_version == version
|
264
|
+
}
|
265
|
+
if package.nil?
|
266
|
+
error "No such package found."
|
267
|
+
end
|
268
|
+
|
269
|
+
puts package.generate
|
270
|
+
end
|
271
|
+
|
272
|
+
desc "copy PACKAGE TO_CODENAME TO_COMPONENT ",
|
273
|
+
"Copy the package named PACKAGE to given codename and component. If --versions is not specified, copy all versions of PACKAGE. Otherwise, only the specified versions will be copied. Source codename and component is given by --codename and --component options."
|
274
|
+
|
275
|
+
option :cache_control,
|
276
|
+
:type => :string,
|
277
|
+
:aliases => "-C",
|
278
|
+
:desc => "Add cache-control headers to S3 objects"
|
279
|
+
|
280
|
+
option :arch,
|
281
|
+
:type => :string,
|
282
|
+
:aliases => "-a",
|
283
|
+
:desc => "The architecture of the package in the APT repository."
|
284
|
+
|
285
|
+
option :versions,
|
286
|
+
:default => nil,
|
287
|
+
:type => :array,
|
288
|
+
:desc => "The space-delimited versions of PACKAGE to delete. If not" +
|
289
|
+
"specified, ALL VERSIONS will be deleted. Fair warning." +
|
290
|
+
"E.g. --versions \"0.1 0.2 0.3\""
|
291
|
+
|
292
|
+
option :preserve_versions,
|
293
|
+
:default => false,
|
294
|
+
:type => :boolean,
|
295
|
+
:aliases => "-p",
|
296
|
+
:desc => "Whether to preserve other versions of a package " +
|
297
|
+
"in the repository when uploading one."
|
298
|
+
|
299
|
+
def copy(package_name, to_codename, to_component)
|
300
|
+
if package_name.nil?
|
301
|
+
error "You must specify a package name."
|
302
|
+
end
|
303
|
+
if to_codename.nil?
|
304
|
+
error "You must specify a codename to copy to."
|
305
|
+
end
|
306
|
+
if to_component.nil?
|
307
|
+
error "You must specify a component to copy to."
|
308
|
+
end
|
309
|
+
|
310
|
+
arch = options[:arch]
|
311
|
+
if arch.nil?
|
312
|
+
error "You must specify the architecture of the package to copy."
|
313
|
+
end
|
314
|
+
|
315
|
+
versions = options[:versions]
|
316
|
+
if versions.nil?
|
317
|
+
warn "===> WARNING: Copying all versions of #{package_name}"
|
318
|
+
else
|
319
|
+
log "Versions to copy: #{versions.join(', ')}"
|
320
|
+
end
|
321
|
+
|
322
|
+
configure_s3_client
|
323
|
+
|
324
|
+
# retrieve the existing manifests
|
325
|
+
log "Retrieving existing manifests"
|
326
|
+
from_manifest = Deb::S3::Manifest.retrieve(options[:codename],
|
327
|
+
component, arch,
|
328
|
+
options[:cache_control])
|
329
|
+
to_release = Deb::S3::Release.retrieve(to_codename)
|
330
|
+
to_manifest = Deb::S3::Manifest.retrieve(to_codename, to_component, arch,
|
331
|
+
options[:cache_control])
|
332
|
+
packages = from_manifest.packages.select { |p|
|
333
|
+
p.name == package_name &&
|
334
|
+
(versions.nil? || versions.include?(p.full_version))
|
335
|
+
}
|
336
|
+
if packages.size == 0
|
337
|
+
error "No packages found in repository."
|
338
|
+
end
|
339
|
+
|
340
|
+
packages.each do |package|
|
341
|
+
to_manifest.add package, options[:preserve_versions], false
|
342
|
+
end
|
343
|
+
|
344
|
+
to_manifest.write_to_s3 { |f| sublog("Transferring #{f}") }
|
345
|
+
to_release.update_manifest(to_manifest)
|
346
|
+
to_release.write_to_s3 { |f| sublog("Transferring #{f}") }
|
347
|
+
|
348
|
+
log "Copy complete."
|
349
|
+
end
|
350
|
+
|
351
|
+
desc "delete PACKAGE",
|
352
|
+
"Remove the package named PACKAGE. If --versions is not specified, delete" +
|
353
|
+
"all versions of PACKAGE. Otherwise, only the specified versions will be " +
|
354
|
+
"deleted."
|
355
|
+
|
356
|
+
option :arch,
|
357
|
+
:type => :string,
|
358
|
+
:aliases => "-a",
|
359
|
+
:desc => "The architecture of the package in the APT repository."
|
360
|
+
|
361
|
+
option :versions,
|
362
|
+
:default => nil,
|
363
|
+
:type => :array,
|
364
|
+
:desc => "The space-delimited versions of PACKAGE to delete. If not" +
|
365
|
+
"specified, ALL VERSIONS will be deleted. Fair warning." +
|
366
|
+
"E.g. --versions \"0.1 0.2 0.3\""
|
367
|
+
|
368
|
+
def delete(package)
|
369
|
+
if package.nil?
|
370
|
+
error("You must specify a package name.")
|
371
|
+
end
|
372
|
+
|
373
|
+
versions = options[:versions]
|
374
|
+
if versions.nil?
|
375
|
+
warn("===> WARNING: Deleting all versions of #{package}")
|
376
|
+
else
|
377
|
+
log("Versions to delete: #{versions.join(', ')}")
|
378
|
+
end
|
379
|
+
|
380
|
+
arch = options[:arch]
|
381
|
+
if arch.nil?
|
382
|
+
error("You must specify the architecture of the package to remove.")
|
383
|
+
end
|
384
|
+
|
385
|
+
configure_s3_client
|
386
|
+
|
387
|
+
# retrieve the existing manifests
|
388
|
+
log("Retrieving existing manifests")
|
389
|
+
release = Deb::S3::Release.retrieve(options[:codename], options[:origin], options[:suite])
|
390
|
+
manifest = Deb::S3::Manifest.retrieve(options[:codename], component, options[:arch], options[:cache_control])
|
391
|
+
|
392
|
+
deleted = manifest.delete_package(package, versions)
|
393
|
+
if deleted.length == 0
|
394
|
+
if versions.nil?
|
395
|
+
error("No packages were deleted. #{package} not found.")
|
396
|
+
else
|
397
|
+
error("No packages were deleted. #{package} versions #{versions.join(', ')} could not be found.")
|
398
|
+
end
|
399
|
+
else
|
400
|
+
deleted.each { |p|
|
401
|
+
sublog("Deleting #{p.name} version #{p.version}")
|
402
|
+
}
|
403
|
+
end
|
404
|
+
|
405
|
+
log("Uploading new manifests to S3")
|
406
|
+
manifest.write_to_s3 {|f| sublog("Transferring #{f}") }
|
407
|
+
release.update_manifest(manifest)
|
408
|
+
release.write_to_s3 {|f| sublog("Transferring #{f}") }
|
409
|
+
|
410
|
+
log("Update complete.")
|
411
|
+
end
|
412
|
+
|
413
|
+
|
414
|
+
desc "verify", "Verifies that the files in the package manifests exist"
|
415
|
+
|
416
|
+
option :fix_manifests,
|
417
|
+
:default => false,
|
418
|
+
:type => :boolean,
|
419
|
+
:aliases => "-f",
|
420
|
+
:desc => "Whether to fix problems in manifests when verifying."
|
421
|
+
|
422
|
+
def verify
|
423
|
+
configure_s3_client
|
424
|
+
|
425
|
+
log("Retrieving existing manifests")
|
426
|
+
release = Deb::S3::Release.retrieve(options[:codename], options[:origin], options[:suite])
|
427
|
+
|
428
|
+
release.architectures.each do |arch|
|
429
|
+
log("Checking for missing packages in: #{options[:codename]}/#{options[:component]} #{arch}")
|
430
|
+
manifest = Deb::S3::Manifest.retrieve(options[:codename], component,
|
431
|
+
arch, options[:cache_control])
|
432
|
+
missing_packages = []
|
433
|
+
|
434
|
+
manifest.packages.each do |p|
|
435
|
+
unless Deb::S3::Utils.s3_exists? p.url_filename_encoded
|
436
|
+
sublog("The following packages are missing:\n\n") if missing_packages.empty?
|
437
|
+
puts(p.generate)
|
438
|
+
puts("")
|
439
|
+
|
440
|
+
missing_packages << p
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
if options[:sign] || (options[:fix_manifests] && !missing_packages.empty?)
|
445
|
+
log("Removing #{missing_packages.length} package(s) from the manifest...")
|
446
|
+
missing_packages.each { |p| manifest.packages.delete(p) }
|
447
|
+
manifest.write_to_s3 { |f| sublog("Transferring #{f}") }
|
448
|
+
release.update_manifest(manifest)
|
449
|
+
release.write_to_s3 { |f| sublog("Transferring #{f}") }
|
450
|
+
|
451
|
+
log("Update complete.")
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
private
|
457
|
+
|
458
|
+
def component
|
459
|
+
return @component if @component
|
460
|
+
@component = if (section = options[:section])
|
461
|
+
warn("===> WARNING: The --section/-s argument is " \
|
462
|
+
"deprecated, please use --component/-m.")
|
463
|
+
section
|
464
|
+
else
|
465
|
+
options[:component]
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
def puts(*args)
|
470
|
+
$stdout.puts(*args) unless options[:quiet]
|
471
|
+
end
|
472
|
+
|
473
|
+
def log(message)
|
474
|
+
puts ">> #{message}" unless options[:quiet]
|
475
|
+
end
|
476
|
+
|
477
|
+
def sublog(message)
|
478
|
+
puts " -- #{message}" unless options[:quiet]
|
479
|
+
end
|
480
|
+
|
481
|
+
def error(message)
|
482
|
+
$stderr.puts "!! #{message}" unless options[:quiet]
|
483
|
+
exit 1
|
484
|
+
end
|
485
|
+
|
486
|
+
def provider
|
487
|
+
access_key_id = options[:access_key_id]
|
488
|
+
secret_access_key = options[:secret_access_key]
|
489
|
+
|
490
|
+
if access_key_id.nil? ^ secret_access_key.nil?
|
491
|
+
error("If you specify one of --access-key-id or --secret-access-key, you must specify the other.")
|
492
|
+
end
|
493
|
+
|
494
|
+
static_credentials = {}
|
495
|
+
static_credentials[:access_key_id] = access_key_id if access_key_id
|
496
|
+
static_credentials[:secret_access_key] = secret_access_key if secret_access_key
|
497
|
+
|
498
|
+
AWS::Core::CredentialProviders::DefaultProvider.new(static_credentials)
|
499
|
+
end
|
500
|
+
|
501
|
+
def configure_s3_client
|
502
|
+
error("No value provided for required options '--bucket'") unless options[:bucket]
|
503
|
+
|
504
|
+
settings = {
|
505
|
+
:s3_endpoint => options[:endpoint],
|
506
|
+
:proxy_uri => options[:proxy_uri],
|
507
|
+
:use_ssl => options[:use_ssl]
|
508
|
+
}
|
509
|
+
settings.merge!(provider.credentials)
|
510
|
+
|
511
|
+
Deb::S3::Utils.s3 = AWS::S3.new(settings)
|
512
|
+
Deb::S3::Utils.bucket = options[:bucket]
|
513
|
+
Deb::S3::Utils.signing_key = options[:sign]
|
514
|
+
Deb::S3::Utils.gpg_options = options[:gpg_options]
|
515
|
+
Deb::S3::Utils.prefix = options[:prefix]
|
516
|
+
Deb::S3::Utils.encryption = options[:encryption]
|
517
|
+
|
518
|
+
# make sure we have a valid visibility setting
|
519
|
+
Deb::S3::Utils.access_policy =
|
520
|
+
case options[:visibility]
|
521
|
+
when "public"
|
522
|
+
:public_read
|
523
|
+
when "private"
|
524
|
+
:private
|
525
|
+
when "authenticated"
|
526
|
+
:authenticated_read
|
527
|
+
else
|
528
|
+
error("Invalid visibility setting given. Can be public, private, or authenticated.")
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|