-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole-test
executable file
·30 lines (25 loc) · 974 Bytes
/
console-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Get the script directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Default values
CHALLENGE="The sun is shining..."
RESPONSE_HASH="cf0dee735ed650d6baca9b6a4e3fb087"
function tty_command()
{
# Run this command if the session is from a physical TTY
$DIR/response-test -c "$CHALLENGE" -m "$RESPONSE_HASH" -s "exit 0" -f "$DIR/lolsh $PPID"
}
# systemd implements an $INVOCATION_ID for processes it spawns (including console TTYs)
# so this should evaluate to true (mostly probably?) only for console TTYs and will run
# if a virtual terminal is started from within a TTY
if [[ -n "$INVOCATION_ID" && -n "$SHELL" ]]; then
tty_command
exit 0
fi
# I don't know if it would ever be possible to login through a
# physical console and not have $SHELL or $INVOCATION_ID set?
# But I'm paranoid. And environment variables aren't always reliable.
# So we also test the tty device.
case $(tty) in /dev/tty[0-9]*)
tty_command ;;
esac