Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions scripts/find_input_devices.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -417,16 +438,27 @@ 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}"
echo -e "${BLUE}│${NC} ${WHITE}Device:${NC} $(printf "%-60s" "$name") ${BLUE} │${NC}"
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
Expand Down