├── .gitignore ├── ccleaner.rb ├── nmap.rb ├── launchy.rb ├── gimp.rb ├── sliksvn.rb ├── gnuplot.rb ├── wireshark.rb ├── emacsw32.rb ├── tweakui.rb ├── Rakefile ├── astyle.rb ├── rubyinstaller-base.rb ├── unzip.rb ├── zip.rb ├── putty.rb ├── ruby-1.8-mingw.rb ├── mydefrag.rb ├── sysinternals-suite.rb ├── emacs.rb ├── miranda.rb ├── doxygen.rb ├── totalcmd.rb ├── windirstat.rb ├── 7zip.rb ├── msysgit.rb ├── rubyinstaller-1.8.6-p398.rb ├── rubyinstaller-1.8.7-p249.rb ├── rubyinstaller-1.9.1-p378.rb ├── imagemagick.rb ├── rubyinstaller-1.8.6-p398-rc2.rb ├── rubyinstaller-1.9.2.rb └── mpm.rb /.gitignore: -------------------------------------------------------------------------------- 1 | mpm.exe 2 | -------------------------------------------------------------------------------- /ccleaner.rb: -------------------------------------------------------------------------------- 1 | url = "http://download.piriform.com/ccsetup235.exe" 2 | install do 3 | get url do |path| 4 | system path 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /nmap.rb: -------------------------------------------------------------------------------- 1 | url = "http://nmap.org/dist/nmap-5.21-win32.zip" 2 | install do 3 | get url do |path| 4 | unzip path, ProgramFiles 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /launchy.rb: -------------------------------------------------------------------------------- 1 | url = "http://www.launchy.net/downloads/win/Launchy2.5.exe" 2 | install do 3 | get url do |path| 4 | system path, "/SILENT" 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /gimp.rb: -------------------------------------------------------------------------------- 1 | url = "http://downloads.sourceforge.net/gimp-win/gimp-2.6.10-i686-setup-1.exe" 2 | install do 3 | get url do |path| 4 | system path 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /sliksvn.rb: -------------------------------------------------------------------------------- 1 | url = "http://www.sliksvn.com/pub/Slik-Subversion-1.6.12-win32.msi" 2 | install do 3 | get url do |path| 4 | system "msiexec", "/i", dospath(path) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /gnuplot.rb: -------------------------------------------------------------------------------- 1 | url = 'http://downloads.sourceforge.net/project/gnuplot/gnuplot/4.4.2/gp442win32.zip' 2 | install do 3 | get url do |path| 4 | unzip path, ProgramFiles 5 | end 6 | end 7 | 8 | -------------------------------------------------------------------------------- /wireshark.rb: -------------------------------------------------------------------------------- 1 | url = 'http://media-2.cacetech.com/wireshark/win32/wireshark-win32-1.4.0.exe' 2 | destination = ProgramFiles / "wireshark" 3 | install do 4 | get url do |path| 5 | system path, "/S", "/D=#{dospath destination}" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /emacsw32.rb: -------------------------------------------------------------------------------- 1 | url = "http://ourcomments.org/Emacs/DL/EmacsW32/EmacsCVS/ptch/Emacs-23-CvsP091103-EmacsW32-1.58.exe" 2 | destination = ProgramFiles / "EmacsW32" 3 | install do 4 | get url do |path| 5 | system path, "/SILENT", "/DIR=#{dospath destination}" 6 | end 7 | end 8 | 9 | -------------------------------------------------------------------------------- /tweakui.rb: -------------------------------------------------------------------------------- 1 | url = 'http://download.microsoft.com/download/f/c/a/fca6767b-9ed9-45a6-b352-839afb2a2679/TweakUiPowertoySetup.exe' 2 | homepage = 'http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx' 3 | install do 4 | get url do |path| 5 | system path 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | task :default => :mpm 2 | task :mpm => "mpm.zip" 3 | 4 | rbfiles = Dir.glob('*.rb') - ['mpm.rb'] 5 | 6 | file "mpm.zip" => [ "mpm.exe", rbfiles].flatten do 7 | system "zip", "mpm.zip", "mpm.exe", *rbfiles 8 | end 9 | file "mpm.exe" => "mpm.rb" do 10 | system "ocra", "mpm.rb" 11 | end 12 | -------------------------------------------------------------------------------- /astyle.rb: -------------------------------------------------------------------------------- 1 | url = "http://sourceforge.net/projects/astyle/files/astyle/astyle%202.01/AStyle_2.01_windows.zip/download" 2 | install do 3 | get url do |path| 4 | with_temppath do |tmppath| 5 | unzip path, tmppath 6 | cp 'astyle/bin/astyle.exe', ToolBinaryPath 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /rubyinstaller-base.rb: -------------------------------------------------------------------------------- 1 | def install 2 | get URL do |path| 3 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 4 | end 5 | end 6 | 7 | def uninstall 8 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 9 | if uninstaller 10 | system uninstaller, "/VERYSILENT" 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /unzip.rb: -------------------------------------------------------------------------------- 1 | url = "ftp://ftp.info-zip.org/pub/infozip/win32/unz552xn.exe" 2 | destination = ToolBinaryPath 3 | install do 4 | get url do |path| 5 | with_temppath do 6 | system path 7 | mkdir_p destination 8 | Dir["*.exe"].each do |exe| 9 | cp exe, destination 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /zip.rb: -------------------------------------------------------------------------------- 1 | url = "ftp://ftp.info-zip.org/pub/infozip/win32/zip232xn.zip" 2 | destination = ToolBinaryPath 3 | install do 4 | get url do |path| 5 | with_temppath do 6 | system "unzip", path 7 | mkdir_p destination 8 | Dir["*.exe"].each do |exe| 9 | cp exe, destination 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /putty.rb: -------------------------------------------------------------------------------- 1 | url = "http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip" 2 | install do 3 | begin 4 | get url, if_modified_since: registry.last_modified do |path, options| 5 | unzip path, ToolBinaryPath 6 | registry.last_modified = options.last_modified 7 | end 8 | rescue NotModified 9 | puts "Putty is current" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /ruby-1.8-mingw.rb: -------------------------------------------------------------------------------- 1 | @name = "ruby" 2 | @version = "1.8.6-p383-rc1" 3 | 4 | def install 5 | get URL do |path| 6 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 7 | end 8 | end 9 | 10 | def uninstall 11 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 12 | if uninstaller 13 | system uninstaller, "/VERYSILENT" 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /mydefrag.rb: -------------------------------------------------------------------------------- 1 | url = "http://www.mydefrag.com/Downloads/Download.php?File=MyDefrag-v4.3.1.exe" 2 | destination = ProgramFiles / "mydefrag" 3 | uninstaller = destination / "Uninstall.exe" 4 | install do 5 | get url do |path| 6 | system path, "/VERYSILENT", "/DIR=#{dospath destination}", "/TASKS=\"Associate\"" 7 | end 8 | end 9 | uninstall do 10 | system uninstaller, "/S" 11 | end 12 | -------------------------------------------------------------------------------- /sysinternals-suite.rb: -------------------------------------------------------------------------------- 1 | url = "http://download.sysinternals.com/files/SysinternalsSuite.zip" 2 | install do 3 | begin 4 | get(url, if_modified_since: registry.last_modified) do |path, options| 5 | unzip path, ToolBinaryPath 6 | registry.last_modified = options.last_modified 7 | end 8 | rescue NotModified 9 | puts "SysinternalsSuite is current" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /emacs.rb: -------------------------------------------------------------------------------- 1 | require 'natural_sort_kernel' 2 | downloadpage = "http://mirrors.dotsrc.org/gnu/emacs/windows/" 3 | install do 4 | scrape downloadpage do |html| 5 | file = html.xpath('//a/@href').map { |a| a.value }.select { |a| a =~ /^emacs-.*-i386.zip$/ }.natural_sort.last 6 | get URI.join(downloadpage, file) do |path| 7 | unzip path, ProgramFiles 8 | end 9 | end 10 | exit 11 | end 12 | -------------------------------------------------------------------------------- /miranda.rb: -------------------------------------------------------------------------------- 1 | # download_page = 'http://www.miranda-im.org/download/' 2 | update_page = 'http://update.miranda-im.org/update.xml' 3 | install do 4 | download_url = nil 5 | scrape_xml update_page do |doc| 6 | download_url = doc.xpath('/miranda/releases/releasestable/downloadunicodeexe').text 7 | end 8 | if download_url 9 | get download_url do |path| 10 | system path 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /doxygen.rb: -------------------------------------------------------------------------------- 1 | download_page = "http://www.stack.nl/~dimitri/doxygen/download.html" 2 | install do 3 | scrape download_page do |html| 4 | dl = html.xpath("//a/@href").map { |href| URI.join(download_page, href.value) } 5 | dl.select! { |uri| uri.scheme == "http" and File.basename(uri.request_uri) =~ /^doxygen-.*-setup\.exe$/ } 6 | get dl.first do |path| 7 | system path, "/SILENT" 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /totalcmd.rb: -------------------------------------------------------------------------------- 1 | download_page = 'http://www.ghisler.com/amazons3.php' 2 | install do 3 | require 'open-uri' 4 | download_url = nil 5 | scrape download_page do |doc| 6 | 7 | p doc.xpath('//a/@href') 8 | download_url = doc.xpath('//a/@href').find { |a| a =~ /tcmd.*\.exe/ } 9 | end 10 | if download_url 11 | get download_url do |path| 12 | exit 13 | system path 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /windirstat.rb: -------------------------------------------------------------------------------- 1 | url = "http://sourceforge.net/projects/windirstat/files/windirstat/1.1.2%20installer%20re-release%20%28more%20languages%21%29/windirstat1_1_2_setup.exe" 2 | destination = ProgramFiles / "WinDirStat" 3 | uninstaller = destination / "Uninstall.exe" 4 | 5 | install do 6 | get url do |path| 7 | system path, "/S", "/D=#{dospath destination}" 8 | end 9 | end 10 | uninstall do 11 | system uninstaller, "/S" 12 | end 13 | -------------------------------------------------------------------------------- /7zip.rb: -------------------------------------------------------------------------------- 1 | URL = "http://downloads.sourceforge.net/sevenzip/7z915.exe" 2 | DOWNLOAD_PAGE = "http://www.7-zip.org/" 3 | install do 4 | scrape DOWNLOAD_PAGE do |html| 5 | hrefs = html.xpath("//a[@href]") 6 | uris = hrefs.map { |a| URI.join(DOWNLOAD_PAGE, a[:href]) } 7 | exes = uris.select { |uri| File.basename(uri.request_uri) =~ /^7z(\d+)\.exe$/ } 8 | get exes.first do |path| 9 | system path 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /msysgit.rb: -------------------------------------------------------------------------------- 1 | url = "http://msysgit.googlecode.com/files/Git-1.7.2.3-preview20100911.exe" 2 | sha1 = "16862fcab1c5a0f66d4232c4b6371b5c4f0936af" 3 | destination = ProgramFiles / "Git-1.7.2.3-preview20100911" 4 | 5 | install do 6 | get url, :sha1 => sha1 do |path| 7 | system dospath(path), "/DIR=#{dospath destination}", "/VERYSILENT" 8 | end 9 | end 10 | 11 | uninstall do 12 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 13 | system uninstaller, "/VERYSILENT" 14 | end 15 | -------------------------------------------------------------------------------- /rubyinstaller-1.8.6-p398.rb: -------------------------------------------------------------------------------- 1 | @name = "ruby" 2 | @version = "1.8.6-p398" 3 | URL = "http://rubyforge.org/frs/download.php/71066/rubyinstaller-1.8.6-p398.exe" 4 | Destination = File.join Base::ProgramFiles, "rubyinstaller-1.8.6-p398" 5 | def install 6 | get URL do |path| 7 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 8 | end 9 | end 10 | 11 | def uninstall 12 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 13 | if uninstaller 14 | system uninstaller, "/VERYSILENT" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /rubyinstaller-1.8.7-p249.rb: -------------------------------------------------------------------------------- 1 | @name = "ruby" 2 | @version = "1.8.7-p249" 3 | URL = "http://rubyforge.org/frs/download.php/71067/rubyinstaller-1.8.7-p249.exe" 4 | Destination = File.join Base::ProgramFiles, "rubyinstaller-1.8.7-p249" 5 | def install 6 | get URL do |path| 7 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 8 | end 9 | end 10 | 11 | def uninstall 12 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 13 | if uninstaller 14 | system uninstaller, "/VERYSILENT" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /rubyinstaller-1.9.1-p378.rb: -------------------------------------------------------------------------------- 1 | @name = "ruby" 2 | @version = "1.9.1-p378" 3 | URL = "http://rubyforge.org/frs/download.php/71078/rubyinstaller-1.9.1-p378.exe" 4 | Destination = File.join Base::ProgramFiles, "rubyinstaller-1.9.1-p378" 5 | def install 6 | get URL do |path| 7 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 8 | end 9 | end 10 | 11 | def uninstall 12 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 13 | if uninstaller 14 | system uninstaller, "/VERYSILENT" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /imagemagick.rb: -------------------------------------------------------------------------------- 1 | baseurl = "http://www.imagemagick.org/script/binary-releases.php" 2 | download_url = nil 3 | match = /^ImageMagick-.*-Q8-windows-dll.exe$/ 4 | 5 | scrape baseurl do |html| 6 | html.xpath("//a").each do |link| 7 | if href = link['href'] 8 | url = URI.join(baseurl, href) 9 | if url.scheme == "http" and File.basename(url.path) =~ match 10 | download_url = url 11 | end 12 | end 13 | end 14 | end 15 | 16 | install do 17 | get download_url do |path| 18 | system path 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /rubyinstaller-1.8.6-p398-rc2.rb: -------------------------------------------------------------------------------- 1 | @name = "ruby" 2 | @version = "1.8.6-p383-rc1" 3 | URL = "http://rubyforge.org/frs/download.php/69033/rubyinstaller-1.8.6-p398-rc2.exe" 4 | Destination = File.join(Base::ProgramFiles, "rubyinstaller-1.8.6-p398-rc2") 5 | def install 6 | get URL do |path| 7 | system path.tr('/','\\'), "/DIR=#{dospath Destination}", "/VERYSILENT" 8 | end 9 | end 10 | 11 | def uninstall 12 | uninstaller = Dir["#{Destination}/unins*.exe"][0] 13 | if uninstaller 14 | system uninstaller, "/VERYSILENT" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /rubyinstaller-1.9.2.rb: -------------------------------------------------------------------------------- 1 | require 'open-uri' 2 | 3 | url = "http://rubyforge.org/frs/download.php/74298/rubyinstaller-1.9.2-p180.exe" 4 | name = File.basename(url).gsub(/\.exe$/, '') 5 | version = name[/rubyinstaller-(.*)/, 1] 6 | destination = Base::ProgramFiles / name 7 | download_page = 'http://rubyinstaller.org/downloads/' 8 | 9 | install do 10 | get url do |path| 11 | # system "\"#{dospath path}\" /TASKS=\"MODPATH,ASSOCFILES\" /DIR=\"#{dospath destination}\"" 12 | system dospath(path), "/TASKS=\"MODPATH,ASSOCFILES\"", "/DIR=\"#{dospath destination}\"" 13 | end 14 | end 15 | 16 | uninstall do 17 | uninstaller = Dir["#{destination}/unins*.exe"][0] 18 | if uninstaller 19 | system uninstaller, "/VERYSILENT" 20 | end 21 | end 22 | 23 | def scrape 24 | doc = Nokogiri::HTML(open(download_page)) 25 | p doc.xpath('//a').map { |a| 26 | if href = a['href'] 27 | basename = File.basename(URI.parse(href).path) 28 | basename =~ /^rubyinstaller-(\d+)\.(\d+)\.(\d+)-p(\d+)\.exe$/ && href 29 | end 30 | }.select {|x| x} 31 | end 32 | -------------------------------------------------------------------------------- /mpm.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'net/ftp' 3 | require 'fileutils' 4 | require 'cgi' 5 | require 'time' 6 | require 'ostruct' 7 | 8 | begin 9 | require 'nokogiri' 10 | rescue LoadError 11 | end 12 | 13 | class String 14 | def /(n) 15 | File.join(self, n) 16 | end 17 | end 18 | 19 | class ProgressBar 20 | UPDATE_INTERVAL = 0.25 21 | WIDTH = 68 22 | 23 | def initialize(max) 24 | @max = max 25 | @prg = 0 26 | @last_fully = -1 27 | @last_partially = -1 28 | @last_time = Time.now 29 | paint 30 | yield(self) 31 | puts 32 | end 33 | 34 | def inc(count) 35 | @prg += count 36 | paint 37 | end 38 | 39 | def paint 40 | width = WIDTH - 2 41 | pct = (@prg * 100.0 / @max).round 42 | progress = [@prg, @max].min 43 | finished = progress / @max.to_f * width 44 | fully = finished.floor 45 | partially = (finished - fully > 0.001 ? 1 : 0) 46 | now = Time.now 47 | if fully != @last_fully or partially != @last_partially or now - @last_time > UPDATE_INTERVAL 48 | rest = width - partially - fully 49 | printf "\r%3d%% [" + "=" * fully + ">" * partially + "-" * rest + "]", pct 50 | @last_fully = fully 51 | @last_partially = partially 52 | @last_time = now 53 | end 54 | end 55 | end 56 | def ProgressBar(max, &block) 57 | ProgressBar.new(max, &block) 58 | end 59 | 60 | module Tasks 61 | def actions 62 | @actions ||= {} 63 | end 64 | def install(&block) 65 | self.actions[:install] = block 66 | end 67 | def uninstall(&block) 68 | self.actions[:uninstall] = block 69 | end 70 | end 71 | 72 | class Base 73 | include FileUtils 74 | include Tasks 75 | include Nokogiri if defined?(Nokogiri) 76 | 77 | attr_reader :registry 78 | 79 | ProgramFiles = "C:/appl" 80 | Temp = ENV['TEMP'] 81 | ToolBinaryPath = File.join(ProgramFiles, "tools", "bin") 82 | 83 | def initialize 84 | @cache_enabled = false 85 | @registry = OpenStruct.new 86 | end 87 | 88 | def load_registry(basename) 89 | registry_path = File.expand_path("~/.instregistry/" + basename) 90 | if File.file?(registry_path) 91 | content = File.open(registry_path, "rb") { |io| io.read } 92 | @registry = Marshal.load(content) 93 | end 94 | end 95 | 96 | def save_registry(basename) 97 | registry_path = File.expand_path("~/.instregistry/" + basename) 98 | mkdir_p File.dirname(registry_path) 99 | File.open(registry_path, "wb") { |io| io.write(Marshal.dump(@registry)) } 100 | end 101 | 102 | def dospath(path) 103 | path.tr('/','\\') 104 | end 105 | 106 | def randstr 107 | [rand(2**64)].pack("Q").unpack("h*") 108 | end 109 | 110 | def with_temppath 111 | path = File.join(Temp, randstr) 112 | 113 | dir = Dir.pwd 114 | begin 115 | mkdir(path) 116 | chdir(path) 117 | yield(path) 118 | ensure 119 | chdir(dir) 120 | rm_rf(path) 121 | end 122 | end 123 | 124 | class Redirection < Exception 125 | def initialize(url) 126 | @url = url 127 | end 128 | def url 129 | @url 130 | end 131 | end 132 | 133 | class NotModified < Exception 134 | end 135 | 136 | def httpget(uri, opt = {}) 137 | request_headers = {} 138 | if if_modified_since = opt[:if_modified_since] 139 | request_headers["If-Modified-Since"] = if_modified_since.httpdate 140 | end 141 | begin 142 | puts uri 143 | Net::HTTP.start(uri.host, uri.port) do |http| 144 | http.request_get(uri.request_uri, request_headers) do |response| 145 | case response 146 | when Net::HTTPNotModified 147 | raise NotModified 148 | when Net::HTTPRedirection 149 | raise Redirection, response['Location'] 150 | else 151 | yield(response) 152 | end 153 | end 154 | end 155 | rescue Redirection => redir 156 | uri = URI.parse(redir.url) 157 | retry 158 | end 159 | end 160 | 161 | def ftpget(uri, &block) 162 | Net::FTP.open(uri.host) do |ftp| 163 | print "\rlogging in..." 164 | ftp.login 165 | print "\rchdir... " 166 | ftp.chdir(File.dirname(uri.path)) 167 | print "\rsize... " 168 | content_length = ftp.size(File.basename(uri.path)) 169 | print "\rget... " 170 | ProgressBar content_length do |pb| 171 | ftp.retrbinary("RETR " + File.basename(uri.path), 8192) do |fragment| 172 | pb.inc fragment.size 173 | yield fragment 174 | end 175 | end 176 | end 177 | end 178 | 179 | def get(url, options = {}) 180 | response_options = OpenStruct.new 181 | temppath = nil 182 | uri = url.is_a?(URI) ? url : URI.parse(url) 183 | case uri.scheme 184 | when 'ftp' 185 | filename = File.basename(uri.path) 186 | temppath = File.join(Temp, filename) 187 | bytes_downloaded = 0 188 | if not File.exist?(temppath) or not @cache_enabled 189 | File.open temppath, "wb" do |f| 190 | ftpget uri do |fragment| 191 | f.write fragment 192 | end 193 | end 194 | end 195 | 196 | when 'http' 197 | httpget(uri, if_modified_since: options[:if_modified_since]) do |response| 198 | filename = nil 199 | if last_modified = response['Last-Modified'] 200 | response_options.last_modified = Time.parse(last_modified) 201 | end 202 | if contentdisp = response["Content-Disposition"] 203 | token = /([^()<>@,;:\\\"\/\[\]?={} ]*)/ 204 | qstring = /"([^\"]|\\")*"/ 205 | if contentdisp =~ /filename=\"?(#{token}|#{qstring})\"?/ 206 | filename = $2 || CGI::unescape($3) 207 | end 208 | end 209 | filename ||= File.basename(uri.path) 210 | temppath = File.join(Temp, filename) 211 | 212 | ProgressBar response.content_length do |pb| 213 | if not File.exist?(temppath) or not @cache_enabled 214 | File.open(temppath, "wb") do |f| 215 | bytes_downloaded = 0 216 | response.read_body do |fragment| 217 | f.write(fragment) 218 | pb.inc(fragment.size) 219 | bytes_downloaded += fragment.size 220 | end 221 | end 222 | end 223 | end 224 | end 225 | end 226 | 227 | if temppath 228 | if sha1 = options[:sha1] 229 | require 'digest/sha1' 230 | raise "Checksum failure" unless Digest::SHA1.file(temppath) == sha1.downcase 231 | end 232 | yield(temppath, response_options) 233 | end 234 | end 235 | 236 | def unzip(zipfile, targetpath) 237 | mkdir_p targetpath 238 | targetpath = dospath(targetpath) 239 | zipfile = dospath(zipfile) 240 | puts "Unzipping #{File.basename(zipfile)} to #{targetpath}" 241 | system 'unzip', '-q', '-o', zipfile, '-d', targetpath 242 | end 243 | 244 | def system(*args) 245 | puts args.join(" ") 246 | Kernel.system(*args) 247 | end 248 | 249 | def scrape(url) 250 | require 'open-uri' 251 | require 'nokogiri' 252 | content = nil 253 | open(url) do |io| 254 | content = io.read 255 | end 256 | yield(Nokogiri::HTML.parse(content)) 257 | end 258 | 259 | def scrape_xml(url) 260 | require 'open-uri' 261 | require 'nokogiri' 262 | content = nil 263 | open(url) do |io| 264 | content = io.read 265 | end 266 | yield(Nokogiri::XML.parse(content)) 267 | end 268 | end 269 | 270 | def registry 271 | @registry 272 | end 273 | 274 | if ARGV.empty? 275 | puts < 277 | 278 | mpm install 279 | mpm uninstall 280 | END_OF_USAGE 281 | exit 282 | end 283 | 284 | obj = Base.new 285 | obj.load_registry(ARGV[1]) 286 | obj.instance_eval(IO.read(ARGV[1]), ARGV[1]) 287 | obj.actions[ARGV[0].to_sym].call 288 | obj.save_registry(ARGV[1]) 289 | --------------------------------------------------------------------------------