This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapt.rb
More file actions
55 lines (47 loc) · 1.45 KB
/
apt.rb
File metadata and controls
55 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
dep "our apt source" do
requires "apt source".with(uri: "http://apt.tc-dev.net/", repo: "main")
requires "gpg key".with("B6D8A3F9")
end
dep "apt sources", for: :ubuntu do
met? do
Babushka::Renderable.new("/etc/apt/sources.list").from?(dependency.load_path.parent / "apt/sources.list.erb")
end
meet do
render_erb "apt/sources.list.erb", to: "/etc/apt/sources.list"
shell "rm -f /etc/apt/sources.list.d/babushka.list"
Babushka::AptHelper.update_pkg_lists "Updating apt lists with our new config"
end
end
dep "upgrade apt packages", template: "task" do
requires "aptitude.bin"
run do
log_shell("Upgrading installed packages", "#{Babushka::AptHelper.pkg_cmd} -y full-upgrade")
end
end
dep "apt packages removed", :packages, for: :apt do
def installed_packages
shell("dpkg --get-selections").split("\n").select {|l|
l[/\binstall$/]
}.map do |l|
l.split(/\s+/, 2).first
end
end
def to_remove(packages)
# This is required because babushka parameters aren't enumerable yet.
package_list = packages.to_a
installed_packages.select do |installed_package|
package_list.any? {|p| installed_package[p] }
end
end
met? do
to_remove(packages).empty?
end
meet do
to_remove(packages).each do |pkg|
log_shell "Removing #{pkg}", "apt-get -y remove --purge '#{pkg}'", sudo: true
end
end
after do
log_shell "Autoremoving packages", "apt-get -y autoremove", sudo: true
end
end