media_change.sh 1.1 KB

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. DEVICE_NAME=$1 # Get the device name passed from udev
  3. BASE_DIR="/home/dietpi"
  4. LOGFILE="$BASE_DIR/media_change.log"
  5. # Check if the device exists in the fdisk -l output and log the result
  6. if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
  7. echo "$(date) Floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
  8. echo "$(date) Mounting device $1 to /mnt/floppy." >> $LOGFILE
  9. /usr/bin/systemd-mount --umount /mnt/floppy
  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 $BASE_DIR/floppy-ytube-player/main.py "$var" >> $LOGFILE 2>&1
  17. else
  18. echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
  19. /usr/bin/systemd-mount --umount /mnt/floppy
  20. echo "$(date) Floppy unmounted" >> $LOGFILE
  21. /usr/bin/python3 $BASE_DIR/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
  22. fi