Class: RepoMgr::Backend::Deb

Inherits:
Object
  • Object
show all
Defined in:
lib/repo_mgr/backends/deb.rb

Overview

deb backend handler implemented on top of aptly

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Deb

Returns a new instance of Deb.



11
12
13
14
# File 'lib/repo_mgr/backends/deb.rb', line 11

def initialize(config)
  @config = config
  init_aptly_config
end

Instance Method Details

#add_pkg(repo, pkg) ⇒ Object



37
38
39
40
41
# File 'lib/repo_mgr/backends/deb.rb', line 37

def add_pkg(repo, pkg)
  sign_pkg repo, pkg
  repo_add repo, pkg
  repo_publish repo
end

#add_repo(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/repo_mgr/backends/deb.rb', line 16

def add_repo(name)
  return if aptly_repos.include? name

  cmd = "aptly -config=#{@aptly_config_file} repo create #{name}"
  out, status = Open3.capture2e cmd

  unless status.exitstatus.zero?
    Tools.error "aptly repo create failed with:\n#{out}"
  end

  repo_config = @config.cfg[:repos][name]

  @aptly_config['FileSystemPublishEndpoints'][name] = {
    rootDir: repo_config[:path],
    linkMethod: 'copy',
    verifyMethod: 'md5'
  }

  save_aptly_config
end

#check_sig(pkg, allow_fail: false) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/repo_mgr/backends/deb.rb', line 48

def check_sig(pkg, allow_fail: false)
  out, status = Open3.capture2e "dpkg-sig --verify #{pkg}"

  return out if status.exitstatus.zero? || allow_fail

  Tools.error "unable to check package signature for #{pkg} - "\
    "dpkg-sig returned:\n#{out}"
end

#export(repo) ⇒ Object



91
92
93
# File 'lib/repo_mgr/backends/deb.rb', line 91

def export(repo)
  repo_publish repo
end

#rebuild_pkg_list(repo) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/repo_mgr/backends/deb.rb', line 76

def rebuild_pkg_list(repo)
  out, status = Open3.capture2e "aptly -config=#{@aptly_config_file} "\
    "-with-packages repo show #{repo}"

  unless status.exitstatus.zero?
    Tools.error "aptly repo show failed with with:\n#{out}"
  end

  pkgs = out.split
  mark = pkgs.find_index 'Packages:'
  pkgs = pkgs.drop(mark + 1)

  pkgs.map { |e| "#{e}.deb" }
end

#remove_pkg(repo, pkg) ⇒ Object



43
44
45
46
# File 'lib/repo_mgr/backends/deb.rb', line 43

def remove_pkg(repo, pkg)
  repo_rm repo, pkg
  repo_publish repo
end

#sign_pkg(repo, pkg) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/repo_mgr/backends/deb.rb', line 57

def sign_pkg(repo, pkg)
  signature = check_sig pkg, allow_fail: true

  unless signature[-6, 5] == 'NOSIG'
    return puts "-- dpkg-sig returned:\n#{signature.first}"
  end

  if @config.cfg[:repos][repo].nil?
    Tools.error "unable to find #{repo} repository"
  end

  keyid = @config.cfg[:repos][repo][:keyid]
  out, status = Open3.capture2e "dpkg-sig -k #{keyid} -s builder #{pkg}"

  return if status.exitstatus.zero?

  Tools.error "unable to sign #{pkg} - dpkg-sig returned:\n#{out}"
end