Created
November 29, 2010 02:24
-
-
Save chrisgibson/719518 to your computer and use it in GitHub Desktop.
Poor Man's Nook Sync
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
#!/bin/bash | |
# | |
# nook-sync | |
# TODO: Remove hard-coded (mac-specific) device mount dir. | |
# TODO: Provide option for 2-way syncing | |
# TODO: Provide option to delete files on device that aren't in sync dir | |
function usage { | |
cat << EOF | |
usage: $0 options | |
Syncs NOOK_SYNC_DIR with your Nook device. | |
OPTIONS: | |
-h show this message | |
-d dry-run | |
EOF | |
} | |
DRY_RUN= | |
while getopts "dh" OPTION; do | |
case $OPTION in | |
d) | |
DRY_RUN=1 | |
;; | |
h) | |
usage | |
exit 1 | |
;; | |
?) | |
usage | |
exit | |
;; | |
esac | |
done | |
if [ -z "$NOOK_SYNC_DIR" ]; then | |
echo "ERROR: NOOK_SYNC_DIR environment variable not set" | |
usage | |
exit 1 | |
fi | |
if [ ! -d "/Volumes/nook/my documents" ]; then | |
echo "ERROR: Failed to find the nook. Are you sure it's connected?" | |
exit 1 | |
fi | |
function sync_dir { | |
LOCAL_DIR=${NOOK_SYNC_DIR}/"$1" | |
DEVICE_DIR=/Volumes/nook/"$1" | |
if [ ! -d "$LOCAL_DIR" ]; then | |
echo "$1" not found in sync dir. ignoring... | |
echo "$LOCAL_DIR" | |
return | |
fi | |
rsync_options="" | |
if [ ! -z $DRY_RUN ]; then | |
rsync_options="${rsync_options} --dry-run" | |
fi | |
echo Syncing $1... | |
rsync $rsync_options --progress --modify-window=1 --archive --recursive --exclude '.DS_Store' "$LOCAL_DIR"/ "$DEVICE_DIR" | |
} | |
SYNCED_DIRS=("my documents" "my music" "my screensavers" "my wallpapers") | |
for dir in "${SYNCED_DIRS[@]}"; do | |
sync_dir "$dir" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment