1 changed files with 31 additions and 10 deletions
			
			
		@ -1,16 +1,37 @@ | 
				
			|||||
#!/bin/bash | 
					#!/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 | 
					# Get the device name from the udev rule | 
				
			||||
DEVICE_NAME=$1 | 
					DEVICE_NAME=$2 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					SOCKET_PATH="/tmp/usb-Sono-Socket.socket" | 
				
			||||
 | 
					
 | 
				
			||||
# Mount the device | 
					if [ "$ACTION" == "add" ]; then | 
				
			||||
udisksctl mount -b "$DEVICE_NAME" | 
					    # Mount the device | 
				
			||||
 | 
					    udisksctl mount -b "$DEVICE_NAME" | 
				
			||||
 | 
					
 | 
				
			||||
# Check if the mount was successful | 
					    # Check if the mount was successful | 
				
			||||
if [ $? -eq 0 ]; then | 
					    if [ $? -eq 0 ]; then | 
				
			||||
    # Define the socket path | 
					        # Write a message to the socket | 
				
			||||
    SOCKET_PATH="/tmp/usb-Sono-Socket.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" | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    # Check if the unmount was successful | 
				
			||||
 | 
					    if [ $? -eq 0 ]; then | 
				
			||||
        # Write a message to the socket | 
					        # Write a message to the socket | 
				
			||||
    echo "USB storage device connected" | socat - UNIX-CONNECT:$SOCKET_PATH | 
					        echo "success disconnect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH | 
				
			||||
    echo "USB storage device connected" >> /tmp/tmp.log | 
						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