-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
etc: Port iptsd-find-hidraw to iptsd-foreach
Also add a deprecation notice, since it can't handle multiple devices.
- Loading branch information
Showing
3 changed files
with
62 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |