updated media_change.sh
This commit is contained in:
parent
2b8c95f3f6
commit
fca38b5819
@ -1,26 +1,27 @@
|
||||
#!/bin/bash
|
||||
exec >> /home/dietpi/mount.log 2>&1
|
||||
export LC_ALL=en_GB.utf-8
|
||||
export LANG=en_GB.utf-8
|
||||
|
||||
echo "$(date) Start."
|
||||
echo "$(date) Media change detected on device $1"
|
||||
device=${1##*/}
|
||||
DEVICE_NAME=$1 # Get the device name passed from udev
|
||||
|
||||
lsblk | grep $device
|
||||
LOGFILE="/home/dietpi/media_change.log"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "$(date) Device exists on machine."
|
||||
echo "$(date) Mounting device $1 to /mnt/floppy."
|
||||
# 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
|
||||
/usr/bin/systemd-mount --umount /mnt/floppy
|
||||
echo "$(date) Floppy unmounted"
|
||||
echo "$(date) Floppy unmounted" >> $LOGFILE
|
||||
/usr/bin/systemd-mount $1 /mnt/floppy
|
||||
echo "$(date) Floppy mounted"
|
||||
echo "$(date) Floppy mounted" >> $LOGFILE
|
||||
|
||||
# Read content from diskplayer.contents
|
||||
var=$(cat /mnt/floppy/diskplayer.contents)
|
||||
echo python3 /home/pi/pythonDiskPlayer/player.py \"$var\"
|
||||
runuser -l dietpi -c "python3 /home/dietpi/floppy-ytube-player/main.py \"$var\""
|
||||
echo "$(date) Running Python script with argument: '$var'" >> $LOGFILE
|
||||
# Run the Python script and capture both stdout and stderr to the log
|
||||
/usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py "$var" >> $LOGFILE 2>&1
|
||||
/usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py PLAY >> $LOGFILE 2>&1
|
||||
else
|
||||
echo "$(date) Device does not exist on machine."
|
||||
runuser -l dietpi -c "python3 /home/dietpi/floppy-ytube-player/main.py stop"
|
||||
echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
|
||||
/usr/bin/systemd-mount --umount /mnt/floppy
|
||||
echo "$(date) Floppy unmounted" >> $LOGFILE
|
||||
/usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
|
||||
fi
|
||||
echo "$(date) End."
|
||||
|
Loading…
x
Reference in New Issue
Block a user