-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapt-hold
executable file
·80 lines (64 loc) · 1.7 KB
/
apt-hold
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env ruby
require 'epitools'
require 'slop'
original_ARGV = ARGV.dup
opts = Slop.parse :help => true do
banner %{Usage: apt-hold [options] <package(s)>
Puts packages on "hold", so they won't be automatically upgraded by apt-get.
Example:
apt-hold google-chrome-stable}
on :l, :list, "List specified packages (or ALL packages if none specified)"
on :u, :unhold, "Unhold the package"
end
args = ARGV
# sudoifnotroot
unless Process.uid == 0
system("sudo", __FILE__, *original_ARGV)
exit
end
def selections
@selections ||= IO.popen("dpkg --get-selections") do |r|
Hash[ r.lines.map {|l| l.strip.split } ]
end
end
def selections_for(packages)
s = selections
packages.map { |arg| [ arg, s[arg] ] if s[arg] }.compact
end
def holds
selections.select{|pkg,state| state == "hold"}
end
STATE_INFO = {
"hold" => ["Hold", :light_green],
"install" => ["None", :grey]
}
def set_selections(packages, state)
input = packages.map { |pkg| "#{pkg} #{state}" }.join("\n")
puts input
IO.popen("dpkg --set-selections", "w") do |dpkg|
dpkg.puts input
end
end
def print_packages(packages)
#selections_for(args.flatten).each do |package, state|
packages.each do |package, state|
desc, color = STATE_INFO[state]
col1_width = packages.map{|k,v| k.size}.max + 2
puts "#{package.ljust(col1_width).light_yellow} => #{desc.send(color)}"
end
end
if opts.list?
if args.any?
print_packages selections_for(args)
else
print_packages holds
end
elsif args.empty?
puts "<8>(<9>Note: Type <11>--help</11> for directions.<8>)".colorize
puts
print_packages holds
elsif opts.unhold?
set_selections( args, "install" )
else
set_selections( args, "hold" )
end