Karl 3 роки тому
батько
коміт
da31f570f9
1 змінених файлів з 26 додано та 0 видалено
  1. 26 0
      media_change.sh

+ 26 - 0
media_change.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+exec >> /home/pi/pythonDiskPlayer/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 pi -c "python3 /home/pi/pythonDiskPlayer/player.py \"$var\""
+else
+    echo "$(date) Device does not exist on machine."
+    runuser -l pi -c "python3 /home/pi/pythonDiskPlayer/player.py stop"
+fi
+echo "$(date) End."