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
|
# File 'lib/gastly/phantomjs_patch.rb', line 10
def install!
STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!"
FileUtils.mkdir_p Phantomjs.base_dir
temp_dir = File.join(temp_path, 'phantomjs_install')
FileUtils.rm_rf temp_dir
FileUtils.mkdir_p temp_dir
Dir.chdir temp_dir do
unless download_via_curl || download_via_wget
fail "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n"
end
case package_url.split('.').last
when 'bz2'
system "bunzip2 #{File.basename(package_url)}"
system "tar xf #{File.basename(package_url).sub(/\.bz2$/, '')}"
when 'zip'
system "unzip #{File.basename(package_url)}"
else
fail "Unknown compression format for #{File.basename(package_url)}"
end
= Dir['phantomjs*'].find { |path| File.directory?(path) }
if .nil?
FileUtils.mkdir_p File.join(Phantomjs.base_dir, platform, 'bin')
if FileUtils.mv 'phantomjs', File.join(Phantomjs.base_dir, platform, 'bin')
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
end
else
if FileUtils.mv , File.join(Phantomjs.base_dir, platform)
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
end
end
if FileUtils.rm_rf temp_dir
STDOUT.puts 'Removed temporarily downloaded files.'
end
end
fail 'Failed to install phantomjs. Sorry :(' unless File.exist?(phantomjs_path)
end
|