-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_repo.rb
executable file
·52 lines (42 loc) · 1.14 KB
/
delete_repo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
require 'aptly'
require 'optparse'
require 'ostruct'
require 'uri'
require 'net/ssh/gateway'
require 'date'
options = OpenStruct.new
options.repos = nil
options.all = false
options.host = 'localhost'
options.port = '8080'
options.distribution = nil
parser = OptionParser.new do |opts|
opts.banner = "Usage: #{opts.program_name} [options] --repo yolo"
opts.on('-r', '--repo name', String, 'Regex to filter out repos') do |v|
options.repo = v
end
opts.on('-g', '--gateway URI', 'open gateway to remote') do |v|
options.gateway = URI(v)
end
end
parser.parse!
# raise parser.help if options.regex.nil?
if options.gateway
case options.gateway.scheme
when 'ssh'
gateway = Net::SSH::Gateway.new(options.gateway.host, options.gateway.user)
options.port = gateway.open('localhost', options.gateway.port)
else
raise 'Gateway scheme not supported'
end
end
Aptly.configure do |config|
config.host = options.host
config.port = options.port
end
@repos = Aptly::Repository.list.select { |x| x.Name.match?(options.repo) }
@repos.each do |repo|
repo.published_in.each { |pubd| pubd.drop }
puts repo.delete
end