Check for e updates


/ Published in: Ruby
Save to your folder(s)

Requires wget and curl.


Copy this code and paste it in your HTML
  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

You need to login to post a comment.