Created
June 28, 2010 15:47
-
-
Save banyan/455991 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| require 'fileutils' | |
| def directories(path = Dir.pwd) | |
| Dir.entries(path).map do |f| | |
| expand_path = File.expand_path(f, path) | |
| expand_path if File.directory?(expand_path) | |
| end[2..-1].delete_if {|v| v.nil?} | |
| end | |
| SRC_PATH = "/home/admin/bin/play_src/" | |
| BIN_PATH = "/home/admin/bin/" | |
| COMMAND = "play" | |
| buf = [] | |
| directories(SRC_PATH).each do |path| | |
| buf << path.split(/\//).last | |
| end | |
| version = ARGV.first | |
| unless version then | |
| puts "Usage: ./play_switch.rb version [#{buf.join(' ')}]" | |
| exit | |
| end | |
| def remove_symbolic_link | |
| FileUtils.rm(BIN_PATH + "/#{COMMAND}") if FileTest.exist?(BIN_PATH + "/#{COMMAND}") | |
| end | |
| def create_symbolic_link(version) | |
| original = SRC_PATH + version + '/' + COMMAND | |
| link = BIN_PATH + COMMAND | |
| FileUtils.symlink(original, link) | |
| end | |
| remove_symbolic_link | |
| create_symbolic_link(version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment