Karl Hudgell 6 месяцев назад
Родитель
Сommit
386db9ba31
2 измененных файлов с 27 добавлено и 0 удалено
  1. 1 0
      100-floppy-change.rules
  2. 26 0
      media_change.sh

+ 1 - 0
100-floppy-change.rules

@@ -0,0 +1 @@
+ACTION=="change", ATTRS{idVendor}=="057b", ATTRS{idProduct}=="0000", ENV{DISK_MEDIA_CHANGE}=="1", RUN+="/home/dietpi/floppy-ytube-player/media_change.sh $env{DEVNAME}"

+ 26 - 0
media_change.sh

@@ -0,0 +1,26 @@
+#!/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##*/}
+
+lsblk | grep $device
+
+if [ $? -eq 0 ]; then
+    echo "$(date) Device exists on machine."
+    echo "$(date) Mounting device $1 to /mnt/floppy."
+    /usr/bin/systemd-mount --umount /mnt/floppy
+    echo "$(date) Floppy unmounted"
+    /usr/bin/systemd-mount $1 /mnt/floppy
+    echo "$(date) Floppy mounted"
+    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\""
+else
+    echo "$(date) Device does not exist on machine."
+    runuser -l dietpi -c "python3 /home/dietpi/floppy-ytube-player/main.py stop"
+fi
+echo "$(date) End."