Skip to content

Commit

Permalink
etc: Port iptsd-find-hidraw to iptsd-foreach
Browse files Browse the repository at this point in the history
Also add a deprecation notice, since it can't handle multiple devices.
  • Loading branch information
StollD committed Apr 25, 2024
1 parent 1b4d896 commit 9735aeb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 47 deletions.
46 changes: 0 additions & 46 deletions etc/iptsd-find-hidraw

This file was deleted.

2 changes: 1 addition & 1 deletion etc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install_subdir(
)

install_data(
'iptsd-find-hidraw',
'scripts/iptsd-find-hidraw',
install_dir: bindir,
install_mode: 'rwxr-xr-x',
)
Expand Down
61 changes: 61 additions & 0 deletions etc/scripts/iptsd-find-hidraw
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later

script_dir="$(dirname "$(realpath "${0}")")"

function spdlog() {
level="${1}"
messages=("${@:2}")

case "${level}" in
info)
level="$(printf "%s%s%s" "\033[32m" "info" "\e[0m")"
;;
warn)
level="$(printf "%s%s%s" "\033[33m\033[1m" "warning" "\e[0m")"
;;
error)
level="$(printf "%s%s%s" "\033[31m\033[1m" "error" "\e[0m")"
;;
esac

echo -e "[$(date '+%H:%M:%S.%3N')] [${level}]" "${messages[@]}" >&2
}

spdlog "warn" "iptsd-find-hidraw is deprecated, please use iptsd-foreach"

function check_and_print_path() {
script="${1}"

if [ -x "${script}" ]; then
echo "${script}"
return 0
fi

return 1
}

function find_iptsd_foreach() {
# iptsd-foreach should always be right next to us
if check_and_print_path "${script_dir}/iptsd-foreach"; then
return 0
fi

# Fall back to looking in PATH
if check_and_print_path "$(command -v "iptsd-foreach" || true)"; then
spdlog "warn" "Using iptsd-foreach from PATH"
spdlog "warn" "This script shouldn't have to use PATH, something might be wrong"
return 0
fi

return 1
}

iptsd_foreach="$(find_iptsd_foreach)"

if [ -z "${iptsd_foreach}" ]; then
spdlog "error" "Could not locate iptsd-foreach"
exit 1
fi

exec "${iptsd_foreach}" -t touchscreen -i 0 -- echo {}

0 comments on commit 9735aeb

Please sign in to comment.