From e08c74ea4e7dd76d6dbbe996327b22e67f6bebaf Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Fri, 29 Mar 2013 20:55:47 +0000 Subject: [PATCH] rksu: rewrite in perl, make syntax consistent with Sysdev's --- bin/rksu | 82 ++++++++++++++++++++++++++++++++---------------- debian/changelog | 6 ++++ debian/control | 2 +- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/bin/rksu b/bin/rksu index 18313c8..2bd9ee0 100755 --- 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"; +} diff --git a/debian/changelog b/debian/changelog index 91d728f..2602157 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mh-sysadmin-tools (1.4) unstable; urgency=low + + * rksu: rewrite in perl, make syntax consistent with Sysdev's + + -- Michael Howe Fri, 29 Mar 2013 20:49:40 +0000 + mh-sysadmin-tools (1.3) unstable; urgency=low * with-creds: support the '-a' option diff --git a/debian/control b/debian/control index 281d2e6..5974bfe 100644 --- a/debian/control +++ b/debian/control @@ -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 -- 2.39.5