| 1 |
|
| 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 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
def self.builtin_map |
| 24 |
{ |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 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", |
| 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", |
| 48 |
"sles/15.7", |
| 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", |
| 59 |
"fedora/43", |
| 60 |
"fedora/44", |
| 61 |
"opensuse/16.0", |
| 62 |
"sles/16.0", |
| 63 |
], |
| 64 |
}, |
| 65 |
|
| 66 |
|
| 67 |
|
| 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", |
| 76 |
"linuxmint/vanessa", |
| 77 |
"linuxmint/vera", |
| 78 |
"linuxmint/victoria", |
| 79 |
"linuxmint/virginia", |
| 80 |
"ubuntu/jammy", |
| 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", |
| 91 |
"linuxmint/faye", |
| 92 |
"linuxmint/wilma", |
| 93 |
"linuxmint/xia", |
| 94 |
"linuxmint/zara", |
| 95 |
"linuxmint/zena", |
| 96 |
"ubuntu/noble", |
| 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", |
| 107 |
"debian/forky", |
| 108 |
"linuxmint/gigi", |
| 109 |
"ubuntu/resolute", |
| 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 |