commit 0473645a76e005adc0540ed489ff088c07575a73
parent f3e17dad3fe6d5c5dc5fd2c94953d977d32c589e
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Sun, 22 Sep 2019 13:42:27 -0400
Updated phone syncing scripts, they actually kinda work now
Former-commit-id: 6df16d97fa3a680f43e13c2c67b047a3662a2d46
Diffstat:
3 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/scripts/mount_phone b/scripts/mount_phone
@@ -10,9 +10,10 @@ clean_up() {
echo "Exiting..."
if kill -0 "$mtpfs_pid" &> /dev/null; then
kill "$mtpfs_pid"
+ wait "$mtpfs_pid"
fi
- [ ! -d "$mountpoint" ] || rm -r "$mountpoint";
- [ ! -L "$mountdir" ] || rm "$mountdir";
+ [ ! -d "$mountpoint" ] || rmdir "$mountpoint";
+ [ ! -L "$mountdir" ] || unlink "$mountdir";
}
trap clean_up INT TERM EXIT
diff --git a/scripts/sync_phone_music b/scripts/sync_phone_music
@@ -5,7 +5,12 @@ if ! command -v rsync &>/dev/null; then
fi
do_rsync() {
- rsync -uhamP --delete --stats "$@"
+ 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
@@ -17,6 +22,39 @@ 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"
+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)
read -rp "Execute? [Y/n]" -n 1 -s conf
diff --git a/scripts/sync_phone_playlist b/scripts/sync_phone_playlist
@@ -1,10 +1,29 @@
#!/usr/bin/env bash
-[ $# -eq 2 ] || { echo "Please pass the playlist and playlist dir path as an argument." && exit 1; }
+die() {
+ echo "$1" >&2
+ exit 1
+}
-if command -v gsed &>/dev/null; then
- sedcmd="gsed"
-else
- sedcmd="sed"
-fi
+process_file() {
+ echo "Processing $1"
+ tr '\r' '\n' < "$1" | sed 's:^/Volumes.*Music/:../Music/:' > "$PHONE_DIR"/"${1##*/}"
+}
-cat "$1" | tr '\r' '\n' | $sedcmd 's:/Volumes.*Music/:../Music/:' > "$2"/"${1##*/}"
+PHONE_DIR="$HOME/phone/Card/Playlists"
+
+[ -d "$PHONE_DIR" ] || die "Phone not present, expected at $PHONE_DIR"
+[ $# -ge 1 ] || die "Need something to act on."
+
+for i in "$@"; do
+ if [ -d "$i" ]; then
+ while read -r f; do
+ process_file "$f"
+ done < <(find "$i" -name "*.m3u" -type f -maxdepth 1)
+ elif [ -f "$i" ]; then
+ if [[ "$i" == *.m3u ]]; then
+ process_file "$i"
+ else
+ echo "Could not process $i"
+ fi
+ fi
+done