home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / etc / scvs < prev    next >
Text File  |  2001-05-10  |  6KB  |  193 lines

  1. #!/usr/bin/perl
  2. # Note : you may have to edit path to Perl above, according to your system setup
  3.  
  4. #
  5. # modified for ssh+chroot setup by Anton Berezin <tobez@plab.ku.dk> #
  6. # Synopsys : scvs -d :pserver:cvs@www.stlport.com/stlport <cvs command> # (this is for read-only anonymous access via "cvs" user)
  7. # Please use your cvs login name if you have one instead of "cvs" above, to be able to commit your changes 
  8. #
  9.  
  10.  
  11. #--
  12. #   tunable variables
  13. #--
  14.  
  15. # Set this if it does not work otherwise
  16. # $tune_cvs_server_name = "cvs.stlport.com";
  17.  
  18. # where cvs program is located on the client system
  19. $tune_local_cvs_cmd = "cvs";
  20.  
  21. # remote pserver port to use
  22. # for explanation, see
  23. #    http://www.prima.eu.org/tobez/cvs-howto.html#inetd
  24. $tune_remote_cvs_port = 2410;
  25.  
  26. # local pserver port;  you probably don't want to change this
  27. $tune_local_cvs_port = 2401;
  28.  
  29. # ssh command to use; the default is good for UNIX clients
  30. $tune_ssh_cmd = "ssh";
  31.  
  32. # the user on the server side cvs runs as
  33. $tune_ssh_user = "cvs";
  34.  
  35. #--
  36. #   end of tunable variables
  37. #   there is no need to modify anything below
  38. #--
  39.  
  40. #############################################################################
  41. # CVS settings
  42.  
  43. $CVS_CMD=$tune_local_cvs_cmd;
  44.  
  45. $CVS_PORT=$tune_remote_cvs_port;
  46. $CVS_LOCAL_PORT=$tune_local_cvs_port;
  47.  
  48. # the values below will be needed only if the repository is specified via the
  49. # command line or the CVSROOT environment variable, and in those cases they
  50. # will be extracted from there. However, for funny results you can uncomment
  51. # these two lines.
  52. # $CVS_HOST="www.stlport.com";
  53. # $CVS_USER="cvs";
  54.  
  55. #############################################################################
  56. # SSH settings
  57.  
  58. # ssh2 does not seem to work with our -L port:host:hostport argument, so make
  59. # sure we will use ssh1.
  60. $SSH_CMD=$tune_ssh_cmd;
  61.  
  62. # This should be the user on whose behalf the tunneling is made. It is
  63. # typically a user that cannot do any harm, has no password and uses a program
  64. # like nologin (but one that will wait) as a shell.
  65. $SSH_USER=$tune_ssh_user;
  66.  
  67. # This value should also automagically be set from the repository name.
  68. # However, if that host is not running sshd, you may want to tunnel through
  69. # another host and modify and uncomment the line below.
  70. # $SSH_HOST=$CVS_HOST
  71.  
  72. # This value is used if the repository cannot be determined from the
  73. # commandline or the CVSROOT variable. Modify this for your local situation.
  74. $SSH_DEFAULT_HOST=$tune_cvs_server_name;
  75.  
  76. # Port at which the sshd on the remote server runs. Default is 22.
  77. # $SSH_PORT=22;
  78.  
  79. # This should be left unmodified, as it makes no sense changing this. Unless
  80. # some future version (or perhaps even the current version) of cvs allow you
  81. # to specify the remote repository's port.
  82. $SSH_LOCAL_PORT=$CVS_LOCAL_PORT;
  83.  
  84.  
  85. #############################################################################
  86. # & parse_repository ({{rep}})
  87. # . extracts the method, user, host, port and directory from {{rep}}.
  88. # . There are four possibilities:
  89. #   - /path/to/repository
  90. #   - :method:/path/to/repository
  91. #   - :user@hostname:/path/to/repository
  92. #   - :method:user@hostname:/path/to/repository
  93. #   non-standard repositories. Has only been tested for :pserver: method.
  94. #
  95. sub parse_repository
  96. {
  97.   my $rep = $_[0];
  98.   my ($dir,$user,$host,$method);
  99.  
  100.   # determine the directory
  101.   $rep =~ s/:(\/.*)$// && do { $dir=$1; };
  102.   if (not $dir)
  103.     { $rep =~ s/(\/.*)$// && do {$dir = $1; }; }
  104.  
  105.   # determine the hostname and the username
  106.   $rep =~ s/:([^:]*)@(.*)$// && do { $user = $1; $host = $2; };
  107.   if (not $host)
  108.     { $rep =~ s/:([^:]+)$// && do { $host = $1; }; }
  109.  
  110.   # all that is left now is the method
  111.   $rep =~ s/^:([^:]*)// && do { $method = $1; };
  112.  
  113.   # if there is still anything left, we have an error, warn the user
  114.   if ($rep)
  115.     { print STDERR "Warning: repository parsed wrong ('$rep' ignored).\n"; }
  116.  
  117. #  print STDERR "DEBUG: dir=$dir, user=$user, host=$host, method=$method\n";
  118.   return ($method, $user, $host, $dir);
  119. }
  120.  
  121.  
  122. #############################################################################
  123. # main
  124.  
  125. # should be changed to a general cmdline parsing routine.
  126. # get the repository's name from the commandline or the CVSROOT environment
  127. # variable.
  128. if ($ARGV[0] eq "-d")
  129. {
  130.   $rep="$ARGV[1]";
  131.   shift; shift;
  132. }
  133. else
  134. {
  135.   $rep = $ENV{'CVSROOT'};
  136. }
  137.  
  138. # print STDERR "DEBUG: rep = $rep\n";
  139.  
  140. # parse the repository
  141. ($method, $user, $host, $dir) = parse_repository $rep;
  142. # print "met: $method, user: $user, host: $host, dir: $dir\n";
  143.  
  144. # construct the local fake cvs server name.
  145. if ($method) { $cvs_serv = ":$method:"; }
  146. if ($user)   { $cvs_serv .= "$user\@"; }
  147. if ($rep)    { $cvs_serv .= "localhost:"; }
  148. if ($dir)    { $cvs_serv .= $dir; }
  149.  
  150. # print STDERR "DEBUG: cvs_serv = $cvs_serv\n";
  151.  
  152. # construct the tunneling command
  153. $SSH_HOST |= $host;
  154. # print STDERR "DEBUG: SSH_HOST=$SSH_HOST\n";
  155. $SSH_HOST |= $SSH_DEFAULT_HOST;
  156. # print STDERR "DEBUG: SSH_HOST=$SSH_HOST\n";
  157.  
  158. if ($SSH_USER)
  159.   { $ssh_serv="$SSH_USER\@$SSH_HOST"; }
  160. else
  161.   { $ssh_serv="$SSH_HOST"; }
  162.  
  163. # print "ssh_serv: $ssh_serv\n";
  164.  
  165. $tunnel_cmd = "$SSH_CMD $ssh_serv -x -f"
  166.             . ( ($SSH_PORT) ? " -p $(SSH_PORT)" : "" )
  167.             . " -L $SSH_LOCAL_PORT:$SSH_HOST:$CVS_PORT open";
  168.  
  169. # print STDERR "DEBUG: tunnel_cmd: $tunnel_cmd\n";
  170.  
  171. # execute the tunneling, and read the response from the server
  172. open (TUNNELSH,"$tunnel_cmd |") or die "Could not execute $tunnel_cmd!";
  173. chomp ($magicword = <TUNNELSH>);
  174. # print STDERR "DEBUG: magicword = $magicword!\n";
  175.  
  176. # Now we can call system to execute the cvs command.
  177.   # print STDERR "Doing: $CVS_CMD|", ( ($cvs_serv) ? ('-d |', "$cvs_serv|") : ( ) ) , "@ARGV", "|\n";
  178. $exitcode =
  179.   system "$CVS_CMD", ( ($cvs_serv) ? ('-d', $cvs_serv) : () ) , @ARGV;
  180.  
  181. if ($exitcode) { print STDERR "Could not execute CVS command!\n"; }
  182.  
  183. # close the tunnel
  184. #print STDERR "DEBUG: ", ( "$SSH_CMD $ssh_serv -q -x -f"
  185. #            . ( ($SSH_PORT) ? " -p $SSH_PORT" : "" )
  186. #            . " $magicword" );
  187. # print STDERR "before close\n";
  188. system ( "$SSH_CMD $ssh_serv -q -x -f"
  189.             . ( ($SSH_PORT) ? " -p $SSH_PORT" : "" )
  190.             . " $magicword" );
  191.  
  192. # print STDERR "right after close\n";
  193.