#!/usr/bin/env ruby require 'rubygems' require 'trollop' require "sup"; Redwood::check_library_version_against "0.10.2" STATE_BACKUP_FN = "/tmp/sup-state.txt" SOURCE_BACKUP_FN = "sources.yaml-before-xapian-upgrade" BIN_DIR = File.dirname __FILE__ $opts = Trollop::options do version "sup-convert-ferret-index (sup #{Redwood::VERSION})" banner < "-v" opt :dry_run, "Don't actually do anything, just print out what would happen.", :short => "-n" opt :force, "Force overwrite of an old Xapian index" opt :version, "Show version information", :short => :none end def build_cmd cmd (ENV["RUBY_INVOCATION"] ? ENV["RUBY_INVOCATION"] + " " : "") + File.join(BIN_DIR, cmd) end def run cmd puts cmd unless $opts[:dry_run] startt = Time.now system cmd or abort printf "(completed in %.1fs)\n", (Time.now - startt) end puts end begin require 'xapian' rescue LoadError Trollop::die "you don't have the xapian gem installed, so this script won't do much for you--`gem install xapian` (or xapian-full) first" end Redwood::start index = Redwood::Index.init Trollop::die "you appear to already have a Xapian index--delete #{File.join(Redwood::BASE_DIR, "xapian")} or use --force if you really want to do this" unless Redwood::Index.is_a_deprecated_ferret_index? || $opts[:force] puts "## Step one: back up all message state to #{STATE_BACKUP_FN}" run "#{build_cmd 'sup-dump'} --index ferret > #{STATE_BACKUP_FN}" puts "## message state saved to #{STATE_BACKUP_FN}" source_backup_fn = File.join Redwood::BASE_DIR, SOURCE_BACKUP_FN puts "## Step two: back up sources.yaml file to #{source_backup_fn}" run "cp #{Redwood::SOURCE_FN} #{source_backup_fn}" puts "## Step three: build the Xapian index" run "#{build_cmd 'sup-sync'} --all --all-sources --index xapian --restore #{STATE_BACKUP_FN} #{$opts[:verbose] ? '--verbose' : ''}" puts "## xapian index successfully built!" puts <