Skip to content

Instantly share code, notes, and snippets.

@AlekseyDurachenko
Last active February 8, 2017 18:20
Show Gist options
  • Save AlekseyDurachenko/335e3ca333a70d16a101 to your computer and use it in GitHub Desktop.
Save AlekseyDurachenko/335e3ca333a70d16a101 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e # abort if any command failed
# MP3 player must be attached to the USB
if [ ! -b /dev/disk/by-uuid/2408-0200 ]
then
echo "MP840 is not attached"
exit 1
fi
# /etc/fstab:
# UUID=2408-0200 /media/MP840 vfat noauto,async,rw,user,dmask=000,fmask=111,utf8,codepage=866 0 0
mount /media/MP840
# the flag file must be created on the device root
if [ ! -f /media/MP840/rsync-accept.flag ]
then
echo "The flag file on the MP840 is missing"
umount -l /media/MP840
exit 1
fi
# detect the dbus session of the current user
USERNAME=`whoami`
export DBUS_SESSION_BUS_ADDRESS=`ps -u $USERNAME e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35`
# for kde5 because previous recept is not working
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]
then
pid=$(pgrep -u $USERNAME kdeconnectd)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//' )
export DBUS_SESSION_BUS_ADDRESS=$dbus
fi
# notification of the beginning of the synchronization
echo "Synchronization is beginning"
espeak -p 1 "Synchronization is beginning"
if [ ! -z "$DBUS_SESSION_BUS_ADDRESS" ]
then
notify-send "MP3 Player MP840" "Synchronization is beginning..."
fi
# synchronization: mirror
rsync -vr --delete --size-only /home/user/MySync/TranscendMP840/sdcard/ /media/MP840/sdcard/
# operation may take a long time, due to `async` in the /etc/fstab
umount -l /media/MP840
# notification of the completion of synchronization
echo "Synchronization is complete"
espeak -p 1 "Synchronization is complete"
if [ ! -z "$DBUS_SESSION_BUS_ADDRESS" ]
then
notify-send "MP3 Player MP840" "Synchronization is complete!"
fi
# all is well
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment