]> git.michaelhowe.org Git - packages/m/mh-sysadmin-tools.git/commitdiff
rksu: rewrite in perl, make syntax consistent with Sysdev's
authorMichael Howe <michael@michaelhowe.org>
Fri, 29 Mar 2013 20:55:47 +0000 (20:55 +0000)
committerMichael Howe <michael@michaelhowe.org>
Fri, 29 Mar 2013 20:55:47 +0000 (20:55 +0000)
bin/rksu
debian/changelog
debian/control

index 18313c86f7d95ee177ce5b9fa7483fc757d8ccad..2bd9ee0188ba86e398d232cf215118d8cff79464 100755 (executable)
--- a/bin/rksu
+++ b/bin/rksu
@@ -1,34 +1,62 @@
-#!/bin/sh
-#
-# $HeadURL$
-# $LastChangedRevision$
-# $LastChangedDate$
-# $LastChangedBy$
-#
-
-usage() {
-    echo "$0 [hostname] [optional_command]"
-    echo ""
-    echo "Connects to a remote system and runs 'ksu' to root"
-    echo "Runs optional_command if specified, otherwise, launches a shell"
-    echo ""
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Getopt::Long;
+
+sub usage {
+    print "$0 [-c command] hostname [hostname2 [...hostnameN]]\n";
+    print "\nConnects to a remote system and runs 'ksu' to root\n";
+    print "Runs command given with -c if specified, otherwise launches bash\n\n";
+}
+
+my( $command, $login, $tty, $quiet );
+
+GetOptions(
+    "c|command=s"   => \$command,
+    "login!"        => \$login,
+    "quiet!"        => \$quiet,
+    "tty!"          => \$tty,
+);
+
+my @hosts = @ARGV;
+
+if( ! @hosts ){
+    warn "No hosts provided\n";
+    usage();
+    exit 1;
 }
 
-if [ $# -eq 0 ]; then
-    echo "Error: no host specified!" >&2
-    usage
-    exit 1
-fi
+# If it's undef it's not specified either way on the command line
+$login = 1
+    unless( defined($login) );
 
-execargs=''
-ADMINPATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
+my $adminpath = "/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin";
 
-targethost=$1
-shift
+my @ssh_args = qw{ -oForwardX11=no -oForwardX11Trusted=no -oGSSAPIDelegateCredentials=yes -oBatchMode=yes -oForwardAgent=no -oClearAllForwardings=yes };
+my @ksu_args = qw{ -z };
+if( $quiet ){
+    push @ksu_args, "-q";
+}
+
+if( ! $command ){
+    $command = "/bin/bash";
+    if( $login ){
+        $command .= " --login";
+        # Force TTY allocation
+        $tty = 1;
+    }
+}
+
+if( $tty ){
+    push @ssh_args, "-t";
+}
 
 
-if [ -n "$1" ]; then
-    execargs="-a -c '$@'"
-fi
+push @ksu_args, "-a", "-c", "'$command'";
 
-ssh -oForwardX11=no -oForwardX11Trusted=no -oGSSAPIDelegateCredentials=yes -t $targethost PATH=$ADMINPATH ksu -z $execargs
+foreach my $host ( @hosts ){
+    my @args = ( "/usr/bin/ssh", @ssh_args, $host, "PATH=$adminpath", "ksu", @ksu_args );
+#    print "Running " . join(' ', @args) . "\n";
+    system( @args ) == 0
+        or warn "rksu failed to $host ('" . join(' ', @args) . "': $!\n";
+}
index 91d728fb91743d9d1861d526aa790d5d2c238ba5..26021578d6e9840a628309efecf48c6a91cc3146 100644 (file)
@@ -1,3 +1,9 @@
+mh-sysadmin-tools (1.4) unstable; urgency=low
+
+  * rksu: rewrite in perl, make syntax consistent with Sysdev's 
+
+ -- Michael Howe <michael@michaelhowe.org>  Fri, 29 Mar 2013 20:49:40 +0000
+
 mh-sysadmin-tools (1.3) unstable; urgency=low
 
   * with-creds: support the '-a' option
index 281d2e638a9e9b0d4420547711b89f8ace65d9f3..5974bfed96616d754db3b2b59a6afefde996c5f4 100644 (file)
@@ -9,7 +9,7 @@ Standards-Version: 3.8.4
 
 Package: mh-sysadmin-tools
 Architecture: all
-Depends: ${misc:Depends}, krb5-user, kstart
+Depends: ${misc:Depends}, krb5-user, kstart, perl
 Recommends: rb3
 Description: General sysadmin tools as used on the michaelhowe.org systems
  This package contains simple scripts that are used for sysadmin work on