diff --git a/scripts/find_input_devices.sh b/scripts/find_input_devices.sh index 8bc3bb15..81aaa51a 100755 --- a/scripts/find_input_devices.sh +++ b/scripts/find_input_devices.sh @@ -230,15 +230,36 @@ check_input_group() { get_device_status() { local device="$1" - if stat "$device" >/dev/null 2>&1; then - echo -e "${GREEN}${CHECK} Accessible${NC}" - return 0 + # Check existence + if [[ ! -e "$device" ]]; then + return 2 # missing + fi + + # Get file metadata + local mode owner group + mode=$(stat -c "%a" "$device") + owner=$(stat -c "%u" "$device") + group=$(stat -c "%g" "$device") + + # Determine readability + local readable=0 + local euid=$(id -u) + local user_groups=$(id -Gn) + local group_name + group_name=$(getent group "$group" | cut -d: -f1) + + if [[ $euid -eq "$owner" ]] || echo "$user_groups" | grep -qw "$group_name"; then + readable=1 + fi + + if (( readable )); then + return 0 # accessible else - echo -e "${RED}${CROSS} Permission Denied${NC}" - return 1 + return 1 # permission denied fi } + # Get device type based on name, capabilities, and handlers get_device_type() { local device_name="$1" @@ -417,6 +438,8 @@ display_devices() { fi # Process and display each device + local status + local status_code while IFS='|' read -r name path type; do if [[ "$GENERATE_CONFIG" == "false" ]]; then echo -e "${BLUE}┌───────────────────────────────────────────────────────────────────────────┐${NC}" @@ -424,9 +447,18 @@ display_devices() { echo -e "${BLUE}│${NC} ${WHITE}Path:${NC} $(printf "%-60s" "$path") ${BLUE} │${NC}" echo -e "${BLUE}│${NC} ${WHITE}Type:${NC} $(printf "%-60s" "$type") ${BLUE} │${NC}" - local status - status=$(get_device_status "$path") - echo -e "${BLUE}│${NC} ${WHITE}Status:${NC} $status $(printf "%*s" $((60 - ${#status} + 10)) "") ${BLUE} │${NC}" + set +e + get_device_status "$path" + status_code=$? # capture numeric return + set -e + + case $status_code in + 0) status="${GREEN}${CHECK} Accessible${NC}" ;; + 1) status="${RED}[ERROR] Permission Denied${NC}" ;; + 2) status="${YELLOW}[MISSING] Device not found${NC}" ;; + esac + + echo -e "${BLUE}│${NC} ${WHITE}Status:${NC} $status $(printf "%*s" $((66 - ${#status} + 10)) "") ${BLUE} │${NC}" echo -e "${BLUE}└───────────────────────────────────────────────────────────────────────────┘${NC}" echo fi