View previous topic :: View next topic |
Author |
Message |
Alcarohtar n00b
Joined: 29 Apr 2005 Posts: 6
|
Posted: Fri Apr 29, 2005 12:33 am Post subject: qemerge: a small utility to update the system |
|
|
Hi.
qemerge is a simple script to help those who want to have the system always updated. It will do an emerge -utp world and install, one by one, the packages outdated.
It has, however, two problems: first, it doesn't install dependencies. second, it doesn't install a package if it's not a completely new version (ie, it won't download xiba-1.1.0-r2 if you have xiba-1.1.0-r1). Actually, I like this feature, because most revisions are pretty much not very important. It can be easily turned off.
Also, you can "mask" certain bigger packages, that you prefer to install by hand, like a glibc or a new X, that take a while to compile.
Finally, it will download packages while installing them.
I know this is not production ready and there is probably already something like this, but it has served me quite well for the past few months and so, I'd like to share it with you.
Oh, by the way. It was written in ruby. If you don't want to bother emerging ruby, don't.
The code:
Code: |
#!/usr/bin/ruby -w
require 'thread'
# masked packages (partial name only)
masked = %w(
xorg
gentoo-dev-sources
kde
development-sources
glibc
gcc
firefox
thunderbird
sun-jdk
)
# 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_r (inst, new)
exp = /(.*)-r/
inst =~ exp
inst_version = $1 || inst
new =~ exp
new_version = $1 || new
true if inst_version == new_version
end
# ./qemerge -f only fetchs packages
fetchonly = ARGV[0] == '-f'
# list of packages to update
packages = `emerge -utp world`.collect do |line|
line =~ /\[ebuild.*\].*/
line
end
# filter revisions
todo = packages.collect do |line|
line =~ /\[ebuild.*\] [-\w]*\/([-\w\.]*) \[(.*)\]/
package = $1
new_version = $2
package =~ /-(\d[-_\d\.r\w]+)\b/
inst_version = $1
package unless differ_by_r(inst_version, new_version)
end.compact!
#filter masked
todo.collect! do |p|
p unless masked.detect { |x| p.include?(x) }
end.compact!
printf("\n I'm going to install the following packages:\n\n")
todo.each { |p| puts(" . #{p}") }
puts
# - 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 fetchonly
threads << Thread.new(p) do |package|
mutex.synchronize do
puts(" + emerging #{package}...")
s = system("emerge =#{package} &> /dev/null")
printf(" + %-60s [ %-5s ]\n", package, s)
end
end
}
threads.each { |t| t.join() }
|
|
|
Back to top |
|
|
rhill Retired Dev
Joined: 22 Oct 2004 Posts: 1629 Location: sk.ca
|
Posted: Fri Apr 29, 2005 2:50 am Post subject: |
|
|
cool. we need more ruby stuff. _________________ by design, by neglect
for a fact or just for effect |
|
Back to top |
|
|
regeya Apprentice
Joined: 28 Jul 2002 Posts: 270 Location: Desoto, IL, USA
|
Posted: Sat May 28, 2005 6:18 am Post subject: |
|
|
Neat idea, and nice to see a bit of Ruby invading Gentoo. _________________ Why, yes, I am a bore. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|