-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
183 lines (164 loc) · 6.65 KB
/
install.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require 'open-uri'
require 'zip'
require "find"
require "./main"
def install()
install_menu = <<~EOS
#####################################
# #
# #
# ░█░█▄░█░▄▀▀░▀█▀▒▄▀▄░█▒░░█▒░ #
# ░█░█▒▀█▒▄██░▒█▒░█▀█▒█▄▄▒█▄▄ #
# #
# #
#####################################
EOS
puts(install_menu)
platform_arch = ARCH.x64? ? "x86_64" : "i686"
platform = platform_version(platform_arch)
print("\nDetected OS and ARCH: #{platform}")
not_detected = <<~EOS
\n\nPlatform not detected!
Further installation is not possible.
Please, execute instructions manually, or fix installation code if you think it's a bug.
EOS
return puts(not_detected) if platform == "unknown"
mac_not_supported = <<~EOS
\n\nMac platform not supported!
Please, install the required packages manually and write the correct path in the main.rb file
EOS
return puts(mac_not_supported) if OS.mac?
chome(platform)
chromedriver(platform)
ext_settings()
done = <<~EOS
\n\n#####################################
# #
# #
# ░█▀▄░▄▀▄░█▄░█▒██▀░█ #
# ▒█▄▀░▀▄▀░█▒▀█░█▄▄░▄ #
# #
# #
#####################################
EOS
puts(done)
end
def chome(platform)
print("\n\nChecking the installation of chrome...")
chome_dir = "#{Dir.pwd}/_browsers/chrome-#{platform}"
puts("\n Chome path: #{chome_dir}")
unless Dir.exist?(chome_dir)
print(" Local chrome not found! Trying to download the stable version..")
unless File.exist?("#{chome_dir}.zip")
chrome_version = "116.0.5845.96" # Need to get the latest version from the site?
download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/#{chrome_version}/#{platform}/chrome-#{platform}.zip"
download = URI.open(download_url)
IO.copy_stream(download, "#{chome_dir}.zip")
print("\n Downloading is complete..\n")
end
print("\n Extracting chrome-#{platform}.zip...\n")
Zip::File.open("#{chome_dir}.zip") do |zip|
zip.each do |entry|
entry_path=File.join("#{Dir.pwd}/_browsers", entry.name)
FileUtils.mkdir_p(File.dirname(entry_path))
zip.extract(entry, entry_path) unless File.exist?(entry_path)
end
end
print(" Extracting complete!\n")
else
manifest = Dir["#{chome_dir}/*.manifest"][0]
chrome_version = !manifest.nil? ? File.basename(manifest, ".manifest") : "unknown"
print(" Local chrome was found! Version: #{chrome_version}")
end
# give execution right
if OS.linux?
print(" \nGive execution rights to chrome folder ...\n")
res = `chmod +x #{chome_dir}/ -R`
print(res)
res = `ls -l #{chome_dir}/chrome`
print(res)
end
end
def chromedriver(platform)
print("\n\nChecking the installation of chromedriver...")
chromedriver_dir = "#{Dir.pwd}/_browsers"
chromedriver = Dir["#{chromedriver_dir}/chromedriver*"].reject { |f| File.extname(f) == ".zip" }[0]
unless chromedriver.nil?
chromedriver_bin = File.basename(chromedriver)
chromedriver_version = `#{chromedriver_dir}/#{chromedriver_bin} -version`
chromedriver_version = chromedriver_version.match(/\d*\.\d*\d*\.\d*\d*\.\d*/)
print("\n Local chromedriver was found! Version: #{chromedriver_version}\n")
else
print("\n Local chromedriver not found! Trying to download the stable version..\n")
unless File.exist?("#{chromedriver_dir}/chromedriver-#{platform}.zip")
chromedriver_version = "116.0.5845.96" # Need to get the latest version from the site?
download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/#{chromedriver_version}/#{platform}/chromedriver-#{platform}.zip"
download = URI.open(download_url)
IO.copy_stream(download, "#{chromedriver_dir}/chromedriver-#{platform}.zip")
print(" Downloading is complete..\n")
end
print(" Extracting chromedriver-#{platform}.zip...\n")
Zip::File.open("#{chromedriver_dir}/chromedriver-#{platform}.zip") do |zip|
zip.each do |entry|
entry_path=File.join("#{Dir.pwd}/_browsers", entry.name.split('/').last)
zip.extract(entry, entry_path) unless File.exist?(entry_path)
end
end
print(" Extracting complete!\n")
chromedriver = Dir["#{chromedriver_dir}/chromedriver*"].reject { |f| File.extname(f) == ".zip" }[0]
chromedriver_bin = File.basename(chromedriver)
end
# give execution right
if OS.linux?
print(" \nGive execution rights to: ./chromedriver binary...\n")
res = `chmod +x #{chromedriver_dir}/#{chromedriver_bin}`
print(res)
res = `ls -l #{chromedriver_dir}/#{chromedriver_bin}`
print(res)
end
end
# extension settings
def ext_settings
print("\nChecking the installation of _ChromeData settings...")
chromedata_path = "#{Dir.pwd}/_browsers/_ChromeData"
puts("\n _ChromeData path: #{chromedata_path}")
unless Dir.exist?(chromedata_path)
print(" _ChromeData folder not found! Trying to create folder...\n\n")
FileUtils.mkdir_p(chromedata_path)
else
print(" _ChromeData folder was found!\n\n")
end
ext_settings_path = "#{chromedata_path}/Default/Local Extension Settings/"
# Violentmonkey script
tfile = "#{ext_settings_path}/jinjaccalgkegednnccohejagnlnfdag/000003.log"
unless File.exist?(tfile)
print(" Extension settings not found! Extracting _settings.zip...\n")
Zip::File.open("#{Dir.pwd}/_browsers/_ext/_settings.zip") do |zip|
zip.each do |entry|
entry_path=File.join("#{Dir.pwd}/_browsers", entry.name)
FileUtils.mkdir_p(File.dirname(entry_path))
zip.extract(entry, entry_path){ true }
end
end
print(" Extracting complete!\n")
else
print(" Extension settings was found!\n")
# script presense check
if (File.size(tfile) < 7000)
print(" Incorrect Violentmonkey script size! Extracting _settings.zip...\n")
Zip::File.open("#{Dir.pwd}/_browsers/_ext/_settings.zip") do |zip|
zip.each do |entry|
entry_path=File.join("#{Dir.pwd}/_browsers", entry.name)
FileUtils.mkdir_p(File.dirname(entry_path))
zip.extract(entry, entry_path){ true }
end
end
print(" Extracting complete!\n")
else
print(" Correct Violentmonkey script size!")
end
end
end
if __FILE__ == $0
install()
end