Browse Source

update to use BASE_DIR

Karl Hudgell 6 months ago
parent
commit
3aac573369
1 changed files with 4 additions and 4 deletions
  1. 4 4
      media_change.sh

+ 4 - 4
media_change.sh

@@ -2,14 +2,14 @@
 
 
 DEVICE_NAME=$1  # Get the device name passed from udev
 DEVICE_NAME=$1  # Get the device name passed from udev
 
 
-LOGFILE="/home/dietpi/media_change.log"
+BASE_DIR="/home/dietpi" 
+LOGFILE="$BASE_DIR/media_change.log"
 
 
 # Check if the device exists in the fdisk -l output and log the result
 # Check if the device exists in the fdisk -l output and log the result
 if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
 if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
     echo "$(date) Floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
     echo "$(date) Floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
     echo "$(date) Mounting device $1 to /mnt/floppy." >> $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"  >> $LOGFILE
     /usr/bin/systemd-mount $1 /mnt/floppy
     /usr/bin/systemd-mount $1 /mnt/floppy
     echo "$(date) Floppy mounted"  >> $LOGFILE
     echo "$(date) Floppy mounted"  >> $LOGFILE
 
 
@@ -17,10 +17,10 @@ if sudo fdisk -l | grep -q "$DEVICE_NAME"; then
     var=$(cat /mnt/floppy/diskplayer.contents)
     var=$(cat /mnt/floppy/diskplayer.contents)
     echo "$(date) Running Python script with argument: '$var'"  >> $LOGFILE
     echo "$(date) Running Python script with argument: '$var'"  >> $LOGFILE
     # Run the Python script and capture both stdout and stderr to the log
     # 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 $BASE_DIR/floppy-ytube-player/main.py "$var" >> $LOGFILE 2>&1
 else
 else
     echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
     echo "$(date): No floppy disk is present in device $DEVICE_NAME" >> $LOGFILE
     /usr/bin/systemd-mount --umount /mnt/floppy
     /usr/bin/systemd-mount --umount /mnt/floppy
     echo "$(date) Floppy unmounted"  >> $LOGFILE
     echo "$(date) Floppy unmounted"  >> $LOGFILE
-    /usr/bin/python3 /home/dietpi/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
+    /usr/bin/python3 $BASE_DIR/floppy-ytube-player/main.py EJECT >> $LOGFILE 2>&1
 fi
 fi