Created
July 2, 2025 00:17
-
-
Save kenyon/aa708a160fad05669147e7d67d664098 to your computer and use it in GitHub Desktop.
get_puppet_enterprise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# frozen_string_literal: true | |
# This script downloads the given version of Puppet Enterprise and agent repo | |
# packages to our repo location. Releases: https://www.puppet.com/releases | |
# Command line arguments: <PE version> <primary server Ubuntu version> [agent version] | |
# Example: get_puppet_enterprise 2025.3.0 24.04 | |
# Example with agent version: get_puppet_enterprise 2025.4.0 24.04 8.13.1 | |
# Only need to provide the agent version if | |
# https://forge.puppet.com/private/versions/pe hasn't been updated with the PE | |
# version you want to download (it's not always updated immediately after a PE | |
# release). See https://help.puppet.com/pe/current/topics/software_components_installed.htm | |
require 'English' | |
require 'fileutils' | |
require 'json' | |
require 'open-uri' | |
# type os_name os_version os_arch fips | |
downloads = [ | |
%w[perepo el 8 x86_64 false], | |
%w[perepo el 9 x86_64 false], | |
%w[perepo el 8 x86_64 true], | |
%w[perepo el 9 x86_64 true], | |
%w[perepo ubuntu 22.04 amd64 false], | |
%w[perepo ubuntu 24.04 amd64 false], | |
%w[native windows 11 x64 false], | |
%w[native windows 11 x64 true], | |
] | |
# This "password" is a UUID that comes from our PE license. | |
download_password = 'FIXME' | |
destination = '/repo/puppet' | |
pe_version = ARGV[0] | |
ubuntu_version = ARGV[1] | |
primary_server_tarball = "puppet-enterprise-#{pe_version}-ubuntu-#{ubuntu_version}-amd64.tar.gz" | |
primary_server_tarball_url = "https://pm.puppetlabs.com/puppet-enterprise/#{pe_version}/#{primary_server_tarball}" | |
def agent_version(pe_version = ARGV[0]) | |
pe_release_series = "#{pe_version.split('.').first(2).join('.')}.x" | |
ARGV[2] || JSON.parse(URI.open('https://forge.puppet.com/private/versions/pe').read).find do |release| | |
release['release'] == pe_release_series | |
end['versions'].find do |version| | |
version['version'] == pe_version | |
end['agent'] | |
rescue NoMethodError | |
warn "Could not find agent version for PE version #{pe_version} in https://forge.puppet.com/private/versions/pe" | |
exit 1 | |
end | |
repos_dir = File.join('puppet-agent', pe_version, agent_version, 'repos') | |
`gpg --keyserver keyserver.ubuntu.com --receive-keys 0xD6811ED3ADEEB8441AF5AA8F4528B6CD9E61EF26` | |
FileUtils.cd(destination, verbose: true) do | |
[ | |
'', | |
'.asc', | |
].each do |extension| | |
`wget --continue --content-disposition #{primary_server_tarball_url}#{extension}` | |
end | |
`gpg --verify #{primary_server_tarball}.asc #{primary_server_tarball}` | |
raise "GPG verification failed for #{primary_server_tarball}" unless $CHILD_STATUS.success? | |
%w[ | |
windows | |
windowsfips | |
].each do |dir| | |
FileUtils.mkdir_p(File.join(repos_dir, dir), verbose: true) | |
end | |
end | |
downloads.each do |type, os_name, os_version, os_arch, fips| | |
dir = if os_name == 'windows' | |
fips == 'true' ? 'windowsfips' : 'windows' | |
else | |
'.' | |
end | |
FileUtils.cd(File.join(destination, repos_dir, dir), verbose: true) do | |
`wget --continue --content-disposition --user='license-id' --password='#{download_password}' \ | |
'https://artifacts-puppetcore.puppet.com/v1/download?version=#{agent_version}&type=#{type}&os_name=#{os_name}&os_version=#{os_version}&os_arch=#{os_arch}&fips=#{fips}'` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment