about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-05-06 21:39:34 +0000
committerEric Wong <e@80x24.org>2014-05-06 21:39:34 +0000
commit9f5697d64b6e536ee7f9a248d5903dd1e2a2b376 (patch)
tree5426f56e3fbbd66f8bb8f18d712dd1d6099be285
parent5b43edd70cad4944fc9eadf9477613daa931bc31 (diff)
Rubyforge about to be dead.
-rw-r--r--archive/rfmig.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/archive/rfmig.rb b/archive/rfmig.rb
new file mode 100644
index 0000000..033051a
--- /dev/null
+++ b/archive/rfmig.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+require 'find'
+require 'fileutils'
+rfdir = 'rubyforge.org:/var/www/gforge-projects/clogger/'
+newbase = 'http://clogger.bogomips.org/'
+refresh = '<meta http-equiv="refresh" content="0; url=%s" />'
+old = 'rf.old'
+new = 'rf.new'
+cmd = %W(rsync -av #{rfdir} #{old}/)
+unless File.directory?(old)
+  system(*cmd) or abort "#{cmd.inspect} failed: #$?"
+end
+
+Find.find(old) do |path|
+  path =~ /\.html\z/ or next
+  data = File.read(path)
+  tmp = path.split(%r{/})
+  tmp.shift == old or abort "BUG"
+  dst = "#{new}/#{tmp.join('/')}"
+
+  tmp[-1] = '' if tmp[-1] == "index.html"
+  url = "#{newbase}#{tmp.join('/')}"
+  meta = sprintf(refresh, url)
+  data.sub!(/(<head[^>]*>)/i, "#$1#{meta}")
+  data.sub!(/(<body[^>]*>)/i,
+            "#{$1}Redirecting to <a href=\"#{url}\">#{url}</a> ...<br/>")
+  FileUtils.mkdir_p(File.dirname(dst))
+  File.open(dst, "w") { |fp| fp.write(data) }
+end
+
+print "Verify results in #{new}/, then run:\n  "
+puts %W(rsync -av #{new}/ #{rfdir}).join(' ')