Skip to content

Instantly share code, notes, and snippets.

@burke
Created February 24, 2010 13:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burke/313430 to your computer and use it in GitHub Desktop.
Save burke/313430 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- ruby -*-
# TODO: Intelligently find (maybe even install?) latest REE & passenger.
CONFIG_FLAGS="--with-http_secure_link_module"
REE_VERSION="ruby-enterprise-1.8.7-2010.01"
require 'open-uri'
current = open("http://www.nginx.eu/download/sources/").
read.
scan(/\<A[^\>]+\>([^\<]+)\</).
map(&:to_s).
select{|e| e =~ /nginx-.*\.tar\.gz/}.
map { |e| e.
sub(/nginx-(.*)\.tar\.gz/, '\1').
split('.').
map(&:to_i) }.
sort.
last
vstring = current.join('.')
dname = "nginx-#{vstring}"
fname = "#{dname}.tar.gz"
targetdir = "#{dname}-#{Time.now.to_i}"
srcdir = File.expand_path("~/src")
url = "http://www.nginx.eu/download/sources/#{fname}"
if File.exists?("#{srcdir}/#{fname}")
puts "Already up to date. Continue anyway?"
exit unless gets.chomp =~ /y/
end
Dir.chdir(File.expand_path('~/src'))
system <<SYSTEM
rm -r #{fname} #{dname} 2>/dev/null
wget #{url}
tar xf #{fname}
rm #{fname}
sudo /opt/#{REE_VERSION}/bin/passenger-install-nginx-module --auto \
--nginx-source-dir=#{srcdir}/#{dname} --prefix=/opt/nginx/versions/#{targetdir} \
--extra-configure-flags='#{CONFIG_FLAGS}'
SYSTEM
puts "Everything is installed... should I go ahead and set the symlink to the new nginx?"
exit unless gets.chomp =~ /y/
system "sudo ln -sf /opt/nginx/versions/#{targetdir} /opt/nginx/current"
puts "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment