Skip to content

Commit 9735aeb

Browse files
committed
etc: Port iptsd-find-hidraw to iptsd-foreach
Also add a deprecation notice, since it can't handle multiple devices.
1 parent 1b4d896 commit 9735aeb

File tree

3 files changed

+62
-47
lines changed

3 files changed

+62
-47
lines changed

etc/iptsd-find-hidraw

-46
This file was deleted.

etc/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ install_subdir(
55
)
66

77
install_data(
8-
'iptsd-find-hidraw',
8+
'scripts/iptsd-find-hidraw',
99
install_dir: bindir,
1010
install_mode: 'rwxr-xr-x',
1111
)

etc/scripts/iptsd-find-hidraw

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
script_dir="$(dirname "$(realpath "${0}")")"
5+
6+
function spdlog() {
7+
level="${1}"
8+
messages=("${@:2}")
9+
10+
case "${level}" in
11+
info)
12+
level="$(printf "%s%s%s" "\033[32m" "info" "\e[0m")"
13+
;;
14+
warn)
15+
level="$(printf "%s%s%s" "\033[33m\033[1m" "warning" "\e[0m")"
16+
;;
17+
error)
18+
level="$(printf "%s%s%s" "\033[31m\033[1m" "error" "\e[0m")"
19+
;;
20+
esac
21+
22+
echo -e "[$(date '+%H:%M:%S.%3N')] [${level}]" "${messages[@]}" >&2
23+
}
24+
25+
spdlog "warn" "iptsd-find-hidraw is deprecated, please use iptsd-foreach"
26+
27+
function check_and_print_path() {
28+
script="${1}"
29+
30+
if [ -x "${script}" ]; then
31+
echo "${script}"
32+
return 0
33+
fi
34+
35+
return 1
36+
}
37+
38+
function find_iptsd_foreach() {
39+
# iptsd-foreach should always be right next to us
40+
if check_and_print_path "${script_dir}/iptsd-foreach"; then
41+
return 0
42+
fi
43+
44+
# Fall back to looking in PATH
45+
if check_and_print_path "$(command -v "iptsd-foreach" || true)"; then
46+
spdlog "warn" "Using iptsd-foreach from PATH"
47+
spdlog "warn" "This script shouldn't have to use PATH, something might be wrong"
48+
return 0
49+
fi
50+
51+
return 1
52+
}
53+
54+
iptsd_foreach="$(find_iptsd_foreach)"
55+
56+
if [ -z "${iptsd_foreach}" ]; then
57+
spdlog "error" "Could not locate iptsd-foreach"
58+
exit 1
59+
fi
60+
61+
exec "${iptsd_foreach}" -t touchscreen -i 0 -- echo {}

0 commit comments

Comments
 (0)