Skip to content

Instantly share code, notes, and snippets.

@mks-m
Created December 22, 2009 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mks-m/261685 to your computer and use it in GitHub Desktop.
Save mks-m/261685 to your computer and use it in GitHub Desktop.
#!/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