media_change.sh 847 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. exec >> /home/dietpi/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) Mounting device $1 to /mnt/floppy."
  12. /usr/bin/systemd-mount --umount /mnt/floppy
  13. echo "$(date) Floppy unmounted"
  14. /usr/bin/systemd-mount $1 /mnt/floppy
  15. echo "$(date) Floppy mounted"
  16. var=$(cat /mnt/floppy/diskplayer.contents)
  17. echo python3 /home/pi/pythonDiskPlayer/player.py \"$var\"
  18. runuser -l dietpi -c "python3 /home/dietpi/floppy-ytube-player/main.py \"$var\""
  19. else
  20. echo "$(date) Device does not exist on machine."
  21. runuser -l dietpi -c "python3 /home/dietpi/floppy-ytube-player/main.py stop"
  22. fi
  23. echo "$(date) End."