Check for e updates

#!/usr/bin/env ruby
BEGIN {$VERBOSE = true}
require 'date'
require 'fileutils'
require 'time'

LOCAL_FILE = 'e_setup.exe'
REMOTE_FILE = 'http://opencompany.org/download/e_setup.exe'
WGET_CMD = '/usr/bin/wget --spider -S'

def download_run()
`curl -R -O #{REMOTE_FILE}`
puts "Setting file permissions..."
`chmod +x #{LOCAL_FILE}`
puts "Running setup."
`cygstart #{LOCAL_FILE}`
end

unless File.exists?(LOCAL_FILE)
download_run()
exit()
end

puts "Checking modification times..."
begin
mod_time = Time.parse(%x{#{WGET_CMD} #{REMOTE_FILE} 2>&1}.split("
").grep(/Last-Modified:/)[0].split(": ")[1].chomp)
if mod_time > File.mtime(LOCAL_FILE)
puts "Remote file is newer.  Downloading..."
download_run()
else
puts "Remote file no newer than local file.  Nothing to do."
end
rescue
puts "Error during download process: ",$!
exit(false)
end

source

Leave a Reply