From 5238da68cdb1f51a416564a0faeb909f25d9b168 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 28 Jan 2011 12:07:16 +0000 Subject: [PATCH] Allow specifying paths to Kerberos helpers. Use -I to tell ktmux_helper where to find kinit. Use -L to tell ktmux_helper where to find klist. Use -R to tell ktmux_helper where to find krenew. If any of the above options are omitted, ktmux_helper will search for the corresponding tool in the PATH. --- .profile.d/tmux.bashrc | 6 ++++-- opt/bin/ktmux | 17 +++++++++++++++-- opt/bin/ktmux_helper | 18 +++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.profile.d/tmux.bashrc b/.profile.d/tmux.bashrc index 458c94f..b5ac757 100644 --- a/.profile.d/tmux.bashrc +++ b/.profile.d/tmux.bashrc @@ -1,9 +1,11 @@ # profile-requires: screen.bashrc # XXX: Use a module. tmux=$(PATH=$PATH:/comm/tmux/stable/bin find_working tmux 2>/dev/null) +krenew=$(PATH=$PATH:/comm/kstart/stable/bin find_working krenew 2>/dev/null) if [ $? = 0 ]; then - alias session="bigtmux $tmux has -t session 2>/dev/null && tmux attach -t session || ktmux -T $tmux -s session" + alias session="bigtmux $tmux has -t session 2>/dev/null && tmux attach -t session || ktmux -R $krenew -T $tmux -s session" if [ -n "$TMUX" ]; then - $tmux run-shell ktmux_helper ';' detach 2>/dev/null + $tmux run-shell "ktmux_helper -R $krenew" ';' detach 2>/dev/null fi fi +unset krenew tmux diff --git a/opt/bin/ktmux b/opt/bin/ktmux index eb590da..9d88576 100755 --- a/opt/bin/ktmux +++ b/opt/bin/ktmux @@ -1,10 +1,23 @@ #!/bin/bash +# +# ktmux: Start tmux and ktmux_helper. +# Usage: ktmux [options] +# Options: -I Pass path to kinit through to ktmux_helper. +# -L Pass path to klist through to ktmux_helper. +# -R Pass path to krenew through to ktmux_helper. +# -T Path to tmux. +# -n Window name for new tmux session. +# -s Session name for new tmux session. +# -t Target session name for new tmux session. +# tmux=tmux +helper_opts= tmux_opts= session_opts= -while getopts ":T:n:s:t:" opt; do +while getopts ":I:L:R:T:n:s:t:" opt; do case $opt in + I|L|R) helper_opts="$helper_opts -$opt $OPTARG";; T) tmux="$OPTARG";; n|s|t) session_opts="$session_opts -$opt $OPTARG";; esac @@ -18,4 +31,4 @@ if [ -z "$KRB5CCNAME" ]; then fi klist -s || kinit -exec $tmux ${tmux_opts## } new-session ${session_opts## } -d ';' set-environment KRB5CCNAME "$KRB5CCNAME" ';' attach ';' run-shell ktmux_helper +exec $tmux ${tmux_opts## } new-session ${session_opts## } -d ';' set-environment KRB5CCNAME "$KRB5CCNAME" ';' attach ';' run-shell "ktmux_helper ${helper_opts## }" diff --git a/opt/bin/ktmux_helper b/opt/bin/ktmux_helper index 31605c8..fe942d4 100755 --- a/opt/bin/ktmux_helper +++ b/opt/bin/ktmux_helper @@ -1,10 +1,15 @@ #!/usr/bin/perl # # ktmux_helper: Run krenew in the background for tmux. +# Usage: ktmux_helper [options] +# Options: -I Specify path to kinit. +# -L Specify path to klist. +# -R Specify path to krenew. # Notes: Doesn't handle multiple sessions properly. # use FindBin; +use Getopt::Std; use POSIX ":sys_wait_h"; my $PROG = $FindBin::Script; @@ -21,6 +26,13 @@ my $tmux_helper = &get_tmux_helper; exit 0 if $tmux_helper; $tmux_helper = $$; +my %opts; +getopts('I:L:R:', \%opts); + +my $kinit = $opts{'I'} || "kinit"; +my $klist = $opts{'L'} || "klist"; +my $krenew = $opts{'R'} || "krenew"; + my $exitasap = 0; my $pid = 0; @@ -47,7 +59,7 @@ LOOP: while (&ping_tmux) { } else { exit 1 if &check_credentials; - exec "krenew", "-K", "60"; + exec $krenew, "-K", "60"; print "$PROG: Can't run krenew: $!\n"; exit 111; } @@ -88,7 +100,7 @@ sub ping_tmux { # Try to check existing Kerberos credentials. sub check_credentials { - system "klist", "-s"; + system $klist, "-s"; return 1 if $? < 0; return 0 unless $?; kill USR1, $tmux_helper; @@ -99,7 +111,7 @@ sub check_credentials { sub want_credentials { # Do we already know? return sleep 1 if &check_kinit_child; - system "tmux", "new-window", "-n", "Renew Kerberos credentials", "exec kinit"; + system "tmux", "new-window", "-n", "Renew Kerberos credentials", "exec $kinit"; } sub cleanup { -- 2.7.4