This commit is contained in:
2024-10-18 22:19:09 +02:00
parent a850f644de
commit ece099b6a4
11 changed files with 1056 additions and 229 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Make sure stdin and stdout are a tty.
if [ ! -t 0 ] ; then
exit 1
@@ -7,17 +7,6 @@ if [ ! -t 1 ] ; then
exit 1
fi
# Save the tty's state.
saved_stty=$(stty -g)
# Trap ^C to fix the tty.
trap ctrl_c INT
function ctrl_c() {
stty "$saved_stty"
exit 1
}
# Read some bytes from stdin. Pass the number of bytes to read as the first argument.
function read_bytes()
{
@@ -47,6 +36,22 @@ function version {
echo -n "$1" | sed -e 's/.* //'
}
trap clean_up EXIT
_STTY=$(stty -g) ## Save current terminal setup
function clean_up() {
stty "$_STTY" ## Restore terminal settings
}
# Prepare to silently read any (>=0) characters with no timeout.
stty -echo -icanon raw min 0 time 0
# Consume all pending input.
while read none; do :; done
# Reset the TTY, so it behaves as expected for the rest of the it2check script.
clean_up
# Enter raw mode and turn off echo so the terminal and I can chat quietly.
stty -echo -icanon raw
@@ -69,7 +74,7 @@ echo -n ''
echo -n ''
version_string=$(read_dsr)
if [ "${version_string}" != "0" -a "${version_string}" != "3" ]; then
if [ -n "${version_string}" -a "${version_string}" != "0" -a "${version_string}" != "3" ]; then
# Already read DSR 1337. Read DSR 5 and throw it away.
dsr=$(read_dsr)
else
@@ -77,9 +82,6 @@ else
version_string=""
fi
# Restore the terminal to cooked mode.
stty "$saved_stty"
# Extract the terminal name and version number from the response.
version=$(version "${version_string}")
term=$(terminal "${version_string}")