summaryrefslogtreecommitdiff
path: root/d/sys/doc/directssh
diff options
context:
space:
mode:
Diffstat (limited to 'd/sys/doc/directssh')
-rwxr-xr-xd/sys/doc/directssh82
1 files changed, 82 insertions, 0 deletions
diff --git a/d/sys/doc/directssh b/d/sys/doc/directssh
new file mode 100755
index 0000000..2c8f748
--- /dev/null
+++ b/d/sys/doc/directssh
@@ -0,0 +1,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;