Posted By

gtcaz on 03/09/07


Tagged

check ruby download update e


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
webstic


Check for e updates


 / Published in: Ruby
 

Requires wget and curl.

  1. #!/usr/bin/env ruby
  2. BEGIN {$VERBOSE = true}
  3. require 'date'
  4. require 'fileutils'
  5. require 'time'
  6.  
  7. LOCAL_FILE = 'e_setup.exe'
  8. REMOTE_FILE = 'http://opencompany.org/download/e_setup.exe'
  9. WGET_CMD = '/usr/bin/wget --spider -S'
  10.  
  11. def download_run()
  12. `curl -R -O #{REMOTE_FILE}`
  13. puts "Setting file permissions..."
  14. `chmod +x #{LOCAL_FILE}`
  15. puts "Running setup."
  16. `cygstart #{LOCAL_FILE}`
  17. end
  18.  
  19. unless File.exists?(LOCAL_FILE)
  20. download_run()
  21. exit()
  22. end
  23.  
  24. puts "Checking modification times..."
  25. begin
  26. mod_time = Time.parse(%x{#{WGET_CMD} #{REMOTE_FILE} 2>&1}.split("\n").grep(/Last-Modified:/)[0].split(": ")[1].chomp)
  27. if mod_time > File.mtime(LOCAL_FILE)
  28. puts "Remote file is newer. Downloading..."
  29. download_run()
  30. else
  31. puts "Remote file no newer than local file. Nothing to do."
  32. end
  33. rescue
  34. puts "Error during download process: ",$!
  35. exit(false)
  36. end

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mazzika on March 25, 2011

thx u

You need to login to post a comment.