Module: AviraUpdateMirrors
- Defined in:
- lib/avira_update_mirrors.rb,
lib/avira_update_mirrors/version.rb,
lib/avira_update_mirrors/download.rb,
lib/avira_update_mirrors/parse_info.rb,
lib/avira_update_mirrors/configuration.rb
Defined Under Namespace
Classes: Download, ParseInfo
Constant Summary
collapse
- VERSION =
"0.1.0"
- Configuration =
Struct.new(
:wwwroot_dir,
:products
).new(
'wwwroot',
[
"v12f_zhcn" => {
"update_servers" => %w`
http://80.190.143.227/update
`,
"idx_master" => %q`/idx/master.idx`,
"idxes" => %w`
/idx/wks_avira12-win32-zhcn-pecl.idx
/idx/wks_avira12-win32-zhcn-pecl.info.gz
/idx/webcat-common-int.info.gz
/idx/vdf.info.gz
/idx/rdf-common-int.info.gz
/idx/ave2-win32-int.info.gz
/idx/wks_avira12-win32-zhcn-pecl-info.info.gz
/idx/peclkey-common-int.info.gz
/idx/scanner-win32-int.info.gz
`
}
]
)
Class Method Summary
collapse
Class Method Details
15
16
17
|
# File 'lib/avira_update_mirrors.rb', line 15
def self.configure
yield Configuration
end
|
.mirror ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/avira_update_mirrors.rb', line 19
def self.mirror
@@base_dir = Dir.pwd
@@wwwroot_dir = File.join(@@base_dir, Configuration.wwwroot_dir)
@@download = {}
FileUtils.mkdir_p @@wwwroot_dir
Configuration.products.each_with_index do |product, n|
product.each do |product_name, product_config|
puts "mirroring #{product_name}"
puts " choice update_server"
product_config["update_servers"].each do |update_server|
puts " try #{update_server}"
download = Download.new(update_server, :base_dir => @@base_dir)
download.perform(product_config["idx_master"])
if download.downloaded?
@@download[product_name] = download
puts " use this update_server #{update_server}"
break
else
next
end
end
raise "all update_servers invalidation" unless @@download[product_name]
product_config["idxes"].each do |idx|
puts " downloading #{idx}"
@@download[product_name].perform(idx)
end
parse_info = ParseInfo.new(:wwwroot_dir => @@wwwroot_dir, :downloads_dir => @@download[product_name].downloads_dir)
parse_info.generate_files_list do |msg|
puts msg
end
parse_info.check_files_md5 do |msg|
puts msg
end
puts " #{parse_info.need_download_files.size} files need download"
parse_info.need_download_files.each do |file_name, file_zip_md5|
puts " downloading #{file_name}"
@@download[product_name].perform(file_name)
unless Digest::MD5.file(@@download[product_name].download_file_path) == file_zip_md5.downcase
raise "downloaded file md5 error!"
end
end
puts " copy downloaded files to wwwroot_dir and destroy downloaded files"
FileUtils.cp_r File.join(@@download[product_name].downloads_dir, "."), @@wwwroot_dir
FileUtils.rm_rf @@download[product_name].downloads_dir
end
end
end
|