commit 6c88ca4162d8f912119e9bc3f51020c4bf72bb7b
parent b7d4ab12fc0b1db0a705924db2d688e57fe1bd42
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Sun, 29 Sep 2019 14:09:25 -0400
changed phone syncing scripts
Former-commit-id: d7c683e627f1a1e0e73a166baa169977f6d03221
Diffstat:
2 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/scripts/sync_phone_music b/scripts/sync_phone_music
@@ -1,67 +1,44 @@
#!/usr/bin/env bash
-if ! command -v rsync &>/dev/null; then
- echo "rsync not installed." >&2
+if ! command -v adb-sync &>/dev/null; then
+ echo "adb-sync not installed." >&2
exit 1
fi
+if ! command -v adb &>/dev/null; then
+ echo "adb not installed." >&2
+ exit 1
+fi
+
-do_rsync() {
- rsync -uhamP --iconv=utf-8-mac,utf-8 --delete --stats "$@"
- # This guy saved me: https://askubuntu.com/a/540960
- # "one should always use `--iconv=utf-8-mac,utf-8` when initialising the rsync
- # from the mac, and always use `--iconv=utf-8,utf-8-mac` when initialising the
- # rsync from the linux machine, no matter if I want to sync files from the mac
- # or linux machine."
+do_sync() {
+ adb-sync -d "$@"
+ # Used to use this, keeping for posterity:
+ # rsync -uhamP --iconv=utf-8-mac,utf-8 --delete --stats "$@"
+ # This guy saved me: https://askubuntu.com/a/540960
+ # "one should always use `--iconv=utf-8-mac,utf-8` when initialising the rsync
+ # from the mac, and always use `--iconv=utf-8,utf-8-mac` when initialising the
+ # rsync from the linux machine, no matter if I want to sync files from the mac
+ # or linux machine."
}
die() {
echo "$1" >&2
exit 1
}
-PHONE_DIR="$HOME/phone/Card/Music"
+
+PHONE_DIR="/storage/5D6D-E047/Music"
MUSIC_DIR="${MUSIC_DIR:-$HOME/Music}"
-[ -d "$PHONE_DIR" ] || die "Phone not present, expected at $PHONE_DIR"
[ -d "$MUSIC_DIR" ] || die "Music dir not present, expected at $MUSIC_DIR"
+[ ! -z "$(adb devices | grep device$)" ] || die "Phone not connected."
PARAMS=""
-while (( "$#" )); do
- case "$1" in
- -d|--difference)
- if ! command -v tree &>/dev/null; then
- echo "tree not installed." >&2
- exit 1
- fi
- diff <(tree "$PHONE_DIR") <(tree "$MUSIC_DIR")
- exit 0
- ;;
- -h|--help)
- echo "Usage:"
- echo "Pass -d to only print the difference."
- exit 0
- ;;
- --) # end arg parsing
- shift
- break
- ;;
- -*) # unsupported flags
- echo "Unsupported flag $1" >&2
- exit 1
- ;;
- *) # preserve positional arguments
- PARAMS="$PARAMS $1"
- shift
- ;;
- esac
-done
-eval set -- "$PARAMS"
-
-less -fR <(do_rsync "$MUSIC_DIR"/ "$PHONE_DIR" -n)
+less -fR <(do_sync "$MUSIC_DIR"/ "$PHONE_DIR" --dry-run)
read -rp "Execute? [Y/n]" -n 1 -s conf
echo
case "$conf" in
- Y|y) do_rsync "$MUSIC_DIR"/ "$PHONE_DIR";;
+ Y|y) do_sync "$MUSIC_DIR"/ "$PHONE_DIR";;
*) die "User cancelled.";;
esac
diff --git a/scripts/sync_phone_playlist b/scripts/sync_phone_playlist
@@ -1,4 +1,13 @@
#!/usr/bin/env bash
+if ! command -v adb-sync &>/dev/null; then
+ echo "adb-sync not installed." >&2
+ exit 1
+fi
+if ! command -v adb &>/dev/null; then
+ echo "adb not installed." >&2
+ exit 1
+fi
+
die() {
echo "$1" >&2
exit 1
@@ -6,14 +15,20 @@ die() {
process_file() {
echo "Processing $1"
- tr '\r' '\n' < "$1" | sed 's:^/Volumes.*Music/:../Music/:' > "$PHONE_DIR"/"${1##*/}"
+ tr '\r' '\n' < "$1" | sed 's:^/Volumes.*Music/:../Music/:' > "$tempdir"/"${1##*/}"
+}
+clean_up() {
+ rm -r "$tempdir"
+ exit 0
}
-PHONE_DIR="$HOME/phone/Card/Playlists"
+PHONE_DIR="/storage/5D6D-E047/Playlists"
+[ ! -z "$(adb devices | grep device$)" ] || die "Phone not connected."
-[ -d "$PHONE_DIR" ] || die "Phone not present, expected at $PHONE_DIR"
[ $# -ge 1 ] || die "Need something to act on."
+tempdir="$(mktemp -d)"
+trap clean_up INT KILL TERM QUIT
for i in "$@"; do
if [ -d "$i" ]; then
while read -r f; do
@@ -27,3 +42,12 @@ for i in "$@"; do
fi
fi
done
+
+read -rp "Sync now?" -n 1 -s conf
+case "$conf" in
+ Y|y)
+ adb-sync "$tempdir/" "$PHONE_DIR"
+ ;;
+esac
+
+clean_up