floppy-ytube-player/media_change.sh

27 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2024-09-19 12:11:23 +01:00
#!/bin/bash
2024-09-20 08:04:09 +01:00
DEVICE_NAME=$1 # Get the device name passed from udev
2024-09-19 12:11:23 +01:00
2024-09-20 14:50:52 +01:00
BASE_DIR="/home/dietpi"
LOGFILE="$BASE_DIR/media_change.log"
2024-09-19 12:11:23 +01:00
2024-09-20 08:04:09 +01:00
# Check if the device exists in the fdisk -l output and log the result
if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
echo "$(date) Floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
echo "$(date) Mounting device $1 to /mnt/floppy." >> $LOGFILE
2024-09-19 12:11:23 +01:00
/usr/bin/systemd-mount --umount /mnt/floppy
/usr/bin/systemd-mount $1 /mnt/floppy
2024-09-20 08:04:09 +01:00
echo "$(date) Floppy mounted" >> $LOGFILE
# Read content from diskplayer.contents
2024-09-19 12:11:23 +01:00
var=$(cat /mnt/floppy/diskplayer.contents)
2024-09-20 08:04:09 +01:00
echo "$(date) Running Python script with argument: '$var'" >> $LOGFILE
# Run the Python script and capture both stdout and stderr to the log
2024-09-20 14:50:52 +01:00
/usr/bin/python3 $BASE_DIR/floppy-ytube-player/main.py "$var" >> $LOGFILE 2>&1
2024-09-19 12:11:23 +01:00
else
2024-09-20 08:04:09 +01:00
echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
/usr/bin/systemd-mount --umount /mnt/floppy
echo "$(date) Floppy unmounted" >> $LOGFILE
2024-09-20 14:50:52 +01:00
/usr/bin/python3 $BASE_DIR/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
2024-09-19 12:11:23 +01:00
fi