#!/usr/bin/env ruby $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require "dbox" # usage line def usage <<_EOF Usage: dbox [] Commands: authorize Generate auth keys create [] Create a new Dropbox folder clone [] Clone an existing Dropbox folder pull [] Pull chonges from Dropbox push [] Push changes to Dropbox sync [] Sync changes to Dropbox move [] Move the remote Dropbox folder to a new location Environment varables needed for everything: export DROPBOX_APP_KEY=cmlrrjd3j0gbend export DROPBOX_APP_SECRET=uvuulp75xf9jffl Environment varables needed for everything other than authorize: export DROPBOX_AUTH_KEY=v4d7l1rez1czksn export DROPBOX_AUTH_SECRET=pqej9rmnj0i1gcxr4 See http://github.com/kenpratt/dbox for examples and more information _EOF end def print_usage_and_quit; puts usage; exit 1; end # ensure that push/pull arg was given print_usage_and_quit unless ARGV.size >= 1 command = ARGV[0] args = ARGV[1..-1] # execute the command case command when "authorize" Dbox.authorize when "create", "clone" unless args.size >= 1 puts "Error: Please provide a remote path to clone" print_usage_and_quit end remote_path = args[0] # default to creating a directory inside the current directory with # the same name of the directory being created/cloned local_path = args[1] || remote_path.split("/").last res = Dbox.send(command, remote_path, local_path) exit 1 if res[:failed].size > 0 when "pull", "push" # default to current directory local_path = args[0] || "." res = Dbox.send(command, local_path) exit 1 if res[:failed].size > 0 when "sync" # default to current directory local_path = args[0] || "." res = Dbox.sync(local_path) exit 1 if res[:pull][:failed].size > 0 || res[:push][:failed].size > 0 when "move" remote_path = args[0] # default to current directory local_path = args[1] || "." Dbox.send(command, remote_path, local_path) else print_usage_and_quit end