Skip to content

Instantly share code, notes, and snippets.

@jjwatt
Created December 27, 2012 21:13
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 jjwatt/4392033 to your computer and use it in GitHub Desktop.
Save jjwatt/4392033 to your computer and use it in GitHub Desktop.
quick hack to make build-couchdb work with ruby 1.8 or whatever. I don't really know ruby, but rake kept failing about the Hash initialization, so I found some way to make it work and I think it's related to differences in ruby 1.8 and 1.9. So far the build seems to be working with this. This is build-couchdb/tasks/lib/distros.rb
# Distribution (platform) detection
def detect_distro
# OSX
if `uname`.chomp == 'Darwin'
os_release = %x[ sysctl -n kern.osrelease ].chomp
return [:osx, os_release]
end
# Solaris
if `uname`.chomp == "SunOS"
return [:solaris, `uname -r`.chomp]
end
if `uname -r`.chomp[-4..-1] == "ARCH"
return [:arch, `uname -r`.chomp]
end
# Ubuntu
if File.exist? '/etc/lsb-release'
# info = Hash[ *File.new('/etc/lsb-release').lines.map{ |x|
# x.split('=').map { |y| y.chomp } }.flatten ]
info = File.new('/etc/lsb-release').lines.map{ |x| x.split('=').map {|y| y.chomp}}
if info.assoc('DISTRIB_ID')[1] == 'Ubuntu'
return [:ubuntu, info.assoc('DISTRIB_RELEASE')[1]]
elsif info.assoc('DISTRIB_ID')[1] == 'LinuxMint'
return [:ubuntu, info.assoc('DISTRIB_RELEASE')[1]]
end
end
# Debian
ver = '/etc/debian_version'
return [:debian, File.new(ver).readline.chomp] if !File.exist?('/etc/lsb-release') && File.exist?(ver)
# Fedora
if File.exist? '/etc/fedora-release'
release = File.new('/etc/fedora-release').readline.match(/Fedora release (\d+)/)[1]
return [:fedora, release]
end
# Red Hat # TODO: Do not piggyback the :fedora version.
if File.exist? '/etc/redhat-release'
match = File.new('/etc/redhat-release').readline.match(/Red Hat Enterprise Linux Server release (\S+)/)
if match
release = match[1]
return [:fedora, release]
end
end
# CentOS # TODO: Do not piggyback the :fedora version
if File.exist? '/etc/redhat-release'
match = File.new('/etc/redhat-release').readline.match(/CentOS release (\S+)/)
if match
release = match[1]
return [:fedora, release]
end
end
# Scientific Linux
if File.exist? '/etc/redhat-release'
if RUBY_VERSION <= '1.8.7'
raise 'Version of ruby is too old. Consider installing a more recent version'
end
release = File.new('/etc/redhat-release').readline.match(/Scientific Linux SLF release (\d+)/)[1]
return [:slf, release]
end
# OpenSUSE
if File.exist? '/etc/SuSE-release'
release = File.new('/etc/SuSE-release').readline.match(/openSUSE (\d+)/)[1]
return [:opensuse, release]
end
# Amazon Linux AMI
if File.exist? '/etc/system-release'
match = File.new('/etc/system-release').readline.match(/Amazon Linux AMI release/)
if match
return [:fedora, '5.5']
end
end
raise StandardError, 'could not find distribution, maybe your OS isn\'t supported'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment