2013-01-05 19:30:13 -05:00
|
|
|
#!/usr/bin/env ruby -wKU
|
|
|
|
|
|
|
|
raise "Git is required for the migration." if `which git`.empty?
|
|
|
|
raise "You must run this script from the root of your Octopress blog directory" unless File.exist? File.join(Dir.pwd, '_config.yml') and \
|
|
|
|
File.exist? File.join(Dir.pwd, 'Rakefile')
|
|
|
|
|
|
|
|
require "fileutils"
|
|
|
|
require "yaml"
|
|
|
|
|
2013-01-05 23:15:10 -05:00
|
|
|
LOCAL_OCTOPRESS_INSTALLATION = Dir.pwd
|
|
|
|
|
2013-01-05 19:30:13 -05:00
|
|
|
OCTO_GIT = "https://github.com/imathis/octopress.git"
|
2013-01-05 23:45:54 -05:00
|
|
|
NEW_OCTO = File.join(File.dirname(LOCAL_OCTOPRESS_INSTALLATION), "new-octopress")
|
2013-01-05 19:30:13 -05:00
|
|
|
|
|
|
|
OCTO_CONFIG_GIT = "https://github.com/octopress/sample-octopress-configuration"
|
2013-01-05 23:46:12 -05:00
|
|
|
OCTO_CONFIG_DEST = File.join(NEW_OCTO, "_config")
|
2013-01-05 19:30:13 -05:00
|
|
|
|
2013-01-05 23:46:33 -05:00
|
|
|
def old_octo_dir(*subdirs)
|
2013-01-05 19:30:13 -05:00
|
|
|
File.join(LOCAL_OCTOPRESS_INSTALLATION, *subdirs)
|
|
|
|
end
|
|
|
|
|
2013-01-05 23:46:33 -05:00
|
|
|
def new_octo_dir(*subdirs)
|
|
|
|
File.join(NEW_OCTO, *subdirs)
|
2013-01-05 19:30:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
# Make local copy of imathis/octopress
|
|
|
|
FileUtils.rm_rf tmp_octo_dir
|
2013-01-05 23:16:54 -05:00
|
|
|
system "git clone #{OCTO_GIT} #{tmp_octo_dir}"
|
2013-01-05 19:30:13 -05:00
|
|
|
|
|
|
|
# Make local copy of octopress/sample-octopress-configuration
|
2013-01-05 23:16:54 -05:00
|
|
|
FileUtils.rm_rf OCTO_CONFIG_DEST
|
2013-01-05 23:17:29 -05:00
|
|
|
system "git clone #{OCTO_CONFIG_GIT} #{OCTO_CONFIG_DEST}"
|
|
|
|
FileUtils.rm_rf File.join(OCTO_CONFIG_DEST, ".git")
|
2013-01-05 19:30:13 -05:00
|
|
|
|
|
|
|
# copy new theme to current directory
|
|
|
|
FileUtils.rm_rf curr_octo_dir('.themes', 'classic')
|
2013-01-05 23:18:07 -05:00
|
|
|
FileUtils.cp_r tmp_octo_dir('.themes', 'classic'), curr_octo_dir('.themes')
|
2013-01-05 19:30:13 -05:00
|
|
|
|
|
|
|
# migrate configuration
|
|
|
|
local_config = YAML.load(File.read(curr_octo_dir("_config.yml")))
|
|
|
|
|
|
|
|
FileUtils.mkdir_p curr_octo_dir('_config')
|
2013-01-05 23:16:54 -05:00
|
|
|
FileUtils.cp_r File.join(OCTO_CONFIG_DEST, 'defaults'), curr_octo_dir('_config'), :verbose => true, :remove_destination => true
|
2013-01-05 19:30:13 -05:00
|
|
|
|
|
|
|
# build site configs
|
|
|
|
site_config = {}
|
|
|
|
%w(classic.yml disqus.yml gauges_analytics.yml github_repos_sidebar.yml google_analytics.yml
|
|
|
|
google_plus.yml jekyll.yml share_posts.yml tweets_sidebar.yml).each do |yaml_file|
|
|
|
|
this_yaml = YAML.load(File.read(File.join(curr_octo_dir('defaults', yaml_file))))
|
|
|
|
this_yaml.each_key do |key|
|
|
|
|
if local_config.has_key?(key) and this_yaml[key] != local_config[key]
|
|
|
|
site_config[key] = local_config[key]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# write deploy configs
|
|
|
|
deploy_configs = {}
|
|
|
|
rakefile = File.read(curr_octo_dir('Rakefile'))
|
|
|
|
default_deploy = rakefile.match(/deploy_default\s*=\s*["']([\w-]*)["']/)[1]
|
|
|
|
defaults_deploy_file = curr_octo_dir('_config', 'defaults', 'deploy', (default_deploy == 'push' ? 'gh_pages.yml' : 'rsync.yml'))
|
|
|
|
deploy_configs = YAML.load(File.read(defaults_deploy_file))
|
|
|
|
|
|
|
|
rakefile.match(/deploy_branch\s*=\s*["']([\w-]*)["'])[1]/)
|
|
|
|
# TODO extract deploy configs from Rakefile
|
|
|
|
|
|
|
|
# write configs
|
|
|
|
File.open(curr_octo_dir('_config', 'site.yml'), 'w') do |f|
|
|
|
|
f.write(site_config.to_yaml)
|
|
|
|
end
|
|
|
|
File.open(curr_octo_dir('_config', 'deploy.yml'), 'w') do |f|
|
|
|
|
f.write(deploy_configs.to_yaml)
|
|
|
|
end
|
|
|
|
|
|
|
|
# migrate Rakefile
|
|
|
|
FileUtils.mv curr_octo_dir("Rakefile"), curr_octo_dir("Rakefile-old")
|
|
|
|
FileUtils.cp tmp_octo_dir("Rakefile"), curr_octo_dir("Rakefile")
|
|
|
|
|
|
|
|
# migrate Gemfile
|
|
|
|
FileUtils.rm curr_octo_dir("Gemfile")
|
|
|
|
FileUtils.cp tmp_octo_dir("Gemfile"), curr_octo_dir("Gemfile")
|
|
|
|
|
|
|
|
# migrate updated plugins (but leave deprecated ones)
|
|
|
|
FileUtils.cp_r tmp_octo_dir("plugins"), curr_octo_dir("plugins")
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
FileUtils.rm_rf tmp_octo_dir
|
|
|
|
|
|
|
|
puts "Your Octopress site has been successfully upgraded."
|
|
|
|
puts "Happy blogging!"
|
|
|
|
|
|
|
|
rescue => e
|
|
|
|
puts "An error occurred #{e}."
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|