Skip to content

Instantly share code, notes, and snippets.

@cthornton
Created September 10, 2014 06:04
Show Gist options
  • Save cthornton/63223a4a80296d0bf110 to your computer and use it in GitHub Desktop.
Save cthornton/63223a4a80296d0bf110 to your computer and use it in GitHub Desktop.
Automatically Update Ghost Blog
#!/usr/bin/env ruby
#
# Automatically updates ghost per instructions at:
#
# http://support.ghost.org/how-to-upgrade/
#
# Make sure to back up your files before proceeding (i.e. git repo)!
#
require 'tempfile'
require 'rest_client'
require 'fileutils'
require 'zip'
print 'Ghost Version: '
version = gets.strip
download_file = "https://ghost.org/zip/ghost-#{version}.zip"
file = Tempfile.new 'ghost'
begin
res = RestClient.get(download_file){|response, request, result| response }
if res.code != 200
puts "Invalid ghost version (server returned #{res.code})"
exit(-1)
end
file.write res.body
file.close
folders = ['core', 'content/themes/casper']
folders.each do |folder|
FileUtils.rm_rf(folder)
end
files = ['package.json', 'index.js']
files.each do |file|
FileUtils.rm(file)
end
Zip::File.open(file.path) do |zip_file|
folders.map{|f| "#{f}/**/*" }.each do |glob|
zip_file.glob(glob).each do |entry|
FileUtils.mkdir_p File.dirname(entry.name)
puts "Extracting #{entry.name}..."
entry.extract(entry.name)
end
end
files.each do |file|
entry = zip_file.glob(file).first
FileUtils.mkdir_p File.dirname(entry.name)
puts "Extracting #{entry}"
entry.extract(entry.name)
end
end
File.open('version', 'w') do |f|
f.puts version
end
ensure
file.unlink
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment