LoginSignup
0

More than 5 years have passed since last update.

thunderbirdとFirefoxをrubyでダウンロードする。

Last updated at Posted at 2016-07-08

最新版のthunderbirdとFirefoxをブラウザを使わずにダウンロードする。

初めまして。Yoshi1729と申します。
仕事でパソコンのセットアップをする際に、thunderbirdとfirefoxをブラウザで
ダウンロードするのが面倒と思い、rubyでダウンロードできないかやってみました。使用する環境はWindows7を想定しています。

環境

$ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

書いたコード

webDownload.rb

#! /usr/bin/env ruby
# coding:utf-8

require 'open-uri'
require 'net/http'
require 'uri'

product = ['thunderbird-latest', 'firefox-latest']
saveFilename = ['Thunderbird.exe', 'FireFox.exe']


product.each {|query|
  url = 'https://download.mozilla.org/?product=' + query + '&os=win&lang=ja'
  res = Net::HTTP.get_response(URI.parse(url))
  saveFilename.each {|name|
    open("#{name}", "wb") {|save_file|
      open("#{res['location']}", "rb") {|read_file|
        save_file.write(read_file)
      }
    }
  }
}

print "2 files was downloaded!\n"

余談ですが、wgetコマンドを使ってもダウンロードできます。
詳細は参考URLを参照してください。

wget -O FirefoxSetup.exe "https://download.mozilla.org/?product=firefox-latest&os=win&lang=ja"

wget -O Thunderbird.exe "https://download.mozilla.org/?product=thunderbird-latest&os=win&lang=ja"

参考URL
https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt
https://ftp.mozilla.org/pub/thunderbird/releases/latest/README.txt

以上です。
ここまで読んでくださりありがとうございましたm(..)m

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0