Update or export wordpress using Thor from the command line : http://proccli.com/update-wordpress-ruby-thor
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'thor' | |
require 'open-uri' | |
class Wordpress < Thor | |
include Thor::Actions | |
WORDPRESS_URL = %{http://wordpress.org} | |
FILENAME = %{latest.tar.gz} | |
TMP_PATH = %{/tmp} | |
desc 'update', 'Update wordpress to the latest version' | |
def update | |
download_url = URI.join(WORDPRESS_URL, FILENAME) | |
tmp_path = File.join(TMP_PATH, FILENAME) | |
install_path = File.expand_path(File.dirname(__FILE__)) | |
say %{Downloading latest version of wordpress from #{download_url}}, :yellow | |
run %{`which curl` #{download_url} -o #{tmp_path}} | |
say %{Installing to #{install_path}}, :yellow | |
if yes?(%{Continue? [yes/no]: }, :green) | |
say %{Updating...}, :yellow | |
run %{tar -C #{install_path} -xzf #{tmp_path} --strip 1} | |
else | |
say %{Update Aborted}, :red | |
end | |
end | |
# See: http://drincruz.blogspot.com/2009/11/wordpress-cli-export.html | |
desc 'export', 'Export wordpress to STDOUT (same as using the website)' | |
def export | |
code = %{ | |
require_once('wp-config.php'); | |
require_once('wp-admin/includes/export.php'); | |
export_wp(); | |
}.gsub(/\n|\s*/,'') | |
run %{`which php` -r "#{code}"}, :verbose => false | |
end | |
end | |
Wordpress.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment