Mohammad_Faraji
6 months ago
1 changed files with 31 additions and 10 deletions
@ -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…
Reference in new issue