Skip to content

Instantly share code, notes, and snippets.

@s-shin
Created August 7, 2018 14:16
Show Gist options
  • Save s-shin/ff22c899187995c31926ac5c5c0f8309 to your computer and use it in GitHub Desktop.
Save s-shin/ff22c899187995c31926ac5c5c0f8309 to your computer and use it in GitHub Desktop.
PREREQUISITE: Install platform-tools and https://github.com/google/adb-sync
#!/bin/bash
set -eu
: ${ITUNES_MEDIA_DIR:="${HOME}/Music/iTunes/iTunes Media"}
: ${DST_MUSIC_DIR:=/storage/0000-0000/Music}
usage() {
cat <<EOT
Usage: $0 [-x]
Options:
-x NOT dryrun
Environments:
ITUNES_MEDIA_DIR="${ITUNES_MEDIA_DIR}"
DST_MUSIC_DIR="${DST_MUSIC_DIR}"
EOT
}
abort() { >&2 echo "ERROR: $*"; exit 1; }
run() { echo "RUN: $*"; "$@"; }
opt_nargs=0
opt_dryrun=true
while (($# > 0)); do
case "$1" in
-h | --help ) usage; exit 1;;
-x ) opt_dryrun=false;;
-* ) abort "unknown option: $1";;
* )
case $((++opt_nargs)) in
* ) abort 'too many arguments';;
esac
;;
esac
shift
done
sync_opts=(-n)
if $opt_dryrun; then
sync_opts=("${sync_opts[@]}" --dry-run)
fi
run adb-sync "${sync_opts[@]}" "${ITUNES_MEDIA_DIR}/Music/" "${DST_MUSIC_DIR}/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment