Skip to content
Snippets Groups Projects
Unverified Commit 672c85c3 authored by Caleb Connolly's avatar Caleb Connolly :recycle:
Browse files

main/ttyescape: new aports

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.
parent 3dd89c9a
No related branches found
No related tags found
No related merge requests found
# Maintainer: Caleb Connolly <caleb@connolly.tech>
pkgname=ttyescape
pkgver=0.1
pkgrel=0
pkgdesc="Daemon to allow users to escape to a tty"
url="https://postmarketos.org"
arch="all"
license="GPL-3.0-or-later"
depends="triggerhappy fbkeyboard terminus-font kbd"
install="$pkgname.post-install"
source="
togglevt.sh
ttyescape-triggerhappy.conf.example
"
options="!check"
package() {
install -Dm755 "$srcdir"/togglevt.sh \
"$pkgdir"/usr/bin/togglevt.sh
install -Dm755 "$srcdir"/ttyescape-triggerhappy.conf.example \
"$pkgdir"/etc/triggerhappy/triggers.d/ttyescape.conf.example
}
sha512sums="
6a497c0ad6f51edfae2940edd8768cd756f5bc629011f0248f6638415dada5473ae8cc016ce2d8bab438b59f36283c41226e9c5236ed456c12a1783f01bb78d6 togglevt.sh
f8bf3273cf87392ab2092a005417bc58cb3ae6ad25b9118b76c68481d9d8fc7d964a9d16fc7645f6f9ff0676dccd381be3b846464b2e60a6452b8c883bffb6f1 ttyescape-triggerhappy.conf.example
"
#!/bin/sh
# Toggle between tty1 and tty2, launching fbkeyboard when on tty2
# 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.
# default font, override this by setting it in /etc/conf.d/ttyescape.conf
FONT=/usr/share/consolefonts/ter-128n.psf.gz
# amount of times power must be pressed to trigger
PRESSCOUNT=3
TMPFILE="/tmp/ttyescape.tmp"
# shellcheck disable=SC1091
test -f /etc/conf.d/ttyescape.conf && . /etc/conf.d/ttyescape.conf
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
killall fbkeyboard
else # Switch to tty2 with fbkeyboard
setfont $FONT -C /dev/tty2
chvt 2
# sometimes fbkeyboard can be running already, we shouldn't start it in that case
[ "$(pgrep fbkeyboard)" ] || nohup fbkeyboard -r "$(cat /sys/class/graphics/fbcon/rotate)" &
fi
}
if [ "$1" = "" ]; then
switchtty
exit 0
fi
if [ "$1" != "start" ] && [ ! -f "$TMPFILE" ]; then
echo "EXITING"
exit 0
elif [ "$1" = "start" ]; then
echo "0" > "$TMPFILE"
exit 0
elif [ "$1" = "reset" ]; then
rm "$TMPFILE"
exit 0
elif [ "$1" = "inc" ]; then
val="$(cat "$TMPFILE")"
val=$((val+1))
if [ $val -eq $PRESSCOUNT ]; then
rm "$TMPFILE"
switchtty
else
echo "$val" > "$TMPFILE"
exit 0
fi
fi
KEY_POWER+KEY_VOLUMEDOWN 0 /usr/bin/togglevt.sh inc
KEY_VOLUMEDOWN 1 /usr/bin/togglevt.sh start
KEY_VOLUMEDOWN 0 /usr/bin/togglevt.sh reset
# noop to prevent garbage being typed in console
KEY_VOLUMEDOWN 2 /bin/true
#!/bin/sh
CONF_NAME="/etc/triggerhappy/triggers.d/ttyescape.conf"
# Only delete the config if it's still a symlink to the example config
if [ "$(readlink "$CONF_NAME")" = "$CONF_NAME.example" ]; then
rm "$CONF_NAME"
fi
\ No newline at end of file
#!/bin/sh
rc-update -q add triggerhappy default
# Create symlink for triggerhappy config, done here so it can be overriden without breaking world
ln -s /etc/triggerhappy/triggers.d/ttyescape.conf.example /etc/triggerhappy/triggers.d/ttyescape.conf
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment