[go: up one dir, main page]

Menu

[r130]: / bin / ct-ssh  Maximize  Restore  History

Download this file

162 lines (139 with data), 3.5 kB

#!/bin/sh
## ct-ssh for ct-ssh in /home/ctaf/.ctafconf/bin
##
## Made by GESTES Cedric
## Login   <ctaf@epita.fr>
##
## Started on  Mon Sep 26 04:19:16 2005 GESTES Cedric
## Last update Thu Apr 20 22:03:05 2006 GESTES Cedric
##
##CTAFCONF

action=$1
fname=$2
sshdir=~/.ctafconf/perso/ssh

readparam=""
echo test_bob | read -e testbob >/dev/null 2>/dev/null;
if [ x$? = x0 ]; then
readparam="-e"
fi

ssh_params=

ssh_list ()
{
  for i in $(ls $sshdir) ; do
    echo $i
  done
}

ssh_updatefiles ()
{
  local name;
  local server;
  local user;
  local command;
  local desc;

  for i in $(ls $sshdir | grep ".ssh") ; do
    . $sshdir/$i

    echo "updating: $sshdir/$i"
    filename=$sshdir/$i
    echo "#CTAFCONF" >$filename
    echo "#ctssh" >>$filename
    echo "" >>$filename
    echo "server=\"$server\"" >>$filename
    echo "user=\"$user\"" >>$filename
    echo "command=\"$command\"" >>$filename
    echo "desc=\"$desc\"" >>$filename
  done
}

ssh_connect ()
{
  local server;
  local user;
  local command;
  local desc;

  echo $fname
  if [ -f $sshdir/"$fname".ssh ] ; then
	  . $sshdir/"$fname".ssh
	  echo "connection  : ssh $user@$server $command"
	  echo "description : $desc"
	  ssh $ssh_params $user@$server $command
  else
	  echo "can't find your ssh file in $sshdir"
  fi
}

ssh_add ()
{
    local name;
    local server;
    local user;
    local command;
    local desc;

    echo "adding a new ssh file (in ~/.ctafconf/ssh)"
    echo "Enter the name of the new ssh file"
    echo -n "name ?"
    read $readparam name
    if [ -f $name".ssh" ] ; then
	echo "This name already exist for one of your ssh files, Exiting"
	exit 1
    fi

    echo ""
    echo "Enter the server name"
    echo "localhost ssh.sourceforge.net ssh.epita.fr"
    echo -n "server ?"
    read $readparam server

    echo ""
    echo "Enter one username"
    echo -n "user ?"
    read $readparam user

    echo "If you want, you can specify one command."
    echo "eg: /bin/zsh , /usr/bin/screen , .."
    echo -n "Command ?"
    read $readparam command

    echo ""
    echo -n "Enter one description (avoid using \")?"
    read $readparam desc

    filename=$sshdir/"$name".ssh
    echo "#CTAFCONF" >$filename
    echo "#ctssh" >>$filename
    echo "" >>$filename
    echo "server=\"$server\"" >>$filename
    echo "user=\"$user\"" >>$filename
    echo "command=\"$command\"" >>$filename
    echo "desc=\"$desc\"" >>$filename
}

if [ x$# = x0 ] ||
    [ x$action = 'x-h' ] ||
   [ x$action = 'x--help' ] ; then
    echo "ct-ssh [option] <sshName>"
    echo "Actions possible: "
    echo " --help, -h, help"
    echo "    : display this help"
    echo " --list, -l, list"
    echo "    : list all repositoy"
    echo " --checkout, -c, co <reponame>"
    echo "    : checkout the repository in the current directory"
    echo " --add, -a, add"
    echo "    : add a new repository"
    echo " --update-files"
    echo "    : update all the file in ~/.ctafconf/ssh"
    echo " x, -x, -X : compressed X forwarding"
    exit 1
fi

if [ x$action = 'x--list' ] || [ x$action = xlist ] || [ x$action = 'x-l' ]; then
  ssh_list
  exit 0
fi
if [ x$action = 'xadd' ] || [ x$action = 'x--add' ] || [ x$action = 'x-a' ] ; then
  ssh_add
  exit 0
fi

if [ x$action = "x-X" ] || [ x$action = "x-x" ] || [ x$action = "xx" ] ; then
  ssh_params="-X -C"
  ssh_connect
  exit 0
fi

if [ x$action = 'x--update-files' ] ; then
  ssh_updatefiles
  exit 0
fi

fname=$1
ssh_connect
exit 0