From 71ae0af4bad2fd38ded15bcb643f0ad73232c480 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 30 Sep 2013 03:09:49 +0200 Subject: get rid of python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 14 ++------------ README | 2 +- got | 45 ++++++++++++++++++++++++++++++++++----------- got.py | 47 ----------------------------------------------- gotrc | 23 +++++++++++++---------- 5 files changed, 50 insertions(+), 81 deletions(-) delete mode 100755 got.py diff --git a/Makefile b/Makefile index 201295b..acb3691 100644 --- a/Makefile +++ b/Makefile @@ -2,38 +2,29 @@ PREFIX = SYSCONF = /etc BIN = /bin SBIN = /sbin -LIBEXEC = /libexec LICENSES = /usr/share/licenses COMMAND = got PKGNAME = gates-of-tartaros BASH_SHEBANG = /usr/bin/env bash -PY3_SHEBANG = /usr/bin/env python3 - -all: got.install got.py.install got-cmd.install +all: got.install got-cmd.install got.install: got cp "$<" "$@" sed -i 's:#!/usr/bin/env bash:#!$(BASH_SHEBANG):g' "$@" sed -i 's:@prefix@:$(PREFIX):g' "$@" sed -i 's:@etc@:$(SYSCONF):g' "$@" - sed -i 's:@libexec@:$(LIBEXEC):g' "$@" sed -i 's:@command@:$(COMMAND):g' "$@" -got.py.install: got.py - cp "$<" "$@" - sed -i 's:#!/usr/bin/env python3:#!$(PY3_SHEBANG):g' "$@" - got-cmd.install: got-cmd cp "$<" "$@" sed -i 's:#!/usr/bin/env bash:#!$(BASH_SHEBANG):g' "$@" -install: got.install got.py.install got-cmd.install +install: got.install got-cmd.install install -Dm755 -- "got.install" "$(DESTDIR)$(PREFIX)$(SBIN)/got" - install -Dm755 -- "got.py.install" "$(DESTDIR)$(PREFIX)$(LIBEXEC)/got.py" install -Dm755 -- "got-cmd.install" "$(DESTDIR)$(PREFIX)$(BIN)/got-cmd" install -Dm644 -- "gotrc" "$(DESTDIR)$(SYSCONF)/gotrc.examples/lower-left-ponysay" install -d -- "$(DESTDIR)$(LICENSES)/$(PKGNAME)" @@ -42,7 +33,6 @@ install: got.install got.py.install got-cmd.install uninstall: -rm -- "$(DESTDIR)$(PREFIX)$(SBIN)/got" - -rm -- "$(DESTDIR)$(PREFIX)$(LIBEXEC)/got.py" -rm -- "$(DESTDIR)$(PREFIX)$(BIN)/got-cmd" -rm -- "$(DESTDIR)$(SYSCONF)/gotrc.examples/lower-left-ponysay" -rm -- "$(DESTDIR)$(LICENSES)/$(PKGNAME)/COPYING" diff --git a/README b/README index 290de99..4555751 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ Minimal replacement for agetty written in -Bash and Python with support for SSH. +GNU Bash with support for remote SSH login. En example /etc/gotrc file is included, it requires ponysay, util-say and KMS diff --git a/got b/got index 429f70f..b41091a 100755 --- a/got +++ b/got @@ -18,30 +18,53 @@ # along with this program. If not, see . -if [ "$1" = "---" ]; then +if [ "$1" = "-" ]; then tty="$2" shift 2 + export "$@" + + function _login + { + read user + if [ ! "${user/@/}" = "${user}" ]; then + export GOT_COMMAND="ssh ${user}" + login -p -f sshlogin + elif [ "${user::1}" = "-" ]; then + stty -icanon -echo -isig -ix{on,off,any} + echo $'\e[01;31mNice try! Sleeping for 10 minutes...\e[00m' + sleep 600 + else + login -- "${user}" + fi + } + + function _display + { + echo -en '\e[H\e[2J' + echo -e "\e[${ANSI_COLOR}m${NAME} (${tty})\e[00m" + echo + echo -n 'Login: ' + } + NAME="$(uname -o)" ANSI_COLOR='01;34' # must be exactly ANSI_COLOR as it is defined in /etc/os-release if [ -f "@etc@/os-release" ]; then . "@etc@/os-release" fi - if [ -f "@etc@/@command@rc" ]; then . "@etc@/@command@rc" - else - echo -en '\e[H\e[2J' - echo -e "\e[${ANSI_COLOR}m${NAME} (${tty})\e[00m" - echo - echo -n 'Login: ' fi - tty_settings="$(stty --save)" - @prefix@@libexec@/@command@.py "$@" - stty "${tty_settings}" + _display + _login else + # cannot get any other solution to work with `login` + # then to spawn a new process with pipes preset + tty="/dev/$1" - "$0" --- "$@" > "${tty}" 2> "${tty}" < "${tty}" + tty_settings="$(stty --save)" + "$0" - "$@" > "${tty}" 2> "${tty}" < "${tty}" + stty "${tty_settings}" fi diff --git a/got.py b/got.py deleted file mode 100755 index a96e30a..0000000 --- a/got.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -''' -gates-of-tartaros – Minimal replacement for agetty with SSH support - -Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -''' - - -import os -import sys -import time -from subprocess import Popen - - -for arg in sys.argv[1:]: - if "=" in arg: - os.putenv(arg.split("=")[0], "=".join(arg.split("=")[1:])) - -def spawn(cmd): - Popen(cmd, stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr).wait() - - -user = input() -if "@" in user: - os.putenv("GOT_COMMAND", "ssh " + user) - spawn(["login", "-p", "-f", "sshlogin"]) -else: - if user.startswith("-"): - spawn(["stty", "-icanon", "-echo", "-isig", "-ixon", "-ixoff", "-ixany"]) - print("\033[01;31mNice try! Sleeping for 10 minutes...\033[00m") - time.sleep(10 * 60) - else: - spawn(["login", user]) - diff --git a/gotrc b/gotrc index 94f9f68..7ebaff1 100644 --- a/gotrc +++ b/gotrc @@ -1,13 +1,16 @@ # -*- shell-script -*- -PALETTE=$'\e]P0020840\e]P1CD656C\e]P232A679\e]P3CCAD47\e]P42495BE\e]P5A46EB0\e]P600A09F\e]P7D3D7CF\e]P8555753\e]P9EB5E6A\e]PA0EC287\e]PBF2CA38\e]PC00ACE0\e]PDC473D1\e]PE00C3C7\e]PFEEEEEE' -echo -n "${PALETTE}" -echo -en '\e[H\e[2J\e[?8c' -pony="$(PONYSAY_SHELL_LINES=5 PONYSAY_KMS_PALETTE="${PALETTE}" ponysay -o <&2)" -lines=$(wc -l <<< "${pony}") -height=$(stty size | cut -d ' ' -f 1) -echo -n $'\e['"$(( $height - $lines + 1 ));1H$(sed -e 's:\x1b\[H\x1b\[2J::' <<< "${pony}")${PALETTE}"$'\e[H' -echo -e "\e[${ANSI_COLOR}m${NAME} (${tty})\e[00m" -echo -echo -n 'Login: ' +function _display +{ + PALETTE=$'\e]P0020840\e]P1CD656C\e]P232A679\e]P3CCAD47\e]P42495BE\e]P5A46EB0\e]P600A09F\e]P7D3D7CF\e]P8555753\e]P9EB5E6A\e]PA0EC287\e]PBF2CA38\e]PC00ACE0\e]PDC473D1\e]PE00C3C7\e]PFEEEEEE' + echo -n "${PALETTE}" + echo -en '\e[H\e[2J\e[?8c' + pony="$(PONYSAY_SHELL_LINES=5 PONYSAY_KMS_PALETTE="${PALETTE}" ponysay -o <&2)" + lines=$(wc -l <<< "${pony}") + height=$(stty size | cut -d ' ' -f 1) + echo -n $'\e['"$(( $height - $lines + 1 ));1H$(sed -e 's:\x1b\[H\x1b\[2J::' <<< "${pony}")${PALETTE}"$'\e[H' + echo -e "\e[${ANSI_COLOR}m${NAME} (${tty})\e[00m" + echo + echo -n 'Login: ' +} -- cgit v1.2.3-70-g09d2