Skip to content

Instantly share code, notes, and snippets.

@keymone keymone/upgrade.rb
Created Dec 22, 2009

Embed
What would you like to do?
#!/bin/env ruby
require 'fileutils'
DRUPAL_MAJOR = 6
puts "Scanning for available drupal versions"
available = Dir['*'].map do |file|
if file =~ /^drupal-#{DRUPAL_MAJOR}\.(\d+)$/
$1.to_i
end
end.compact
if available.empty?
puts "Not a drupals directory"
exit 1
end
puts "Found: 6.#{available.map{|c| c.to_s}.join(", 6.")}"
candidate = available.max
puts "Upgrade candidate: #{DRUPAL_MAJOR}.#{candidate}"
puts "Detecting current version"
if File.symlink?('drupal-stable/index.php') &&
File.readlink('drupal-stable/index.php') =~ /drupal-#{DRUPAL_MAJOR}.(\d+)/
current = $1.to_i
else
puts "Cannot identify current installation"
exit 2
end
puts "Current version is #{DRUPAL_MAJOR}.#{current}"
if candidate <= current
puts "No upgrade needed"
exit 3
end
relink = %w{cron.php includes index.php install.php misc modules profiles scripts themes update.php xmlrpc.php}
cur_dir = "./drupal-stable"
new_dir = "../drupal-#{DRUPAL_MAJOR}.#{candidate}"
puts "Relinking"
relink.each do |item|
cur_file, new_file = "#{cur_dir}/#{item}", "#{new_dir}/#{item}"
puts " #{cur_file} -> #{new_file}"
File.unlink cur_file
File.symlink new_file, cur_file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.