tools/proxy_cvs.sh
changeset 5569 c3326e2b8b45
parent 5567 1d593061210b
child 5570 0b0946d94dd3
equal deleted inserted replaced
5567:1d593061210b 5569:c3326e2b8b45
     1 #!/bin/sh
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 # Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
       
    23 #
       
    24 
       
    25 # proxy_cvs.sh 
       
    26 # script tunnels cvs+ssh through http proxy outside of ORAWAN.  It's easy to
       
    27 # tell cvs to use ssh instead of rsh, just set 'CVS_RSH=ssh'. It's lot harder
       
    28 # to tell ssh running on cvs behalf to use http proxy. So our approach is to
       
    29 # create temp script, which executes ssh with all proxy parameters to set up
       
    30 # HTTP tunnel for ssh session.
       
    31 #
       
    32 # If `http_proxy` variable is not set the script uses a default proxy,
       
    33 # which is 'emeacache.uk.oracle.com:80'.
       
    34 #
       
    35 # All arguments, which appear on command line are passed to cvs(1) command with
       
    36 # out any modification.
       
    37 #
       
    38 # Example:
       
    39 # To check out pflogd sources from OpenBSD repository to local pflogd.src
       
    40 # directory one invokes proxy_cvs.sh like that:
       
    41 #
       
    42 #	proxy_cvs.sh -qd [email protected]:/cvs	\
       
    43 #		-d pflogd.src src/sbin/pflogd
       
    44 #
       
    45 # To check a particular version of pflogd sources, one has to use a
       
    46 # corresponding CVS version tag assigned by upstream developers. Command below
       
    47 # retrieves pflogd source code released by OpenBSD 5.4:
       
    48 #
       
    49 #	proxy_cvs.sh -qd [email protected]:/cvs	\
       
    50 #		-rOPENBSD_5_4 -d pflogd.src src/sbin/pflogd
       
    51 #
       
    52 
       
    53 #
       
    54 # crate_ssh_wrapper
       
    55 # function creates a shell script, which a netcat(1) as proxy to tunnel
       
    56 # ssh via http proxy.
       
    57 #
       
    58 # Arguments:
       
    59 #	file name where to dump script, function makes file executable.
       
    60 #
       
    61 function create_ssh_wraper
       
    62 {
       
    63 	if [ -z "$http_proxy" ] ; then
       
    64 		HTTP_PROXY='emeacache.uk.oracle.com:80'
       
    65 	else
       
    66 		HTTP_PROXY=$http_proxy
       
    67 	fi
       
    68 	echo '#!/bin/sh\n' > $1
       
    69 	echo 'ssh -oProxyCommand='"'/usr/bin/nc -X connect -x $HTTP_PROXY %h %p'"\
       
    70 	    '-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null $*' >> $1
       
    71 	chmod +x $1
       
    72 }
       
    73 
       
    74 #
       
    75 # This is a workaround. I don't know how to pass all arguments required by
       
    76 # 'ssh/http' proxy into CVS_RSH environment variable. So my solution is to
       
    77 # dump desired arguments into a temporary shell script and point CVS_RSH
       
    78 # variable to it.
       
    79 #
       
    80 function init_cvs_rsh
       
    81 {
       
    82 	export TMPF=`mktemp`
       
    83 	create_ssh_wraper $TMPF;
       
    84 	CVS_RSH=$TMPF
       
    85 	export CVS_RSH
       
    86 }
       
    87 
       
    88 init_cvs_rsh
       
    89 
       
    90 trap "rm -f $TMPF" EXIT
       
    91 
       
    92 cvs $*
       
    93 
       
    94 RETURN=$?
       
    95 
       
    96 exit $RETURN