avira_update_mirrors 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in avira_update_mirrors.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 vkill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # AviraUpdateMirrors
2
+
3
+ Avira update mirrors
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'avira_update_mirrors'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install avira_update_mirrors
18
+
19
+ ## Usage
20
+
21
+ see `examples`
22
+
23
+ ### about configure
24
+
25
+ see your update log, like this
26
+
27
+ 16:43:57 [UPD] [INFO] Checking whether newer files are available.
28
+ 16:43:57 [UPD] [INFO] Select update server 'http://119.97.137.178/update'.
29
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/master.idx' to 'xx'.
30
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/wks_avira12-win32-en-pecl.idx' to 'xx'.
31
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/wks_avira12-win32-en-pecl.info.gz' to 'xx'.
32
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/webcat-common-int.info.gz' to 'xx'.
33
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/vdf.info.gz' to 'xx'.
34
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/rdf-common-int.info.gz' to 'xx'.
35
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/ave2-win32-int.info.gz' to 'xx'.
36
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/wks_avira12-win32-en-pecl-info.info.gz' to 'xx'.
37
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/peclkey-common-int.info.gz' to 'xx'.
38
+ 16:43:57 [UPD] [INFO] Downloading of 'http://119.97.137.178/update/idx/scanner-win32-int.info.gz' to 'xx'.
39
+
40
+ "http://119.97.137.178/update" is your update_servers
41
+
42
+ "idx/master.idx" is your idx_master
43
+
44
+ "idx/wks_avira12-win32-en-pecl.idx" and more is your idxes
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/avira_update_mirrors/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["vkill"]
6
+ gem.email = ["vkill.net@gmail.com"]
7
+ gem.description = "Avira update mirrors"
8
+ gem.summary = "Avira update mirrors"
9
+ gem.homepage = "https://github.com/vkill/avira_update_mirrors"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "avira_update_mirrors"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = AviraUpdateMirrors::VERSION
17
+
18
+ gem.add_dependency('httparty', '~> 0.8.1')
19
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'avira_update_mirrors'
4
+
5
+ AviraUpdateMirrors.configure do |config|
6
+ config.wwwroot_dir = "wwwroot"
7
+ config.products = [
8
+ "v12f_zhcn" => {
9
+ "update_servers" => %w`
10
+ http://80.190.143.227/update
11
+ `,
12
+ "idx_master" => %q`/idx/master.idx`,
13
+ "idxes" => %w`
14
+ /idx/wks_avira12-win32-zhcn-pecl.idx
15
+ /idx/wks_avira12-win32-zhcn-pecl.info.gz
16
+ /idx/webcat-common-int.info.gz
17
+ /idx/vdf.info.gz
18
+ /idx/rdf-common-int.info.gz
19
+ /idx/ave2-win32-int.info.gz
20
+ /idx/wks_avira12-win32-zhcn-pecl-info.info.gz
21
+ /idx/peclkey-common-int.info.gz
22
+ /idx/scanner-win32-int.info.gz
23
+ `
24
+ }
25
+ ]
26
+ end
27
+
28
+ AviraUpdateMirrors.mirror
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'avira_update_mirrors'
4
+
5
+ AviraUpdateMirrors.configure do |config|
6
+ config.wwwroot_dir = "wwwroot"
7
+ config.products = [
8
+ "v12f_zhcn" => {
9
+ "update_servers" => %w`
10
+ http://80.190.143.227/update
11
+ `,
12
+ "idx_master" => %q`/idx/master.idx`,
13
+ "idxes" => %w`
14
+ /idx/wks_avira12-win32-zhcn-pecl.idx
15
+ /idx/wks_avira12-win32-zhcn-pecl.info.gz
16
+ /idx/webcat-common-int.info.gz
17
+ /idx/vdf.info.gz
18
+ /idx/rdf-common-int.info.gz
19
+ /idx/ave2-win32-int.info.gz
20
+ /idx/wks_avira12-win32-zhcn-pecl-info.info.gz
21
+ /idx/peclkey-common-int.info.gz
22
+ /idx/scanner-win32-int.info.gz
23
+ `
24
+ },
25
+ "v12p_en" => {
26
+ "update_servers" => %w`
27
+ http://80.190.130.226/update
28
+ `,
29
+ "idx_master" => %q`/idx/master.idx`,
30
+ "idxes" => %w`
31
+ /idx/wks_avira12-win32-en-pepr.idx
32
+ /idx/wks_avira12-win32-en-pepr.info.gz
33
+ /idx/webcat-common-int.info.gz
34
+ /idx/vdf.info.gz
35
+ /idx/rdf-common-int.info.gz
36
+ /idx/ave2-win32-int.info.gz
37
+ /idx/wks_avira12-win32-en-pepr-info.info.gz
38
+ /idx/scanner-win32-int.info.gz
39
+ `
40
+ }
41
+ ]
42
+ end
43
+
44
+ AviraUpdateMirrors.mirror
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'avira_update_mirrors'
4
+
5
+ AviraUpdateMirrors.configure do |config|
6
+ config.wwwroot_dir = "wwwroot"
7
+ config.products = [
8
+ "v12p_en" => {
9
+ "update_servers" => %w`
10
+ http://80.190.130.226/update
11
+ `,
12
+ "idx_master" => %q`/idx/master.idx`,
13
+ "idxes" => %w`
14
+ /idx/wks_avira12-win32-en-pepr.idx
15
+ /idx/wks_avira12-win32-en-pepr.info.gz
16
+ /idx/webcat-common-int.info.gz
17
+ /idx/vdf.info.gz
18
+ /idx/rdf-common-int.info.gz
19
+ /idx/ave2-win32-int.info.gz
20
+ /idx/wks_avira12-win32-en-pepr-info.info.gz
21
+ /idx/scanner-win32-int.info.gz
22
+ `
23
+ }
24
+ ]
25
+ end
26
+
27
+ AviraUpdateMirrors.mirror
@@ -0,0 +1,79 @@
1
+ require "httparty"
2
+ require 'fileutils'
3
+ require "zlib"
4
+ require 'rexml/document'
5
+ include REXML
6
+ require "digest/md5"
7
+
8
+ require "avira_update_mirrors/version"
9
+ require "avira_update_mirrors/configuration"
10
+ require "avira_update_mirrors/download"
11
+ require "avira_update_mirrors/parse_info"
12
+
13
+ module AviraUpdateMirrors
14
+
15
+ def self.configure
16
+ yield Configuration
17
+ end
18
+
19
+ def self.mirror
20
+ @@base_dir = Dir.pwd
21
+ @@wwwroot_dir = File.join(@@base_dir, Configuration.wwwroot_dir)
22
+ @@download = {}
23
+
24
+ FileUtils.mkdir_p @@wwwroot_dir
25
+
26
+ Configuration.products.each_with_index do |product, n|
27
+ product.each do |product_name, product_config|
28
+ puts "mirroring #{product_name}"
29
+
30
+ puts " choice update_server"
31
+ product_config["update_servers"].each do |update_server|
32
+
33
+ puts " try #{update_server}"
34
+ download = Download.new(update_server, :base_dir => @@base_dir)
35
+ download.perform(product_config["idx_master"])
36
+
37
+ if download.downloaded?
38
+ @@download[product_name] = download
39
+ puts " use this update_server #{update_server}"
40
+ break
41
+ else
42
+ next
43
+ end
44
+ end
45
+
46
+ raise "all update_servers invalidation" unless @@download[product_name]
47
+
48
+ # download all idxes and parse
49
+ product_config["idxes"].each do |idx|
50
+ puts " downloading #{idx}"
51
+ @@download[product_name].perform(idx)
52
+ end
53
+
54
+
55
+ parse_info = ParseInfo.new(:wwwroot_dir => @@wwwroot_dir, :downloads_dir => @@download[product_name].downloads_dir)
56
+ parse_info.generate_files_list do |msg|
57
+ puts msg
58
+ end
59
+ parse_info.check_files_md5 do |msg|
60
+ puts msg
61
+ end
62
+
63
+ puts " #{parse_info.need_download_files.size} files need download"
64
+ parse_info.need_download_files.each do |file_name, file_zip_md5|
65
+ puts " downloading #{file_name}"
66
+ @@download[product_name].perform(file_name)
67
+ unless Digest::MD5.file(@@download[product_name].download_file_path) == file_zip_md5.downcase
68
+ raise "downloaded file md5 error!"
69
+ end
70
+ end
71
+
72
+ puts " copy downloaded files to wwwroot_dir and destroy downloaded files"
73
+ FileUtils.cp_r File.join(@@download[product_name].downloads_dir, "."), @@wwwroot_dir
74
+ FileUtils.rm_rf @@download[product_name].downloads_dir
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,28 @@
1
+ module AviraUpdateMirrors
2
+ Configuration = Struct.new(
3
+ :wwwroot_dir,
4
+ :products
5
+ ).new(
6
+ 'wwwroot',
7
+ [
8
+ "v12f_zhcn" => {
9
+ "update_servers" => %w`
10
+ http://80.190.143.227/update
11
+ `,
12
+ "idx_master" => %q`/idx/master.idx`,
13
+ "idxes" => %w`
14
+ /idx/wks_avira12-win32-zhcn-pecl.idx
15
+ /idx/wks_avira12-win32-zhcn-pecl.info.gz
16
+ /idx/webcat-common-int.info.gz
17
+ /idx/vdf.info.gz
18
+ /idx/rdf-common-int.info.gz
19
+ /idx/ave2-win32-int.info.gz
20
+ /idx/wks_avira12-win32-zhcn-pecl-info.info.gz
21
+ /idx/peclkey-common-int.info.gz
22
+ /idx/scanner-win32-int.info.gz
23
+ `
24
+ }
25
+ ]
26
+ )
27
+
28
+ end
@@ -0,0 +1,48 @@
1
+ module AviraUpdateMirrors
2
+ class Download
3
+
4
+ include HTTParty
5
+ default_timeout 10
6
+
7
+ attr_reader :error, :response, :downloads_dir, :download_file_path
8
+
9
+ def initialize(base_url, options = {})
10
+ @base_url = base_url
11
+ @base_dir = options[:base_dir] || Dir.pwd
12
+ @downloads_dir = File.join(@base_dir, 'tmp', Time.now.strftime("%Y%m%d%H%M%S%L"))
13
+ FileUtils.mkdir_p @downloads_dir
14
+ @error = nil
15
+ @download_file_path = nil
16
+
17
+ self.class.base_uri @base_url
18
+ end
19
+
20
+ def perform(expand_url)
21
+ @expand_url = expand_url.gsub("\\", "/")
22
+ @error = nil
23
+ @download_file_path = File.join(@downloads_dir, @expand_url)
24
+ FileUtils.mkdir_p File.dirname(@download_file_path)
25
+ begin
26
+ @response = self.class.get(@expand_url)
27
+ rescue Timeout::Error
28
+ @error = 'timeout'
29
+ else
30
+ case @response.code
31
+ when 200
32
+ File.open(@download_file_path, "wb+") do |file|
33
+ file.write @response.body
34
+ end
35
+ when 404
36
+ @error = '404'
37
+ when 500...600
38
+ @error = '500'
39
+ end
40
+ end
41
+ end
42
+
43
+ def downloaded?
44
+ !@error
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,73 @@
1
+ module AviraUpdateMirrors
2
+ class ParseInfo
3
+
4
+ attr_reader :files, :need_download_files
5
+
6
+ def initialize(options)
7
+ @wwwroot_dir = options[:wwwroot_dir]
8
+ @downloads_dir = options[:downloads_dir]
9
+ @files = {}
10
+ @need_download_files = {}
11
+
12
+ end
13
+
14
+ def generate_files_list(&block)
15
+ Dir[File.join(@downloads_dir, "**", "*.info.gz")].each do |info_gz|
16
+ yield " reading and parsing #{info_gz}"
17
+ parse_xml(read_gz(info_gz))
18
+ end
19
+ end
20
+
21
+ def check_files_md5(&block)
22
+ yield " checking #{@files.size} files md5"
23
+ @files.each do |fname, fzipmd5|
24
+ fpath = File.join(@wwwroot_dir, fname)
25
+ unless File.exist?(fpath)
26
+ @need_download_files[fname] = fzipmd5
27
+ else
28
+ unless Digest::MD5.file(fpath) == fzipmd5.downcase
29
+ @need_download_files[fname] = fzipmd5
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+ def read_gz(gzip_file)
37
+ Zlib::GzipReader.open(gzip_file) do |gz|
38
+ gz_body = gz.read rescue ""
39
+ gz.close
40
+ return gz_body
41
+ end
42
+ end
43
+
44
+ def parse_xml(xmlstr)
45
+ xml = Document.new(xmlstr)
46
+ moduleType = []
47
+ xpathquery = "//MODULE"
48
+ XPath.each(xml,xpathquery) do |element|
49
+ moduleType << element.attribute('NAME').to_s
50
+ end
51
+ moduleType.uniq
52
+
53
+ fname = []
54
+ fzipmd5 = []
55
+
56
+ moduleType.each do |m|
57
+ d = XPath.first(xml,"//MODULE[@NAME='#{m}']")
58
+ fp = XPath.first(d,"SOURCE").attribute('value').to_s.gsub(/\\/,"/").gsub(/\.\//,"/")
59
+ next if XPath.first(d,"FILE/NAME") == nil
60
+ XPath.each(d,"FILE/NAME") do |f|
61
+ fname << f.attribute('value').to_s
62
+ end
63
+ XPath.each(d,"FILE/ZIPMD5") do |sum|
64
+ fzipmd5 << sum.attribute('value').to_s
65
+ end
66
+ (0..fname.length-1).each do |n|
67
+ @files[fp.to_s + fname[n].to_s + ".gz"] = fzipmd5[n]
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module AviraUpdateMirrors
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avira_update_mirrors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - vkill
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &14659900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14659900
25
+ description: Avira update mirrors
26
+ email:
27
+ - vkill.net@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - avira_update_mirrors.gemspec
38
+ - examples/mirror_v12f_zhcn.rb
39
+ - examples/mirror_v12f_zhcn_and_v12p_en.rb
40
+ - examples/mirror_v12p_en.rb
41
+ - lib/avira_update_mirrors.rb
42
+ - lib/avira_update_mirrors/configuration.rb
43
+ - lib/avira_update_mirrors/download.rb
44
+ - lib/avira_update_mirrors/parse_info.rb
45
+ - lib/avira_update_mirrors/version.rb
46
+ homepage: https://github.com/vkill/avira_update_mirrors
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.10
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Avira update mirrors
70
+ test_files: []