Skip to content

Instantly share code, notes, and snippets.

@Raboo
Last active March 4, 2019 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raboo/6e12dbf9527e4da466f0601afadac5ab to your computer and use it in GitHub Desktop.
Save Raboo/6e12dbf9527e4da466f0601afadac5ab to your computer and use it in GitHub Desktop.
chef aptly cookbook mirroring ubuntu repos
# ubuntu
excluded_sections = '!Section (comm), !Section (debug), !Section (fonts), !Section (games), !Section (gnome), !Section (graphics), !Section (kde), !Section (localization), !Section (math), !Section (restricted/x11), !Section (science), !Section (sound), !Section (translations), !Section (universe/comm), !Section (universe/debug), !Section (universe/electronics), !Section (universe/embedded), !Section (universe/fonts), !Section (universe/games), !Section (universe/gnome), !Section (universe/gnustep), !Section (universe/graphics), !Section (universe/hamradio), !Section (universe/kde), !Section (universe/localization), !Section (universe/math), !Section (universe/news), !Section (universe/science), !Section (universe/sound), !Section (universe/translations), !Section (universe/video), !Section (universe/x11), !Section (universe/xfce), !Section (universe/zope), !Section (video), !Section (x11), !Section (zope)'
# packages that we want to include from excluded sections
included_packages = '| fonts-dejavu| fonts-dejavu-core| fonts-dejavu-extra| fonts-ubuntu-font-family-console| fontconfig-config| fontconfig| debconf-i18n| krb5-locales| locales| squid-langpack| tzdata| bc| dc| libx11-data| plymouth| plymouth-theme-ubuntu-text| x11-common| xauth| xkb-data| dbus-x11| imagemagick| graphviz| update-notifier-common| python-software-properties'
date = Time.now.strftime('%Y.%m.%d')
['bionic','bionic-security','bionic-updates','xenial','xenial-security','xenial-updates','trusty','trusty-security','trusty-updates'].each do |distro|
aptly_mirror "ubuntu-#{distro}" do
distribution distro
component 'main restricted universe'
keyid '40976EAF437D05B5 3B4FE6ACC0B21F32'
keyserver 'keyserver.ubuntu.com'
uri 'http://no.archive.ubuntu.com/ubuntu'
filter excluded_sections+included_packages
filter_with_deps false
timeout 18000
action [ :create ]
end
aptly_snapshot "ubuntu-#{distro}-#{date}" do
from "ubuntu-#{distro}"
type 'mirror'
notifies :update, "aptly_mirror[ubuntu-#{distro}]", :before
end
end
['bionic','xenial','trusty'].each do |distro|
aptly_snapshot "ubuntu-#{distro}-#{date}-merged" do
merge_sources ["ubuntu-#{distro}-#{date}", "ubuntu-#{distro}-security-#{date}", "ubuntu-#{distro}-updates-#{date}"]
no_remove true
action :merge
end
aptly_publish "ubuntu-#{distro}-#{date}-merged" do
type 'snapshot'
distribution distro
component %w(main)
prefix "#{distro}/ubuntu"
endpoint 'filesystem:default'
not_if "aptly publish list -raw | grep 'filesystem:default:#{distro}/ubuntu #{distro}'", user: node['aptly']['user'], group: node['aptly']['group'], environment: aptly_env
timeout 18000
end
execute "aptly-publish-switch-ubuntu-#{distro}" do
command "aptly publish switch -batch -passphrase='#{node['aptly']['gpg']['passphrase']}' #{distro} filesystem:default:#{distro}/ubuntu ubuntu-#{distro}-#{date}-merged"
sensitive true
user node['aptly']['user']
group node['aptly']['group']
environment aptly_env
timeout 18000
action :run
only_if "aptly publish list -raw | grep 'filesystem:default:#{distro}/ubuntu #{distro}'"
only_if "aptly snapshot list -raw | grep 'ubuntu-#{distro}-#{date}-merged'"
not_if "aptly publish list | grep 'filesystem:default:#{distro}/ubuntu/#{distro}' | grep ubuntu-#{distro}-#{date}-merged"
end
execute "aptly-snapshot-drop-ubuntu-#{distro}" do
command "aptly snapshot list -raw |grep ubuntu-#{distro} | grep -v #{date} | sort -t- -k 4 -r | xargs -n1 -r aptly snapshot drop"
user node['aptly']['user']
group node['aptly']['group']
environment aptly_env
only_if "aptly snapshot list -raw | grep 'ubuntu-#{distro}-#{date}-merged'"
action :nothing
subscribes :run, "execute[aptly-publish-switch-ubuntu-#{distro}]", :delayed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment