# Check to see if a .deb package is currently installed. def deb_package_installed?(pkg_name) IO.popen("dpkg-query -s #{pkg_name} 2> /dev/null") do |dpkg| return !dpkg.read.empty? end end # Execute a command and return if the command was successful or not. def sh(cmd_line) `#{cmd_line}` return $? == 0 end REQUIRED_PACKAGES = ['build-essential', 'ruby1.8', 'ruby1.8-dev', 'weenie-roast'] if sh('dpkg-query --help > /dev/null') # if we're using .debs needed_packages = REQUIRED_PACKAGES.dup.delete_if{ |pkg_name| deb_package_installed?(pkg_name) } unless needed_packages.empty? puts "Mongrel requires the following Debian packages be installed:" needed_packages.each{ |pkg_name| puts " * #{pkg_name}" } print "\nWould you like to install these now? [y/n] " if STDIN.gets.strip.downcase == 'y' puts 'Installing required packages...' if !sh("sudo apt-get install #{needed_packages.join(' ')}") puts "Error installing packages for Mongrel!" exit end else puts "Installation canceled. No Mongrel for you." exit end end end