main/ttyescape: new aports (MR 2309)
Add ttyescape, a script and triggerhappy configuration to allow mobile device
users to access and use a shell without having to plug in to a computer.
One of the largest limitations with a mobile device is the lack of keyboard, for
mainstream OSs like Android and iOS, this is a non-issue as the whole OS stack
is built to automatically recover in case of a crash / hang, hiding the internal
state of affairs from users and making use of careful design to minimise the
impact. When bringing Linux to mobile, we carry not only the benefits of the
Linux desktop but also it's limitations. In the event that your desktop manager
goes haywire or hangs completely, or your graphics drivers get unhappy, the
ability to quickly jump to a tty and start killing bad behaving programs or
reset your display manager is one that most of us take for granted. But when
hit by similar errors on a mobile device there is no such recourse available,
users either have to reboot and hope that the issue doesn't occur again, or pull
out a laptop and pull up a shell (assuming ssh is enabled and the rndis
interface comes up).
ttyescape proposes to solve this issues by pieceing together several already
available tools, notably:
- triggerhappy, a tool used to perform actions when
certain buttons or key combinations are pressed with no dependencies on the
display manager in use.
- fbkeyboard, a framebuffer keyboard for tty's, it
renders on top of the current tty and uses the device touchscreen as input.
2021-07-04 19:14:58 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-11-27 21:21:16 +00:00
|
|
|
# Toggle between tty1 and tty2, launching $KEYBOARD when on tty2
|
main/ttyescape: new aports (MR 2309)
Add ttyescape, a script and triggerhappy configuration to allow mobile device
users to access and use a shell without having to plug in to a computer.
One of the largest limitations with a mobile device is the lack of keyboard, for
mainstream OSs like Android and iOS, this is a non-issue as the whole OS stack
is built to automatically recover in case of a crash / hang, hiding the internal
state of affairs from users and making use of careful design to minimise the
impact. When bringing Linux to mobile, we carry not only the benefits of the
Linux desktop but also it's limitations. In the event that your desktop manager
goes haywire or hangs completely, or your graphics drivers get unhappy, the
ability to quickly jump to a tty and start killing bad behaving programs or
reset your display manager is one that most of us take for granted. But when
hit by similar errors on a mobile device there is no such recourse available,
users either have to reboot and hope that the issue doesn't occur again, or pull
out a laptop and pull up a shell (assuming ssh is enabled and the rndis
interface comes up).
ttyescape proposes to solve this issues by pieceing together several already
available tools, notably:
- triggerhappy, a tool used to perform actions when
certain buttons or key combinations are pressed with no dependencies on the
display manager in use.
- fbkeyboard, a framebuffer keyboard for tty's, it
renders on top of the current tty and uses the device touchscreen as input.
2021-07-04 19:14:58 +00:00
|
|
|
# THIS SCRIPT MUST BE RUN AS ROOT
|
|
|
|
# usage:
|
|
|
|
# togglevt.sh <state>
|
|
|
|
# where <state> is an optional arg to require that a counter be incremented before the action
|
|
|
|
# is performed. The default configuration will perform the switch when the power button has
|
|
|
|
# been pressed 3 times whilst the volume down button is being held.
|
|
|
|
# if no arguments are specified the switch will occur immediately.
|
|
|
|
|
|
|
|
[ "$(whoami)" != root ] && echo "This must be run as root" && exit 1
|
|
|
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
test -f /etc/conf.d/ttyescape.conf && . /etc/conf.d/ttyescape.conf
|
|
|
|
|
|
|
|
# default font, override this by setting it in /etc/conf.d/ttyescape.conf
|
|
|
|
FONT="${FONT:-/usr/share/consolefonts/ter-128n.psf.gz}"
|
|
|
|
# amount of times power must be pressed to trigger
|
|
|
|
PRESSCOUNT="${PRESSCOUNT:-3}"
|
|
|
|
TMPFILE="${TMPFILE:-/tmp/ttyescape.tmp}"
|
2021-11-27 21:21:16 +00:00
|
|
|
KEYBOARD="${KEYBOARD:-buffyboard}"
|
main/ttyescape: new aports (MR 2309)
Add ttyescape, a script and triggerhappy configuration to allow mobile device
users to access and use a shell without having to plug in to a computer.
One of the largest limitations with a mobile device is the lack of keyboard, for
mainstream OSs like Android and iOS, this is a non-issue as the whole OS stack
is built to automatically recover in case of a crash / hang, hiding the internal
state of affairs from users and making use of careful design to minimise the
impact. When bringing Linux to mobile, we carry not only the benefits of the
Linux desktop but also it's limitations. In the event that your desktop manager
goes haywire or hangs completely, or your graphics drivers get unhappy, the
ability to quickly jump to a tty and start killing bad behaving programs or
reset your display manager is one that most of us take for granted. But when
hit by similar errors on a mobile device there is no such recourse available,
users either have to reboot and hope that the issue doesn't occur again, or pull
out a laptop and pull up a shell (assuming ssh is enabled and the rndis
interface comes up).
ttyescape proposes to solve this issues by pieceing together several already
available tools, notably:
- triggerhappy, a tool used to perform actions when
certain buttons or key combinations are pressed with no dependencies on the
display manager in use.
- fbkeyboard, a framebuffer keyboard for tty's, it
renders on top of the current tty and uses the device touchscreen as input.
2021-07-04 19:14:58 +00:00
|
|
|
|
|
|
|
if [ ! -e /dev/uinput ]; then
|
|
|
|
if ! modprobe -q uinput; then
|
|
|
|
echo "uinput module not available, please enable it in your kernel"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
switchtty() {
|
|
|
|
currentvt=$(cat /sys/devices/virtual/tty/tty0/active)
|
|
|
|
|
|
|
|
if [ "$currentvt" = "tty2" ]; then # switch to tty1 with normal UI
|
|
|
|
chvt 1
|
2021-11-27 21:21:16 +00:00
|
|
|
killall "$KEYBOARD"
|
|
|
|
else # Switch to tty2 with $KEYBOARD
|
main/ttyescape: new aports (MR 2309)
Add ttyescape, a script and triggerhappy configuration to allow mobile device
users to access and use a shell without having to plug in to a computer.
One of the largest limitations with a mobile device is the lack of keyboard, for
mainstream OSs like Android and iOS, this is a non-issue as the whole OS stack
is built to automatically recover in case of a crash / hang, hiding the internal
state of affairs from users and making use of careful design to minimise the
impact. When bringing Linux to mobile, we carry not only the benefits of the
Linux desktop but also it's limitations. In the event that your desktop manager
goes haywire or hangs completely, or your graphics drivers get unhappy, the
ability to quickly jump to a tty and start killing bad behaving programs or
reset your display manager is one that most of us take for granted. But when
hit by similar errors on a mobile device there is no such recourse available,
users either have to reboot and hope that the issue doesn't occur again, or pull
out a laptop and pull up a shell (assuming ssh is enabled and the rndis
interface comes up).
ttyescape proposes to solve this issues by pieceing together several already
available tools, notably:
- triggerhappy, a tool used to perform actions when
certain buttons or key combinations are pressed with no dependencies on the
display manager in use.
- fbkeyboard, a framebuffer keyboard for tty's, it
renders on top of the current tty and uses the device touchscreen as input.
2021-07-04 19:14:58 +00:00
|
|
|
setfont "$FONT" -C /dev/tty2
|
|
|
|
chvt 2
|
2021-11-27 21:21:16 +00:00
|
|
|
# sometimes they keyboard can be running already, we shouldn't start it in that case
|
|
|
|
[ "$(pgrep "$KEYBOARD")" ] || nohup "$KEYBOARD" -r "$(cat /sys/class/graphics/fbcon/rotate)" &
|
main/ttyescape: new aports (MR 2309)
Add ttyescape, a script and triggerhappy configuration to allow mobile device
users to access and use a shell without having to plug in to a computer.
One of the largest limitations with a mobile device is the lack of keyboard, for
mainstream OSs like Android and iOS, this is a non-issue as the whole OS stack
is built to automatically recover in case of a crash / hang, hiding the internal
state of affairs from users and making use of careful design to minimise the
impact. When bringing Linux to mobile, we carry not only the benefits of the
Linux desktop but also it's limitations. In the event that your desktop manager
goes haywire or hangs completely, or your graphics drivers get unhappy, the
ability to quickly jump to a tty and start killing bad behaving programs or
reset your display manager is one that most of us take for granted. But when
hit by similar errors on a mobile device there is no such recourse available,
users either have to reboot and hope that the issue doesn't occur again, or pull
out a laptop and pull up a shell (assuming ssh is enabled and the rndis
interface comes up).
ttyescape proposes to solve this issues by pieceing together several already
available tools, notably:
- triggerhappy, a tool used to perform actions when
certain buttons or key combinations are pressed with no dependencies on the
display manager in use.
- fbkeyboard, a framebuffer keyboard for tty's, it
renders on top of the current tty and uses the device touchscreen as input.
2021-07-04 19:14:58 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we receive a command that isn't start
|
|
|
|
# and we don't have the file used to count
|
|
|
|
# then we should do nothing
|
|
|
|
if [ -n "$1" ] && [ "$1" != "start" ] && [ ! -f "$TMPFILE" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
# No args means just DO IT
|
|
|
|
"")
|
|
|
|
switchtty
|
|
|
|
;;
|
|
|
|
# Start counting, this should
|
|
|
|
# run when voldown is pressed
|
|
|
|
"start")
|
|
|
|
echo "0" > "$TMPFILE"
|
|
|
|
;;
|
|
|
|
# Run when voldown releases
|
|
|
|
"reset")
|
|
|
|
rm "$TMPFILE"
|
|
|
|
;;
|
|
|
|
# Run when power pressed while
|
|
|
|
# voldown is pressed
|
|
|
|
"inc")
|
|
|
|
val="$(cat "$TMPFILE")"
|
|
|
|
val=$((val+1))
|
|
|
|
if [ $val -eq "$PRESSCOUNT" ]; then
|
|
|
|
rm "$TMPFILE"
|
|
|
|
switchtty
|
|
|
|
else
|
|
|
|
echo "$val" > "$TMPFILE"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
esac
|