Browse Source

Refactor usb-storage-action To have both add and remove modes

usb-socket
Mohammad_Faraji 6 months ago
parent
commit
7d50f208b7
  1. 41
      src/scripts/utils/usb/usb-storage-action

41
src/scripts/utils/usb/usb-storage-action

@ -1,16 +1,37 @@
#!/bin/bash
# Get the action (add or remove) and the device name from the udev rule
ACTION=$1
# Get the device name from the udev rule
DEVICE_NAME=$1
DEVICE_NAME=$2
SOCKET_PATH="/tmp/usb-Sono-Socket.socket"
# Mount the device
udisksctl mount -b "$DEVICE_NAME"
if [ "$ACTION" == "add" ]; then
# Mount the device
udisksctl mount -b "$DEVICE_NAME"
# Check if the mount was successful
if [ $? -eq 0 ]; then
# Define the socket path
SOCKET_PATH="/tmp/usb-Sono-Socket.socket"
# Check if the mount was successful
if [ $? -eq 0 ]; then
# Write a message to the socket
echo "success connect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH
echo "success connect $DEVICE_NAME" >> /tmp/tmp.log
else
echo "failure connect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH
echo "failure connect $DEVICE_NAME" >> /tmp/tmp.log
fi
elif [ "$ACTION" == "remove" ]; then
# Unmount the device
udisksctl unmount -b "$DEVICE_NAME"
# Write a message to the socket
echo "USB storage device connected" | socat - UNIX-CONNECT:$SOCKET_PATH
echo "USB storage device connected" >> /tmp/tmp.log
# Check if the unmount was successful
if [ $? -eq 0 ]; then
# Write a message to the socket
echo "success disconnect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH
echo "success disconnect $DEVICE_NAME" >> /tmp/tmp.log
else
echo "failure disconnect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH
echo "failure disconnect $DEVICE_NAME" >> /tmp/tmp.log
fi
fi

Loading…
Cancel
Save