Created
May 7, 2009 19:07
-
-
Save hagmonk/108283 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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'net/ssh' | |
require 'net/scp' | |
thingsPath = "HOME/Library/Application\ Support/Cultured\ Code/Things/Database.xml" | |
getTimestamp = "ls -lT '#{thingsPath}' | cut -f9-13 -d' '" | |
getThings = "ps waux | grep [T]hings" | |
quitThings = "osascript -e 'tell application \"Things\"\nquit\nend tell'" | |
openThings = "open -a Things" | |
Net::SSH.start("YOUR-REMOTE-HOST.ORG", "USERNAME") do |ssh| | |
home = ssh.exec!("echo $HOME").chomp | |
remotePath = thingsPath.gsub(/HOME/, home) | |
remoteGetTimestamp = getTimestamp.gsub(/HOME/, home) | |
remoteTimestamp = DateTime.parse(ssh.exec!(remoteGetTimestamp)) | |
home = ENV["HOME"] | |
localPath = thingsPath.gsub(/HOME/, home) | |
localGetTimestamp = getTimestamp.gsub(/HOME/, home) | |
localTimestamp = DateTime.parse(`#{localGetTimestamp}`) | |
if remoteTimestamp > localTimestamp | |
puts "Remote host has more recent Things database." | |
if `#{getThings}` != "" | |
puts "Quitting local Things." | |
system(quitThings) | |
end | |
ssh.scp.download!(remotePath.gsub(/ /, "\\ "), localPath) | |
puts "Received file." | |
puts "Re-opening local Things." | |
system(openThings) | |
else | |
puts "Remote host has out of date Things database" | |
if not ssh.exec!(getThings).nil? | |
puts "Quitting remote Things." | |
ssh.exec!(quitThings) | |
end | |
ssh.scp.upload!(localPath, remotePath.gsub(/ /, "\\ ")) | |
puts "Transmitted file." | |
puts "Re-opening remote Things." | |
ssh.exec!(openThings) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment