From 472d5e52e874b570ce4f04726796fa63a1853e77 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Jun 2020 01:42:24 -0400 Subject: switch the console to graphics mode before using it --- modules/partofme/files/twitch | 3 +++ modules/partofme/files/vtmode.c | 40 ++++++++++++++++++++++++++++++++++++ modules/partofme/manifests/twitch.pp | 25 +++++++++++++++++++--- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 modules/partofme/files/vtmode.c diff --git a/modules/partofme/files/twitch b/modules/partofme/files/twitch index c28b80b..de5a5a7 100644 --- a/modules/partofme/files/twitch +++ b/modules/partofme/files/twitch @@ -1,3 +1,6 @@ #!/bin/sh +vtmode graphics +trap "vtmode text" EXIT + streamlink -p "cvlc -A alsa --alsa-audio-device hdmi:CARD=PCH,DEV=2 -V fb --no-fb-tty" twitch.tv/"${1}" best diff --git a/modules/partofme/files/vtmode.c b/modules/partofme/files/vtmode.c new file mode 100644 index 0000000..e530674 --- /dev/null +++ b/modules/partofme/files/vtmode.c @@ -0,0 +1,40 @@ +#include +#include + +#include +#include +#include + +int main(int argc, char *argv[]) { + int err, fd, mode; + + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + if (strcmp(argv[1], "graphics") == 0) { + mode = KD_GRAPHICS; + } + else if (strcmp(argv[1], "text") == 0) { + mode = KD_TEXT; + } + else { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + fd = open("/dev/tty0", O_WRONLY); + if (fd < 0) { + perror(argv[0]); + return 1; + } + + err = ioctl(fd, KDSETMODE, mode); + if (err < 0) { + perror(argv[0]); + return 1; + } + + return 0; +} diff --git a/modules/partofme/manifests/twitch.pp b/modules/partofme/manifests/twitch.pp index 13bd824..407a514 100644 --- a/modules/partofme/manifests/twitch.pp +++ b/modules/partofme/manifests/twitch.pp @@ -1,10 +1,29 @@ class partofme::twitch { + include c_toolchain + package { ["streamlink", "vlc"]: ensure => installed; } - file { "/usr/local/bin/twitch": - mode => "0755", - source => 'puppet:///modules/partofme/twitch'; + file { + "/usr/local/bin/twitch": + mode => "0755", + source => 'puppet:///modules/partofme/twitch'; + "/usr/local/src/vtmode.c": + source => 'puppet:///modules/partofme/vtmode.c'; + } + + exec { "compile vtmode": + command => "cc /usr/local/src/vtmode.c -o /usr/local/bin/vtmode", + creates => "/usr/local/bin/vtmode", + require => [ + File["/usr/local/src/vtmode.c"], + Class["c_toolchain"], + ], + } + + exec { "suid vtmode": + command => "chmod u+s /usr/local/bin/vtmode", + require => Exec["compile vtmode"], } } -- cgit v1.2.3-54-g00ecf