5 # Copyright:: 2024, Tom Hughes
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 node.default[:accounts][:users][:apt][:status] = :role
22 include_recipe "accounts"
23 include_recipe "apache"
27 repository_keys = data_bag_item("apt", "repository")
29 gpg_passphrase = repository_keys["gpg_passphrase"]
31 template "/etc/aptly.conf" do
32 source "aptly.conf.erb"
38 directory "/srv/apt.openstreetmap.org" do
44 execute "apt-generate-key" do
45 command "gpg --no-tty --batch --passphrase=#{gpg_passphrase} --generate-key"
46 cwd "/srv/apt.openstreetmap.org"
49 environment "HOME" => "/srv/apt.openstreetmap.org"
57 Name-Real: OpenStreetMap Admins
58 Name-Email: admins@openstreetmap.org
60 Passphrase: #{gpg_passphrase}
62 not_if { ::Dir.exist?("/srv/apt.openstreetmap.org/.gnupg") }
65 %w[focal jammy noble bookworm].each do |distribution|
66 repository = "openstreetmap-#{distribution}"
68 execute "aptly-repo-create-#{distribution}" do
69 command "aptly repo create -comment='Packages used on OpenStreetMap Servers' -distribution=#{distribution} #{repository}"
70 cwd "/srv/apt.openstreetmap.org"
73 environment "HOME" => "/srv/apt.openstreetmap.org"
74 not_if "aptly repo show #{repository}"
77 execute "aptly-publish-repo-#{distribution}" do
79 command "aptly publish repo -batch -passphrase=#{gpg_passphrase} #{repository}"
80 cwd "/srv/apt.openstreetmap.org"
83 environment "HOME" => "/srv/apt.openstreetmap.org"
84 subscribes :run, "execute[aptly-repo-create-#{distribution}]", :immediately
87 execute "aptly-publish-update-#{distribution}" do
88 command "aptly publish update -batch -passphrase=#{gpg_passphrase} #{distribution}"
89 cwd "/srv/apt.openstreetmap.org"
92 environment "HOME" => "/srv/apt.openstreetmap.org"
96 execute "gpg-export-key" do
97 command "gpg --no-tty --batch --passphrase=#{gpg_passphrase} --armor --output=/srv/apt.openstreetmap.org/public/gpg.key --export admins@openstreetmap.org"
98 cwd "/srv/apt.openstreetmap.org"
101 environment "HOME" => "/srv/apt.openstreetmap.org"
102 not_if { ::File.exist?("/srv/apt.openstreetmap.org/public/gpg.key") }
105 ssl_certificate "apt.openstreetmap.org" do
106 domains ["apt.openstreetmap.org", "apt.osm.org"]
107 notifies :reload, "service[apache2]"
110 apache_site "apt.openstreetmap.org" do
111 template "apache.erb"
112 directory "/srv/apt.openstreetmap.org"
113 variables :aliases => ["apt.osm.org"]