-PROGS = pong vmware-detect align dpkg_not_running reread_partition_table
+PROGS = pong vmware-detect align dpkg_not_running reread_partition_table grml-runtty
#ifndef CFLAGS
CFLAGS = -O2 -Wall -s
reread_partition_table: reread_partition_table.c
diet $(CC) $(CFLAGS) -o $@ $^
+grml-runtty: grml-runtty.c
+ $(CC) $(CFLAGS) -o $@ $^
+
clean:
rm -f $(PROGS)
--- /dev/null
+/*
+ * Copyright 2011 Christian Hofstaedtler. Licensed under GPL Version 2.
+ *
+ * Most of this is copied from fgetty, which is
+ * Copyright Felix von Leitner, licensed under GPL Version 2.
+*/
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <signal.h>
+
+char* tty;
+char* prog;
+char* user;
+
+void error(const char* message, int exitcode) {
+ write(2, "E: ", 3);
+ write(2, message, strlen(message));
+ write(2, "\n", 1);
+ syslog(LOG_CRIT, "%s", message);
+ sleep(15);
+ closelog();
+ exit(exitcode);
+}
+
+void sigquit_handler(int signum) {
+ error("SIGQUIT received\n",23);
+}
+
+void setup_tty() {
+ struct sigaction sa;
+ int fd;
+ if (chown(tty,0,0) || chmod(tty,0600))
+ error("could not chown/chmod tty device\n",1);
+ sa.sa_handler=SIG_IGN;
+ sa.sa_flags=0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGHUP,&sa,NULL);
+ sa.sa_handler=sigquit_handler;
+ sigaction(SIGQUIT,&sa,NULL);
+
+ setsid();
+ if ((fd=open(tty, O_RDWR, 0))<0)
+ error("open tty failed", errno);
+ if (ioctl (fd, TIOCSCTTY, (void *)1) == -1)
+ error("ioctl TIOCSCTTY failed", errno);
+ if (!isatty(fd))
+ error("\"not a typewriter\" (isatty failed)", errno);
+ if (vhangup()) /* linux specific */
+ error("vhangup failed", errno);
+ close(2); close(1); close(0); close(fd);
+ if (open(tty, O_RDWR,0) != 0)
+ error("could not (re)open tty", errno);
+ if (dup(0) != 1 || dup(0) != 2)
+ error("could not dup stdout and stderr", errno);
+
+ sa.sa_handler=SIG_DFL;
+ sa.sa_flags=0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGHUP,&sa,NULL);
+}
+
+void setenvvar(char* envvar, char* value) {
+ /* buf ends up directly in env. can't use alloca */
+ char* buf = malloc(strlen(envvar) + strlen(value) + 2);
+ strcpy(buf, envvar);
+ strcat(buf, "=");
+ strcat(buf, value);
+ putenv(buf);
+}
+
+int main(int argc, char* argv[]) {
+ struct passwd* pw;
+
+ tty = argv[1];
+ prog = argv[2];
+ user = argv[3];
+
+ openlog("startprog", LOG_CONS | LOG_PID, LOG_AUTHPRIV);
+
+ if (tty == NULL || prog == NULL || user == NULL)
+ error("Usage: startprog /dev/ttyX /bin/bash user", 1);
+
+ pw = getpwnam(user);
+ if (!pw)
+ error("User does not exist", 1);
+
+ clearenv();
+ putenv("TERM=linux");
+ setenvvar("TTY", tty);
+ setenvvar("USER", pw->pw_name);
+ setenvvar("LOGNAME", pw->pw_name);
+ setenvvar("SHELL", pw->pw_shell);
+ setenvvar("HOME", pw->pw_dir);
+ {
+ char uidbuf[15];
+ sprintf(uidbuf, "%i", pw->pw_uid);
+ setenvvar("UID", uidbuf);
+ }
+
+#ifndef DEBUG
+ setup_tty();
+#endif
+ chown(tty, pw->pw_uid, pw->pw_gid);
+
+ if (initgroups(pw->pw_name, pw->pw_gid) == -1)
+ error("initgroups failed", 1);
+ if (setgid(pw->pw_gid) == -1)
+ error("setgid failed", 1);
+ if (setuid(pw->pw_uid) == -1)
+ error("setuid failed", 1);
+
+ {
+ char *Argv[] = {prog, 0};
+ execve(prog, Argv, environ);
+ }
+
+ /* should never come here */
+ error("Program startup failed", 99);
+}
etc/grml
etc/postfix
+sbin
usr/bin
usr/sbin
usr/share/grml-scripts
install -m 755 compile/vmware-detect debian/grml-scripts/usr/bin/vmware-detect
install -m 755 compile/dpkg_not_running debian/grml-scripts/usr/sbin/dpkg_not_running
install -m 755 compile/reread_partition_table debian/grml-scripts/usr/sbin/reread_partition_table
+ install -m 755 compile/grml-runtty debian/grml-scripts/sbin/grml-runtty
# Build architecture-independent files here.
binary-indep: build install
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-hostname.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-info.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-init.1.gz \
- /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-init-screen.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-lock.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-mutt.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-postfix.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-soundtest.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-lang.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-resolution.1.gz \
+ /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-runtty.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-slrn.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-start.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/grml-tpm.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/XF86AudioLowerVolume.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/XF86AudioMute.1.gz \
/usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/XF86AudioRaiseVolume.1.gz \
- /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/zsh-login.1.gz \
/usr/share/man/man1/gsuggest.1.gz /usr/share/man/man1/gsuggest.pl.1.gz
dh_strip
dh_compress
collect hardware information and write it to info.tar.bz2
.SS grml-info
start browser with documentation for Grml
-.SS grml-init
-fix tty permissions and run screen and zsh (notice: not required for
-interactive usage but only for startup of Grml system)
.SS grml-lock
lock virtual consoles
.SS grml-mutt
configuration script for mailclient mutt
.SS grml-resolution
change X resolution via a simple menu frontend
+.SS grml-runtty
+runs arbitrary programs on the specified tty
.SS grml-lang
switch keyboard layout
.SS grml-slrn
Raise audio volume.
.SS xsay
output X clipboard text via flite (soundsystem)
-.SS zsh-login
-Start zsh using login-option through exec.
.SH "ADMIN SCRIPTS"
+++ /dev/null
-#!/bin/dash
-# Filename: grml-init
-# Purpose: fix tty permissions and run zsh
-# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
-# Bug-Reports: see http://grml.org/bugs/
-# License: This file is licensed under the GPL v2.
-################################################################################
-
-# export variable USER for use withing GNU screen:
- export USER=`id -un`
-
-# fix rungetty:
- TTY=`tty`
- sudo chown $USER.$USER $TTY
-
-# now start the shell:
- exec /bin/zsh
-
-## END OF FILE #################################################################
+++ /dev/null
-#!/bin/dash
-# Filename: grml-init-screen
-# Purpose: fix tty permissions and run screen and zsh afterwards
-# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
-# Bug-Reports: see http://grml.org/bugs/
-# License: This file is licensed under the GPL v2.
-################################################################################
-
-# export variable USER for use withing GNU screen:
- export USER=`id -un`
-
-# fix rungetty:
- TTY=`tty`
- sudo chmod 660 $TTY
- sudo chown $USER.tty $TTY
-
-# now start screen:
- cd $HOME
- # do we have a utf8 enabled terminal?
- /usr/bin/screen -U -c /etc/grml/screenrc ; exec /bin/zsh
-
-## END OF FILE #################################################################
#!/bin/dash
# Filename: grml-init-multitail
-# Purpose: fix tty permissions and run multitail
+# Purpose: run multitail
# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>,
# (c) Michael Gebetsroither <gebi@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################
-# export variable USER for use withing GNU screen:
- export USER=`id -un`
-
-# fix rungetty:
- TTY=`tty`
- sudo chown $USER.$USER $TTY
-
-# now start the shell:
- exec /usr/bin/multitail -o 'check_mail:0' /var/log/syslog
+exec /usr/bin/multitail -o 'check_mail:0' /var/log/syslog
## END OF FILE #################################################################
--- /dev/null
+#!/bin/dash
+# Filename: run-screen
+# Purpose: wrapper for screen to start with appropriate configuration
+# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Bug-Reports: see http://grml.org/bugs/
+# License: This file is licensed under the GPL v2.
+################################################################################
+
+# try to mitigate raceconditions from screen
+SCREENDIR_="/var/run/screen"
+mkdir -m 700 "${SCREENDIR_}/S-$USER" >/dev/null 2>&1
+
+# now run screen with config
+
+ if [ `id -u` = 0 ] ; then
+ exec screen -U -c /etc/grml/screenrc
+ elif [ -r "$HOME/.screenrc" ] ; then
+ exec screen -U -c "$HOME/.screenrc"
+ else
+ exec screen -U -c /etc/grml/screenrc_generic
+ fi
+
+## END OF FILE #################################################################
#!/bin/bash
-# Filename: zsh-login
+# Filename: run-welcome
# Purpose: customized zsh login welcome screen for use at grml
# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports: see http://grml.org/bugs/