Debian Codegraph @

script/distro-tool

raw symbols SCIP
1 #!/usr/bin/env ruby
2
3 require 'optionparser'
4
5 class DistroMap
6 attr_reader :entries
7
8 def initialize(map = nil)
9 @entries = map || self.class.builtin_map
10 end
11 # Returns the map for our distros.
12 #
13 # The key in each case is a string containing a lowercase OS name, a slash,
14 # and a version number. The value is a map containing the following fields:
15 #
16 # name:: a human-readable name for this distro.
17 # component:: a component suitable for a packagecloud.io URL.
18 # image:: a Docker image name from build_dockers without any extension.
19 # equivalent:: packagecloud.io components for which we can upload the same
20 # package.
21 # package_type:: the extension for the package format on this OS.
22 # package_tag:: the trailing component after the version number on this OS.
23 def self.builtin_map
24 {
25 # RHEL EOL https://access.redhat.com/support/policy/updates/errata
26 # Fedora EOL https://docs.fedoraproject.org/en-US/releases/
27 # SLES EOL https://www.suse.com/lifecycle/
28 # opensuse https://en.opensuse.org/Lifetime
29 # or https://en.wikipedia.org/wiki/OpenSUSE_version_history
30 "centos/8" => {
31 name: "RPM RHEL 8/Rocky Linux 8",
32 component: "el/8",
33 image: "centos_8",
34 package_type: "rpm",
35 package_tag: "-1.el8",
36 equivalent: [
37 "el/8", # EOL May 2029
38 ],
39 },
40 "rocky/9" => {
41 name: "RPM RHEL 9/Rocky Linux 9",
42 component: "el/9",
43 image: "rocky_9",
44 package_type: "rpm",
45 package_tag: "-1.el9",
46 equivalent: [
47 "el/9", # EOL May 2032
48 "sles/15.7", # EOL July 2031
49 ],
50 },
51 "rocky/10" => {
52 name: "RPM RHEL 10/Rocky Linux 10",
53 component: "el/10",
54 image: "rocky_10",
55 package_type: "rpm",
56 package_tag: "-1.el10",
57 equivalent: [
58 "el/10", # EOL May 2035
59 "fedora/43", # EOL December 2026
60 "fedora/44", # EOL May 2027
61 "opensuse/16.0", # EOL October 2027
62 "sles/16.0", # EOL November 2027
63 ],
64 },
65 # Debian EOL https://wiki.debian.org/LTS/
66 # Ubuntu EOL https://wiki.ubuntu.com/Releases
67 # Mint EOL https://linuxmint.com/download_all.php
68 "debian/11" => {
69 name: "Debian 11",
70 component: "debian/bullseye",
71 image: "debian_11",
72 package_type: "deb",
73 package_tag: "",
74 equivalent: [
75 "debian/bullseye", # EOL August 2026
76 "linuxmint/vanessa", # EOL April 2027
77 "linuxmint/vera", # EOL April 2027
78 "linuxmint/victoria", # EOL April 2027
79 "linuxmint/virginia", # EOL April 2027
80 "ubuntu/jammy", # EOL April 2027
81 ],
82 },
83 "debian/12" => {
84 name: "Debian 12",
85 component: "debian/bookworm",
86 image: "debian_12",
87 package_type: "deb",
88 package_tag: "",
89 equivalent: [
90 "debian/bookworm", # EOL June 2028
91 "linuxmint/faye", # LMDE LTS release based on Debian 12
92 "linuxmint/wilma", # EOL April 2029
93 "linuxmint/xia", # EOL April 2029
94 "linuxmint/zara", # EOL April 2029
95 "linuxmint/zena", # EOL April 2029
96 "ubuntu/noble", # EOL June 2029
97 ]
98 },
99 "debian/13" => {
100 name: "Debian 13",
101 component: "debian/trixie",
102 image: "debian_13",
103 package_type: "deb",
104 package_tag: "",
105 equivalent: [
106 "debian/trixie", # EOL June 2030
107 "debian/forky", # Current testing (Debian 14)
108 "linuxmint/gigi", # LMDE LTS release based on Debian 13
109 "ubuntu/resolute", # EOL July 2031
110 ]
111 },
112 }
113 end
114
115 def distro_name_map
116 entries.map { |k, v| [k, v[:equivalent]] }.to_h
117 end
118
119 def image_names
120 entries.values.map { |v| v[:image] }.to_a
121 end
122 end
123
124 class DistroMapProgram
125 def initialize(stdout, stderr, dmap = nil)
126 @dmap = DistroMap.new(dmap)
127 @stdout = stdout
128 @stderr = stderr
129 end
130
131 def image_names
132 @stdout.puts @dmap.image_names.join(" ")
133 end
134
135 def distro_markdown
136 platform_architectures = {
137 "rpm" => [
138 { arch: ".x86_64" },
139 ],
140 "deb" => [
141 { arch: "_amd64", name: "AMD64" },
142 { arch: "_arm64", name: "ARM64" },
143 ],
144 }
145 separator = {
146 "rpm" => "-",
147 "deb" => "_",
148 }
149 result = @dmap.entries.values.map do |entry|
150 type = entry[:package_type]
151 platform_architectures[type].map do |arch|
152 arch_name = arch.key?(:name) ? " (#{arch[:name]})" : ""
153 "[#{entry[:name]}#{arch_name}](https://packagecloud.io/github/git-lfs/packages/#{entry[:component]}/git-lfs#{separator[type]}VERSION#{entry[:package_tag]}#{arch[:arch]}.#{type}/download)\n"
154 end.join
155 end.join
156 @stdout.puts result
157 end
158
159 def run(args)
160 options = {}
161 OptionParser.new do |parser|
162 parser.on("--image-names", "Print the names of all images") do
163 options[:mode] = :image_names
164 end
165
166 parser.on("--distro-markdown", "Print links to packages for all distros") do
167 options[:mode] = :distro_markdown
168 end
169 end.parse!(args)
170
171 case options[:mode]
172 when nil
173 @stderr.puts "A mode option is required"
174 2
175 when :image_names
176 image_names
177 0
178 when :distro_markdown
179 distro_markdown
180 0
181 end
182 end
183 end
184
185 if $PROGRAM_NAME == __FILE__
186 exit DistroMapProgram.new($stdout, $stderr).run(ARGV)
187 end