#!/bin/bash # syncdropbox -- Synchronize a set of files or a specified folder with # Dropbox. Accomplished by copying the folder into ~/Dropbox or the set of # files into the sync folder in Dropbox, then launching Dropbox.app as # needed setglobal name = '"syncdropbox'" setglobal dropbox = ""$HOME/Dropbox"" setglobal sourcedir = ''"" setglobal targetdir = '"sync'" # Target folder on Dropbox for individual files # Check starting arguments if test $Argc -eq 0 { echo "Usage: $0 [-d source-folder] {file, file, file}" > !2 ; exit 1 } if test $1 = "-d" { setglobal sourcedir = $2 shift; shift } # Validity checks if test ! -z $sourcedir -a $Argc -ne 0 { echo "$name: you can't specify both a directory and specific files." > !2 ; exit 1 } if test ! -z $sourcedir { if test ! -d $sourcedir { echo "$name: please specify a source directory with -d" > !2 ; exit 1 } } ###### MAIN BLOCK if test ! -z $sourcedir { if test -f "$dropbox/$sourcedir" -o -d "$dropbox/$sourcedir" { echo "$name: specified source directory $sourcedir already exists in $dropbox" > !2 ; exit 1 } echo "Copying contents of $sourcedir to $dropbox..." cp -a $sourcedir $dropbox # -a does a recursive copy, preserving owner info &c } else { # No source directory, so we've been given individual files if test ! -d "$dropbox/$targetdir" { mkdir "$dropbox/$targetdir" if test $Status -ne 0 { echo "$name: Error encountered during mkdir $dropbox/$targetdir" > !2 ; exit 1 } } # Ready! Let's copy the specified files cp -p -v $ifsjoin(Argv) "$dropbox/$targetdir" } # Now let's launch the Dropbox app to let it do the actual sync, if needed exec startdropbox -s