Created
March 16, 2011 13:02
-
-
Save firstclown/872455 to your computer and use it in GitHub Desktop.
Ruby script to easily upload files to a test server from the command line
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
#!/usr/bin/env ruby | |
class MoverConfig | |
def initialize() | |
@movearray = Array.new | |
config = getConfigFile | |
if(! config) then | |
p ".move not found" | |
exit | |
end | |
File.open(config,"r") { |configFile| | |
@server = configFile.gets().chomp | |
@remoteBaseDir = configFile.gets().chomp | |
} | |
end | |
def getConfigFile | |
keepLooking = true | |
backToDir = directory = Dir.getwd | |
while(keepLooking) | |
if(! Dir['.move'].empty?) then | |
returnDirectory = directory + '/.move' | |
keepLooking = false | |
else | |
dirarray = directory.split(/\//) | |
@movearray.unshift(dirarray.pop) | |
directory = dirarray.join('/') | |
if(directory == '') then | |
keepLooking = false | |
returnDirectory = false | |
else | |
Dir.chdir(directory) | |
end | |
end | |
end | |
Dir.chdir(backToDir) | |
return returnDirectory | |
end | |
def getServer | |
return(@server) | |
end | |
def getRemoteBaseDir | |
dirExtra = @movearray.join('/') | |
if(dirExtra == '') | |
returnVar = @remoteBaseDir | |
else | |
returnVar = @remoteBaseDir + '/' + dirExtra | |
end | |
return returnVar | |
end | |
end | |
command = ARGV[0] | |
mover = MoverConfig.new() | |
if(command == 'ls') then | |
moveRemote = "#{mover.getServer()}:#{mover.getRemoteBaseDir()}/" | |
system("rsync",moveRemote) | |
else | |
(1...ARGV.size()).each do |n| | |
moveRemote = "#{mover.getServer()}:#{mover.getRemoteBaseDir()}/#{ARGV[n]}" | |
moveLocal = "#{ARGV[n]}" | |
p "Remote Directory: " + moveRemote | |
p "Local Directory: " + moveLocal | |
if(command == 'put') then | |
system("rsync","-Ctru",moveLocal,moveRemote) | |
elsif(command == 'get') then | |
system("rsync","-rpt",moveRemote,moveLocal) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment