1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# -*- shell-script -*-
# gates-of-tartaros – Minimal replacement for agetty with SSH support
#
# Copyright © 2013, 2014, 2015 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 <http://www.gnu.org/licenses/>.
# Module for using the /etc/issue file however
# only partially implemented, but also extended
_display ()
{
if [ ! -f "/etc/issue.default" ] || [ ! "$(md5sum < "/etc/issue.default")" = "$(md5sum < "/etc/issue")" ]; then
python3 <<EOF
import os
import sys
from subprocess import Popen, PIPE
def sh(command):
p = ['sh', '-c', command]
p = Popen(p, stdin = sys.stdin, stdout = PIPE, stderr = sys.stderr)
p = p.communicate()[0].decode('utf-8', 'replace')
return p.rstrip('\\n')
buf = "\\033[H\\033[2J"
data = None
with open("/etc/issue", "rb") as f:
data = f.read().decode("utf-8", "replace")
uname = os.uname()
inet = lambda ip, face = '' : sh("ifconfig %s | grep '^ *%s ' | grep -Po '%s [^ ]*' | cut -d ' ' -f 2 | sed 1q" % (face, ip, ip))
esc = False
for i in range(len(data)):
c = data[i]
i += 1
d = '\\n' if i == len(data) else data[i]
def get_arg():
arg = ''
for j in range(i, len(data)):
arg += data[j]
if arg[-1] == '}':
return arg[1 : -1]
return ''
if esc:
esc = False
if c in "eE": buf += "\\033"
elif c == "N": buf += "\\n"
elif c == "T": buf += "\\t"
elif c == "s": buf += uname.sysname
elif c == "n": buf += uname.nodename
elif c == "r": buf += uname.release
elif c == "v": buf += uname.version
elif c == "m": buf += uname.machine
elif c == "o": buf += sh("hostname -y")
elif c == "O": buf += sh("hostname -d")
elif c == "d": buf += sh("date +%Y-%m-%d")
elif c == "t": buf += sh("date +%H:%M:%S")
elif c == "l": buf += "${tty}"
elif c == "b": buf += sh("stty | grep -Po 'speed [^ ]* baud;' | cut -d ' ' -f 2")
elif c == "u": buf += sh("who | wc -l")
elif c == "U": n = sh('who | wc -l') ; buf += n + (' user' if n == '1' else ' users')
elif c == "4": buf += inet('inet', get_arg() if d == '{' else '')
elif c == "6": buf += inet('inet6', get_arg() if d == '{' else '')
elif c == 'S':
if os.path.exists('/etc/os-release'):
arg = get_arg() if d == '{' else ''
if arg == '':
arg = 'PRETTY_NAME'
val = sh('. /etc/os-release ; echo "${%s}"' % arg)
if (arg == 'PRETTY_NAME') and (val == ''):
val = uname.sysname
elif arg == 'ANSI_COLOR':
val = '\033[%sm' % val
buf += val
else:
buf += c
elif c == "\\\\":
esc = True
else:
buf += c
print(buf, end = "", flush = True)
EOF
echo
echo -n 'Login: '
fi
}
|