-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqemerge
91 lines (74 loc) · 2.1 KB
/
qemerge
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
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/ruby -w
require 'thread'
# masked packages (partial name only)
masked = %w(
glibc
gcc
sun-jdk
vanilla-sources
firefox
mono
)
# Checks if the new package is not an entirely new version but just a new
# revision.
# I.e., it will succeed if the installed package is at version 3.3.0-r2
# and the new package is at 3.3.0-r3.
def differ_by_revision (inst, new)
exp = /(.*)-r/
inst =~ exp
inst_version = $1 || inst
new =~ exp
new_version = $1 || new
true if inst_version == new_version
end
options = ARGV[0].to_s
# list of packages to update
packages = `emerge -p #{options.delete('f')} #{ARGV[1..-1].join(" ")
}`.collect do |line|
line =~ /\[ebuild.*\].*/
line
end
# filter revisions
todo = packages.collect do |line|
line =~ /\[ebuild.*\] ([-\w]*\/[-+\w\.]*) (\[(.*)\])?/
package = $1
new_version = $3
package =~ /-(\d[-_\d\.r\w]+)\b/
inst_version = $1
package unless differ_by_revision(inst_version, new_version)
end.compact!
puts
#filter masked
todo.collect! do |p|
if masked.detect { |x| p.include?(x) }
puts(" [/] #{p}")
else
p
end
end.compact!
printf("\n I'm going to install the following packages:\n\n")
todo.each { |p| puts(" . #{p}") }
puts
exit if options.include?('p')
# - There can be only one thread fecthing at once
# - There can be only one thread emerging at once
# - There can be one thread fetching while some other thread emerges
# - Before emerging, the thread must acquire one mutex and remains
# blocked util that mutex becomes available
threads = []
mutex = Mutex.new()
todo.each { |p|
next if masked.detect { |x| p.include?(x) }
puts(" - fetching #{p}...")
r = system("emerge -f =#{p} &> /dev/null")
printf(" - %-60s [ %-5s ]\n", p, r)
next if not r or options.include?('f')
threads << Thread.new(p) do |package|
mutex.synchronize do
puts(" + emerging #{package}...")
s = system("emerge -1 =#{package} &> /dev/null")
printf(" + %-60s [ %-5s ]\n", package, s)
end
end
}
threads.each { |t| t.join() }