#!/usr/bin/env ruby

msfbase = '/usr/share/metasploit'

Dir.chdir(msfbase)

$stderr.puts "[*]"
$stderr.puts "[*] Attempting to update the Metasploit Framework..."
$stderr.puts "[*]"
$stderr.puts ""

wait = (ARGV.shift.to_s == "wait")

have_configdir = false
ARGV.each do |arg|
	next unless arg =~ /--config-dir/
	have_configdir = true
end

unless have_configdir
	configdir = File.join(msfbase, "data", "svn")
	# Spaces in the directory should be fine since this whole thing is passed
	# as a single argument via the multi-arg syntax for system() below.
	ARGV.push("--config-dir=#{configdir}")
end


system("svn", "cleanup")
system("svn", "update", *ARGV)

if wait
	$stderr.puts ""
	$stderr.puts "[*] Please hit enter to exit"
	$stderr.puts ""	
	$stdin.readline
end
