Last active
December 11, 2015 11:28
-
-
Save yasuoza/4593601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :scala do | |
download_scala = 'scala-2.10.0' | |
def bin_files | |
Dir['/usr/share/scala/bin/**'].select { |file_name| file_name !~ /\.+/ }.map { |file_name| file_name.match(/(\w+)$/).captures[0] } | |
end | |
desc "Download #{download_scala}" | |
task :download do | |
if File.exist?("/tmp/#{download_scala}.tgz") | |
puts "Already downloaded #{download_scala}.tgz" | |
else | |
system <<-SCRIPT | |
wget http://www.scala-lang.org/downloads/distrib/files/#{download_scala}.tgz -O /tmp/#{download_scala}.tgz | |
SCRIPT | |
end | |
unless File.exist?("/tmp/#{download_scala}") | |
puts "Extracting /tmp/#{download_scala}..." | |
system "tar xzf /tmp/#{download_scala}.tgz -C /tmp/" | |
end | |
end | |
task :move_source do | |
if File.exist?('/usr/share/scala') | |
puts "Already source moved" | |
else | |
puts "moving scala source to /usr/share/scala" | |
system <<-SCRIPT | |
sudo mv /tmp/#{download_scala} /usr/share/scala | |
SCRIPT | |
end | |
end | |
desc "Create scala bin files' symlink" | |
task :create_symlink do | |
bin_files.each do |bin_file| | |
orig_file = "/usr/share/scala/bin/#{bin_file}" | |
target_file = "/usr/bin/#{bin_file}" | |
if File.exist?(target_file) | |
puts "File already exist: #{bin_file}. skipping..." | |
next | |
end | |
puts "linkng #{bin_file}..." | |
system "sudo ln -s #{orig_file} #{target_file}" | |
end | |
end | |
desc "Install scala" | |
task :install do | |
Rake::Task['scala:download'].execute | |
Rake::Task['scala:move_source'].execute | |
Rake::Task['scala:create_symlink'].execute | |
end | |
desc "Remove created scala bin files' symlink" | |
task :uninstall do | |
bin_files.each do |bin_file| | |
target_file = "/usr/bin/#{bin_file}" | |
next unless File.exist?(target_file) | |
puts "unlinking #{bin_file}" | |
system "sudo rm #{target_file}" | |
end | |
end | |
end | |
namespace :play do | |
version = '2.1.0' | |
download_play = "play-#{version}" | |
desc "Download play 2.1" | |
task :download do | |
if File.exist?("/tmp/#{download_play}") | |
puts "Already downloaded #{download_play}.zip" | |
else | |
system <<-SCRIPT | |
wget http://downloads.typesafe.com/play/#{version}/#{download_play}.zip -O /tmp/#{download_play}.zip | |
SCRIPT | |
end | |
unless File.exist?("/tmp/#{download_play}") | |
puts "Extracting /tmp/#{download_play}..." | |
system "unzip -q /tmp/#{download_play}.zip -d /tmp/" | |
end | |
end | |
task :move_source do | |
if File.exist?('/usr/share/play') | |
puts "Already source moved" | |
else | |
puts "moving scala source to /usr/share/play" | |
system <<-SCRIPT | |
sudo mv /tmp/#{download_play} /usr/share/play | |
SCRIPT | |
end | |
end | |
desc "Create play executable binary's symlink" | |
task :create_symlink do | |
orig_file = '/usr/share/play/play' | |
target_file = '/usr/bin/play' | |
if File.exist?(target_file) | |
puts "File already exist: #{bin_file}. skipping..." | |
else | |
puts "linkng play..." | |
system "sudo ln -s #{orig_file} #{target_file}" | |
end | |
end | |
desc "Install play" | |
task :install do | |
Rake::Task['play:download'].execute | |
Rake::Task['play:move_source'].execute | |
Rake::Task['play:create_symlink'].execute | |
end | |
desc "Remove created play binary's symlink" | |
task :uninstall do | |
puts "unlinking play" | |
system "sudo rm /usr/bin/play" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment