#!/usr/bin/env ruby
#= Backup_epwww2local.rb
#
#  * Developers: Morikawa Yasuhiro
#  * Version: 2005/03/07 12:31:40
#
# epwww から local にバックアップを行う。
# RsyncBackup クラスに依存する。
# 
#==USAGE
#
#     % Backup_epwww2local.rb [options] [dir [dir ...]]
#
#===OPTIONS
#
#   --n                : for test (not exec "rsync")
#   --check            : for test (exec "rsync" with "-n" option)
#   --delete           : add "--delete" option
#   --nodelete         : remove "--delete" option
#   --logauto          : log to appropriate logfile
#   --log <logfile>    : output rsync command messages to <logfile>
#
#==ToDo
#
# 今のところなし。
#
#==HISTORY
#
#   * 2005/03/07 12:32:03  Yasuhiro Morikawa
#     * 作成
#
##################################################

require "getoptlong"      # for option_parse
require "rsync_backup"    # for "RsyncBackup"

############################################################################

##################################################
## +++             Main Routine             +++ ##

## parse options
parser = GetoptLong.new
parser.set_options(
                   ###    global option   ###
                   ['--n',     GetoptLong::NO_ARGUMENT], # for test  (not exec "rsync")
                   ['--check', GetoptLong::NO_ARGUMENT], # for test (exec "rsync" with "-n" option)
                   ['--delete',GetoptLong::NO_ARGUMENT], # add "--delete" options
                   ['--nodelete',GetoptLong::NO_ARGUMENT], # remove "--delete" options
                   ['--logauto',GetoptLong::NO_ARGUMENT], # log to appropriate logfile
                   ['--log',   GetoptLong::REQUIRED_ARGUMENT] # log to <logfile>
                   )
begin
  parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'"  # strage option value to $OPT_val
  end
rescue
  exit(1)
end


if $0 == __FILE__

  rsyncitem = RsyncBackup.new("~epnetfan/public_html/keiei/pc/doc2005/wireless", 
                              "www.ep.sci.hokudai.ac.jp",
                              "~/Documents/html/y2005/wireless", nil)

  rsyncitem.excludeopt($0) # バックアップスクリプト本体を消さないように
  rsyncitem.noexec($OPT_n)        if $OPT_n
  rsyncitem.logfile($OPT_logauto) if $OPT_logauto
  rsyncitem.logfile($OPT_log)     if $OPT_log
  rsyncitem.rsh
  rsyncitem.checkopt($OPT_check)  if $OPT_check
  rsyncitem.deleteopt(true)
  rsyncitem.deleteopt(!$OPT_delete) if $OPT_nodelete
  rsyncitem.partly(ARGV)
  rsyncitem.run

end
