media_change.sh 1.2 KB

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. DEVICE_NAME=$1 # Get the device name passed from udev
  3. LOGFILE="/home/dietpi/media_change.log"
  4. # Check if the device exists in the fdisk -l output and log the result
  5. if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
  6. echo "$(date) Floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
  7. echo "$(date) Mounting device $1 to /mnt/floppy." >> $LOGFILE
  8. /usr/bin/systemd-mount --umount /mnt/floppy
  9. echo "$(date) Floppy unmounted" >> $LOGFILE
  10. /usr/bin/systemd-mount $1 /mnt/floppy
  11. echo "$(date) Floppy mounted" >> $LOGFILE
  12. # Read content from diskplayer.contents
  13. var=$(cat /mnt/floppy/diskplayer.contents)
  14. echo "$(date) Running Python script with argument: '$var'" >> $LOGFILE
  15. # Run the Python script and capture both stdout and stderr to the log
  16. /usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py "$var" >> $LOGFILE 2>&1
  17. /usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py PLAY >> $LOGFILE 2>&1
  18. else
  19. echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
  20. /usr/bin/systemd-mount --umount /mnt/floppy
  21. echo "$(date) Floppy unmounted" >> $LOGFILE
  22. /usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
  23. fi