#!/usr/bin/env ruby -w # # Author:: Christian Reiniger # License:: GNU GPL v2 or later, as described in the accompanying LICENSE file # Homepage: http://dsadmin.dotsrc.org/ # # ---- # Last change: # # CVS User:: $Author: creinig $ # Date:: $Date: 2006-10-24 10:29:33 +0200 (Tue, 24 Oct 2006) $ # Revision:: $Revision: 110 $ # require 'optparse' require 'ostruct' require 'pp' # This gets overridden by "make install" INSTALL_PATH = Dir.getwd # Set library path containing the main code. # admind binary ($0) is in $(PREFIX)/sbin, libs are in $(PREFIX)/lib $: << File.expand_path(File.join(INSTALL_PATH, 'lib')) def quote(aString) "'" + aString.gsub(/[']/) { '\\\'' } + "'" end def parseOpts options = OpenStruct.new options.lftp = '/usr/bin/lftp' options.user = quote('anonymous') options.pass = quote('place@holder.org') options.port = 21 opts = OptionParser.new do |opts| opts.banner = "Wrapper for lftp's 'mirror' command.\n" + "Usage: lftp-mirror.rb [options] [-- mirroropt ...]" opts.separator "" opts.separator "Options:" opts.on("--lftp STRING", String, "Specify the lftp command to use", " [/usr/bin/lftp]") do |val| options.lftp = val end opts.on("--user STRING", String, "Username for authentication [anonymous]") do |val| options.user = quote(val) end opts.on("--pass STRING", String, "Password for authentication", " [place@holder.org]") do |val| options.pass = quote(val) end opts.on("--host STRING", String, "Remote host") do |val| options.host = quote(val) end opts.on("--port INT", Integer, "Remote port [21]") do |val| options.port = val end opts.on("--rdir STRING", String, "Remote directory") do |val| options.rdir = quote(val) end opts.on("--ldir STRING", String, "Local directory") do |val| options.ldir = quote(val) end opts.on("--help", "Show this message") do puts opts exit end opts.separator "" opts.separator "'mirroropt' can be options that are passed verbatim" opts.separator "to lftp's 'mirror' command" end opts.parse!(ARGV) %w{lftp user pass host port rdir ldir}.each { |key| if(options.send(key).nil?) puts "Option '#{key}' missing" puts puts opts exit(-1) end } options end options = parseOpts options.more = ARGV.collect { |item| quote(item) } o = options # convenience alias cmdstring = "open -u #{o.user},#{o.pass} -p #{o.port} #{o.host} ; " + "cd #{o.rdir} ; " + "mirror #{o.more.join(" ")} ./ #{o.ldir}" #pp [o.lftp, "-c", cmdstring] Kernel.exec(o.lftp, "-c", cmdstring)