android-sync-music/sync-music

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-05-04 15:10:54 +02:00
#!/usr/bin/env sh
###BEGIN CONFIGURATION###
SOURCE_DIR="$HOME/Music/"
DEST_DIR="Internal shared storage/Music/"
###END CONFIGURATION###
UID=$(id -u -r)
die() {
echo "\033[31;1m$@\033[m"
exit 1
}
info() {
echo "\033[33;1m$@\033[m"
}
get_mtp_dir() {
mtpdir="$(echo /run/user/$UID/gvfs/mtp* | head -n1)"
[ -d "$mtpdir" ] && echo "$mtpdir"
}
2022-05-06 13:49:21 +02:00
[ -z "$1" ] && info "Any arguments are passed to rsync."
2022-05-04 15:10:54 +02:00
info "Configuration: 💻:'$SOURCE_DIR' -> 📱:'$DEST_DIR'."
[ ! -d "$SOURCE_DIR" ] && die "The specified source directory '$SOURCE_DIR' does not exist!"
if [ -n "$(get_mtp_dir)" ]; then
info "MTP already mounted."
else
info "Mounting MTP device..."
mtpdev="$(gio mount -li | sed -ne 's@.*=\(mtp://.*\)@\1@p')"
[ -z "$mtpdev" ] && die "MTP device not found!"
gio mount "$mtpdev" || die "Unable to mount MTP device!"
fi
info "Syncing to '$(get_mtp_dir)'."
rsync --progress \
--human-readable \
--omit-dir-times \
--no-perms \
--size-only \
--recursive \
--inplace \
--exclude='*.parts' \
2022-05-06 13:49:21 +02:00
"$@" \
2022-05-04 15:10:54 +02:00
"$SOURCE_DIR" "$(get_mtp_dir)/$DEST_DIR" \
&& info "Success!" \
|| die "Error synchronizing files!"