bin/gemsync in gemsync-0.1.4 vs bin/gemsync in gemsync-0.1.5

- old
+ new

@@ -6,20 +6,20 @@ require 'trollop' # Setup arguments from the command line. # This uses the trollop library on github. opts = Trollop::options do - version "gemsync 0.1.4 (c) 2010 Josh Ellithorpe" + version "gemsync 0.1.5 (c) 2010 Josh Ellithorpe" banner <<-EOS Small gem to sync multiple gem installations. Usage: gemsync [options] Available Options: EOS opt :source, "Either the ruby installation directory, or a list of gems produced from 'gem list'. Ex: /usr or /path/to/gemlist.txt", :type => String, :required => true - opt :destination, "Ruby installation directory you want to sync up. Ex: /opt/ruby-enterprise", :type => String, :required => true + opt :destination, "Ruby installation directory you want to sync up. Ex: /opt/ruby-enterprise", :type => String, :required => false opt :disable_sudo, "Disable sudo when installing gems", :default => false opt :build_docs, "Build documentation", :default => false end # Check if the file or directory exists, if not exit @@ -31,18 +31,24 @@ else @source_type = 'directory' Trollop::die :source, "\n\t-- Binary '#{opts[:source]}/bin/gem' does not exist" unless File.exists?("#{opts[:source]}/bin/gem") end -# Die if destination is set incorrectly -Trollop::die :destination, "\n\t-- Directory '#{opts[:destination]}' does not exist" unless File.directory?(opts[:destination]) -Trollop::die :destination, "\n\t-- Binary '#{opts[:destination]}/bin/gem' does not exist" unless File.exists?("#{opts[:destination]}/bin/gem") +# Attempt to set default destination based upon location of 'gem' binary +if opts[:destination].nil? + guessed_destination_path = `which gem`.split('/')[0..-3].join('/') + Trollop::die :destination, "\n\t-- Destination was not set, and gemsync could not guess it" if (guessed_destination_path == opts[:source] || !File.directory?(guessed_destination_path)) +else + # Die if destination is set incorrectly + Trollop::die :destination, "\n\t-- Directory '#{opts[:destination]}' does not exist" unless File.directory?(opts[:destination]) + Trollop::die :destination, "\n\t-- Binary '#{opts[:destination]}/bin/gem' does not exist" unless File.exists?("#{opts[:destination]}/bin/gem") +end # Cleanup main and sync dir, they shouldn't end in a '/' so lets chomp it. # Couldn't use chomp! since opts are frozen. @main_dir = opts[:source].chomp('/') -@sync_dir = opts[:destination].chomp('/') +@sync_dir = opts[:destination].nil? ? guessed_destination_path.chomp('/') : opts[:destination].chomp('/') # Setup additional flags @docstring = opts[:build_docs] ? '' : '--no-ri --no-rdoc' @sudostring = opts[:disable_sudo] ? '' : (`which sudo`.strip + ' ') # Just stripping newline @@ -126,12 +132,12 @@ for version in (gem_versions.split(", ") - current_gem_versions) if gem_name == "mysql" # Also look for mysql5 type binaries that some package managers use mysql_config = `which mysql_config` || `which mysql_config5` mysql_dir = `which mysql` || `which mysql5` - mysql_dir = mysql_dir.split('/')[0..-2].join('/') + mysql_dir = mysql_dir.split('/')[0..-3].join('/') system("#{@sudostring}#{@sync_dir}/bin/gem install #{gem_name} -v #{version} -- --with-mysql-dir=#{mysql_dir} --with-mysql-config=#{mysql_config} #{@docstring}") else system("#{@sudostring}#{@sync_dir}/bin/gem install #{gem_name} -v #{version} #{@docstring}") end end -end \ No newline at end of file +end