4 changed files with 26 additions and 130 deletions
@ -1,93 +0,0 @@ |
|||||
#!/bin/bash |
|
||||
|
|
||||
ACTION=$1 |
|
||||
DEVNAME=$2 |
|
||||
|
|
||||
SOCKET_PATH="/tmp/usb-Sono-Socket.socket" |
|
||||
LOG_FILE="/tmp/tmpDvd.log" |
|
||||
DEBOUNCE_FILE="/tmp/dvd_debounce_$(echo $DEVNAME | tr '/' '-')" |
|
||||
DEBOUNCE_TIME=10 # seconds |
|
||||
|
|
||||
current_time=$(date +%s) |
|
||||
|
|
||||
# Function to log messages |
|
||||
log_message() { |
|
||||
local message=$1 |
|
||||
echo $message | socat - UNIX-CONNECT:$SOCKET_PATH |
|
||||
echo $message >> $LOG_FILE |
|
||||
} |
|
||||
|
|
||||
# Function to get the size of the DVD |
|
||||
get_dvd_size() { |
|
||||
udisksctl info -b $DEVNAME | grep 'Size:' | awk '{print $2}' | head -n 1 |
|
||||
} |
|
||||
|
|
||||
# Function to check for debounce |
|
||||
check_debounce() { |
|
||||
SIZE=$(get_dvd_size) |
|
||||
if [SIZE -eq 0]; then |
|
||||
ATTEMPTS=3 |
|
||||
while [ "$SIZE" -eq 0 ] && [ $ATTEMPTS -gt 0 ]; do |
|
||||
sleep 2 |
|
||||
SIZE=$(get_dvd_size) |
|
||||
log_message "Debounced: Retried size of $DEVNAME is $SIZE" |
|
||||
ATTEMPTS=$((ATTEMPTS - 1)) |
|
||||
done |
|
||||
elif [SIZE -eq 0]; then |
|
||||
log_message "exit on: Retried size of $DEVNAME is $SIZE" |
|
||||
exit 0 |
|
||||
fi |
|
||||
|
|
||||
if [ -f "$DEBOUNCE_FILE" ]; then |
|
||||
last_run_time=$(cat $DEBOUNCE_FILE) |
|
||||
elapsed_time=$((current_time - last_run_time)) |
|
||||
if [ $elapsed_time -lt $DEBOUNCE_TIME ]; then |
|
||||
log_message "Debounced: $ACTION $DEVNAME" |
|
||||
exit 0 |
|
||||
fi |
|
||||
fi |
|
||||
echo $current_time > $DEBOUNCE_FILE |
|
||||
} |
|
||||
|
|
||||
check_debounce |
|
||||
|
|
||||
|
|
||||
|
|
||||
if [ "$ACTION" == "change" ]; then |
|
||||
# Introduce a delay before checking the device |
|
||||
sleep 2 # Wait for 2 seconds before proceeding |
|
||||
|
|
||||
# Check if the device is already mounted |
|
||||
MOUNTED=$(lsblk -o MOUNTPOINT -nr $DEVNAME) |
|
||||
if [ -z "$MOUNTED" ]; then |
|
||||
# Device is not mounted, check if it is a raw DVD |
|
||||
SIZE=$(get_dvd_size) |
|
||||
|
|
||||
# Debug output for size |
|
||||
log_message "DEBUG: Initial size of $DEVNAME is $SIZE" |
|
||||
|
|
||||
# Retry logic for getting the size |
|
||||
ATTEMPTS=3 |
|
||||
while [ "$SIZE" -eq 0 ] && [ $ATTEMPTS -gt 0 ]; do |
|
||||
sleep 2 |
|
||||
SIZE=$(get_dvd_size) |
|
||||
log_message "DEBUG: Retried size of $DEVNAME is $SIZE" |
|
||||
ATTEMPTS=$((ATTEMPTS - 1)) |
|
||||
done |
|
||||
|
|
||||
if [ "$SIZE" -gt 0 ]; then |
|
||||
log_message "success insert raw DVD $DEVNAME" |
|
||||
else |
|
||||
# Proceed to mount the device |
|
||||
udisksctl mount -b $DEVNAME |
|
||||
if [ $? -eq 0 ]; then |
|
||||
log_message "success mount $DEVNAME" |
|
||||
else |
|
||||
log_message "failed to mount $DEVNAME" |
|
||||
fi |
|
||||
fi |
|
||||
else |
|
||||
log_message "$DEVNAME is already mounted at $MOUNTED" |
|
||||
fi |
|
||||
log_message "success insert $DEVNAME" |
|
||||
fi |
|
@ -0,0 +1,13 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
ACTION=$1 |
||||
|
DEVICE_NAME=$2 |
||||
|
SOCKET_PATH="/run/dvd-Sono-Socket.socket" |
||||
|
|
||||
|
if [ "$ACTION" == "add" ]; then |
||||
|
echo -n "success insert $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH |
||||
|
echo "success insert $DEVICE_NAME with socat" >> /tmp/tmpDvd.log |
||||
|
elif [ "$ACTION" == "remove" ]; then |
||||
|
echo -n "success eject $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH |
||||
|
echo "success eject $DEVICE_NAME" >> /tmp/tmpDvd.log |
||||
|
fi |
@ -1,37 +0,0 @@ |
|||||
#!/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=$2 |
|
||||
|
|
||||
SOCKET_PATH="/tmp/usb-Sono-Socket.socket" |
|
||||
|
|
||||
if [ "$ACTION" == "add" ]; then |
|
||||
# Mount the device |
|
||||
udisksctl mount -b "$DEVICE_NAME" |
|
||||
|
|
||||
# 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" |
|
||||
|
|
||||
# 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 |
|
@ -0,0 +1,13 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
ACTION=$1 |
||||
|
DEVICE_NAME=$2 |
||||
|
SOCKET_PATH="/run/usb-Sono-Socket.socket" |
||||
|
|
||||
|
if [ "$ACTION" == "add" ]; then |
||||
|
echo -n "success connect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH |
||||
|
echo "success connect $DEVICE_NAME with socat" >> /tmp/tmpUsb.log |
||||
|
elif [ "$ACTION" == "remove" ]; then |
||||
|
echo -n "success disconnect $DEVICE_NAME" | socat - UNIX-CONNECT:$SOCKET_PATH |
||||
|
echo "success disconnect $DEVICE_NAME" >> /tmp/tmpUsb.log |
||||
|
fi |
Loading…
Reference in new issue