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