/ Published in: Ruby
                    
                                        
Requires wget and curl.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#!/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("\n").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
Comments
 Subscribe to comments
                    Subscribe to comments
                
                