summaryrefslogtreecommitdiff
path: root/d/sys/doc/directssh
blob: 2c8f748ae0b0d59677d28d5c65cfb23c623b5f60 (plain)
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
#!/usr/bin/perl -w
# This is a ssh replacement script to access machine behind another one
# directly. Store in your path as ssh to use it.
#
# Have a look at the Translate section below to make it work for your
# configuration.
#
# 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.
#
# Author: Nicolas Schodet
#
use strict;

my $ssh = '/usr/bin/ssh';

my ($login, $host, @args);

# Parse the arguments.
while ($_ = shift)
{
    # Get login.
    if (/^-l$/) { $login = shift }
    elsif (/^-l/) { $login = substr $_, 2 }
    # Get host or stop.
    elsif (!/^-/)
    {
	if ($host)
	{
	    unshift @ARGV, $_; last
	}
	else
	{
	    $host = $_;
	}
    }
    # Get options.
    else { push @args, $_ }
}

# Decode host.
unless ($host) { exec $ssh }
if ($host =~ /(.*)@(.*)/)
{
    $login = $1;
    $host = $2;
}

# Get command.
my $cmd;
if (@ARGV)
{
    $cmd = join ' ', @ARGV;
}

# Translate.
for ($host)
{
    if (/^noe(.linux.efrei.fr)?$/)
    {
	$host = "choam.efrei.fr";
	$cmd = 'ssh noe.linux.efrei.fr' . ($cmd ? ' ' . $cmd : '');
    }
    if (/^robot(.assos.efrei.fr)?$/)
    {
	$host = "choam.efrei.fr";
	$cmd = 'ssh robot.assos.efrei.fr' . ($cmd ? ' ' . $cmd : '');
    }
}

# Fill args.
push @args, '-l' . $login if $login;
push @args, $host;
push @args, $cmd if $cmd;

# This is for debug.
#open TTY, ">/dev/tty";
#print TTY join ':', @args, "\n";
#close TTY;

exec $ssh, @args;