# FNM_DOTMATCH so that ../site/.htaccess is uploaded like any other file
def site_glob(pattern)
  Dir.glob(pattern, File::FNM_DOTMATCH).reject{|f| File.basename(f) =~ /\A\.\.?\z/ }
end

site_glob("../site/**/*").reject{|f| File.directory? f }.each{|filename|
  if !File.exist?(uploaded_filename=filename.sub("site","site_uploaded")) || File.read(filename) != File.read(uploaded_filename)
    dest_dir = File.dirname(filename).sub("../site","public_html/iogii")
    `mkdir -p #{File.dirname(uploaded_filename)}`
    `putweb golfscript.com #{dest_dir}/ #{filename} && mv #{filename} #{uploaded_filename}`
  else
    `rm #{filename}`
  end
}
site_glob("../site/*").each{|d| Dir.rmdir(d) if File.directory?(d) && Dir.empty?(d) }
raise if !site_glob("../site/*").empty?
