media_change.sh 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. exec >> /home/pi/pythonDiskPlayer/mount.log 2>&1
  3. export LC_ALL=en_GB.utf-8
  4. export LANG=en_GB.utf-8
  5. echo "$(date) Start."
  6. echo "$(date) Media change detected on device $1"
  7. device=${1##*/}
  8. lsblk | grep $device
  9. if [ $? -eq 0 ]; then
  10. echo "$(date) Device exists on machine."
  11. echo "$(date) Forcing unmount of floppy"
  12. /usr/bin/systemd-mount --umount /mnt/floppy
  13. echo "$(date) Floppy unmounted"
  14. echo "$(date) Mounting floppy "
  15. /usr/bin/systemd-mount $1 /mnt/floppy
  16. echo "$(date) Floppy mounted"
  17. var=$(cat /mnt/floppy/diskplayer.contents)
  18. echo python3 /home/pi/pythonDiskPlayer/player.py \"$var\"
  19. runuser -l pi -c "/home/pi/pythonDiskPlayer/venv/bin/python3 /home/pi/pythonDiskPlayer/player.py \"$var\""
  20. else
  21. echo "$(date) Device does not exist on machine."
  22. runuser -l pi -c "/home/pi/pythonDiskPlayer/venv/bin/python3 /home/pi/pythonDiskPlayer/player.py stop"
  23. echo "$(date) Forcing unmount of floppy"
  24. /usr/bin/systemd-mount --umount /mnt/floppy
  25. fi
  26. echo "$(date) End."