]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apt/recipes/default.rb
foundation: update board wiki to LTS release
[chef.git] / cookbooks / apt / recipes / default.rb
1 #
2 # Cookbook:: apt
3 # Recipe:: default
4 #
5 # Copyright:: 2010, Tom Hughes
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 package %w[
21   apt
22   apt-transport-https
23   gnupg
24 ]
25
26 package "update-notifier-common" if platform?("ubuntu")
27
28 file "/etc/motd.tail" do
29   action :delete
30 end
31
32 apt_preference "cciss-vol-status" do
33   pin          "origin *.ubuntu.com"
34   pin_priority "1100"
35 end
36
37 apt_update "/etc/apt/sources.list" do
38   action :nothing
39 end
40
41 dpkg_arch = node[:packages][:systemd][:arch]
42
43 if platform?("debian")
44   archive_host = "deb.debian.org"
45   archive_security_host = archive_host
46   archive_distro = "debian"
47   archive_security_distro = "debian-security"
48   archive_suites = %w[main updates backports security]
49   archive_components = %w[main contrib non-free non-free-firmware]
50   backport_packages = case node[:lsb][:codename]
51                       when "bookworm" then %W[amd64-microcode exim4 firmware-free firmware-nonfree intel-microcode libosmium linux linux-base linux-signed-#{dpkg_arch} osm2pgsql otrs2 pyosmium smartmontools systemd cgi-mapserver]
52                       when "trixie" then %w[otrs2]
53                       else %w[]
54                       end
55 elsif intel?
56   archive_host = if node[:country]
57                    "#{node[:country]}.archive.ubuntu.com"
58                  else
59                    "archive.ubuntu.com"
60                  end
61   archive_security_host = "security.ubuntu.com"
62   archive_distro = "ubuntu"
63   archive_security_distro = archive_distro
64   archive_suites = %w[main updates backports security]
65   archive_components = %w[main restricted universe multiverse]
66   backport_packages = %w[]
67 else
68   archive_host = "ports.ubuntu.com"
69   archive_security_host = archive_host
70   archive_distro = "ubuntu-ports"
71   archive_security_distro = archive_distro
72   archive_suites = %w[main updates backports security]
73   archive_components = %w[main restricted universe multiverse]
74   backport_packages = %w[]
75 end
76
77 template "/etc/apt/sources.list" do
78   source "sources.list.erb"
79   owner "root"
80   group "root"
81   mode "644"
82   variables :archive_host => archive_host,
83             :archive_security_host => archive_security_host,
84             :archive_distro => archive_distro,
85             :archive_security_distro => archive_security_distro,
86             :archive_suites => archive_suites,
87             :archive_components => archive_components,
88             :codename => node[:lsb][:codename]
89   notifies :update, "apt_update[/etc/apt/sources.list]", :immediately
90 end
91
92 if backport_packages.empty?
93   apt_preference "backports" do
94     action :remove
95   end
96 else
97   apt_preference "backports" do
98     glob backport_packages.sort.map { |p| "src:#{p}" }.join(" ")
99     pin "release n=#{node[:lsb][:codename]}-backports"
100     pin_priority "500"
101   end
102 end
103
104 execute "apt-cache-gencaches" do
105   action :nothing
106   command "apt-cache gencaches"
107   subscribes :run, "apt_preference[backports]", :immediately
108 end
109
110 apt_repository "openstreetmap" do
111   uri "https://apt.openstreetmap.org"
112   components ["main"]
113   key "https://apt.openstreetmap.org/gpg.key"
114 end
115
116 package "unattended-upgrades"
117
118 if Dir.exist?("/usr/share/unattended-upgrades")
119   auto_upgrades = if node[:apt][:unattended_upgrades][:enable]
120                     IO.read("/usr/share/unattended-upgrades/20auto-upgrades")
121                   else
122                     IO.read("/usr/share/unattended-upgrades/20auto-upgrades-disabled")
123                   end
124
125   file "/etc/apt/apt.conf.d/20auto-upgrades" do
126     user "root"
127     group "root"
128     mode "644"
129     content auto_upgrades
130   end
131 end
132
133 template "/etc/apt/apt.conf.d/60chef" do
134   source "apt.conf.erb"
135   owner "root"
136   group "root"
137   mode "644"
138 end