File: raregetty

package info (click to toggle)
hxtools 20180301-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,600 kB
  • sloc: ansic: 5,926; perl: 3,905; sh: 1,638; cpp: 342; makefile: 191; asm: 173
file content (68 lines) | stat: -rwxr-xr-x 1,203 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl
#
#	raregetty
#	written by Jan Engelhardt, 2004-2007
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the WTF Public License version 2 or
#	(at your option) any later version.
#

chdir "/var/lib/empty";
chroot "/var/lib/empty";

use Getopt::Long;
use strict;

my($Clearscr, $Noreopen);
my $Defaulthost = "127.0.0.1";
my $Host        = "*";

&Getopt::Long::Configure(qw(bundling pass_through));
&GetOptions(
  "c"   => \$Clearscr,
  "d=s" => \$Defaulthost,
  "h=s" => \$Host,
  "n"   => \$Noreopen,
);

my $Tty = pop @ARGV;
&query4ssh();

sub query4ssh ()
{
	my $login;

	&reopen_ttys();
	$< = $> = 65534;

	while ($login eq "") {
		if ($Clearscr) {
			print "\e[1;1H\e[2J";
                }
		print "login: ";
		chomp($login = <STDIN>);
	}

	if ($Host eq "*") {
		print "host [$Defaulthost]: ";
		chomp($Host = <STDIN>);
		if( $Host eq "") {
			$Host = $Defaulthost;
		}
	}

	exit(exec "ssh", $login."\@".$Host);
}

sub reopen_ttys ()
{
	if (!$Noreopen) {
		open(STDIN, "< /dev/$Tty");
		open(STDOUT, "> /dev/$Tty");
		open(STDERR, "> /dev/$Tty");
	}
	select((select(STDOUT), $| = 1)[0]);
	select((select(STDERR), $| = 1)[0]);
	return;
}