Created
September 10, 2014 06:04
-
-
Save cthornton/63223a4a80296d0bf110 to your computer and use it in GitHub Desktop.
Automatically Update Ghost Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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