1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#!/bin/sh
# Copyright (c) 2000
# Tanaka Akira. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
###
# CVSconnect enables you to do multiple CVS operations on single network
# connection. CVSconnect sets up special environment using
# $CVSRSH/$CVSROOT for the command line CVS client. In the environment,
# the command line CVS client reuses a network connection.
# CVSconnect is especially designed to use with CVSsuck. And CVSconnect
# (or similar) will be integrated to a future version of CVSsuck.
# However, it is planned that CVSsuck directly connects to a cvs server
# without cvs command.
# Usage: cvsconnect cvsroot [command-to-run...]
#
# If command-to-run is not provided, cvsconnect runs shell with some
# diagnostic messages. Then you can run cvs.
# Example:
# cvsconnect $HOME/.cvsroot
# Limitation:
# * The global option -z for compression cannot be used.
# If you use SSH via ext method, you can use compression by SSH instead.
#
# * CVS client must be run at a time. Running two or more clients at a
# same time will make a trouble. (will be fixed in future release.)
#
# * Some static variables in a CVS server may confuse you.
# It's a CVS bug. Report it to CVS developper :-).
#
# * command line CVS client must request `Root' first.
# Don't mind. There is no implementation which violates this
# assumption, however I know. At least, CVS-1.10 and CVS-1.11 should
# work.
# Notes:
# * When CVS command is failed, CVSconnect automatically re-run the
# command with reconnected connection when CVS command is failed.
# Especially the failure is caused by a long running CVS-1.10 server.
# Since CVS-1.10 doesn't close some file descriptors, a long running CVS
# server will exceed a limit of file descriptors.
#
# * /bin/sh should be POSIX sh because this script uses
# ${parameter#pattern}, etc. If your /bin/sh is ancient Bourne shell,
# use ksh or bash.
prefix=/usr/share/cvsconnect/
cvs_client=${prefix}cvs-client
cvsconnect_client=${prefix}cvsconnect-client
cvsroot="${1?no cvsroot}"
shift
CVSCONNECT_BASE=${TMPDIR:-/tmp}/cvsconnect-$$
CVSCONNECT_CONNECTION=default
export CVSCONNECT_BASE CVSCONNECT_CONNECTION
mkdir $CVSCONNECT_BASE $CVSCONNECT_BASE/bin || exit 1
cat <<End > $CVSCONNECT_BASE/_connect
#!/bin/sh
PATH="$PATH"
CVS_RSH='${CVS_RSH:-rsh}'
export PATH CVS_RSH
exec $cvs_client -r $cvsroot
End
chmod 755 $CVSCONNECT_BASE/_connect
cat <<End > $CVSCONNECT_BASE/_disconnect
#!/bin/sh
PATH="$PATH"
export PATH
for connection in "\$@"
do
for f in $CVSCONNECT_BASE/\$connection.*.pid
do
pid=\`cat \$f 2>/dev/null\` && rm \$f 2>/dev/null && kill \$pid
done
done
rm $CVSCONNECT_BASE/\$connection.*
End
chmod 755 $CVSCONNECT_BASE/_disconnect
CVSCONNECT_CVS="`which cvs`"
export CVSCONNECT_CVS
cat <<End > $CVSCONNECT_BASE/bin/cvs
#!/bin/sh
PATH="$PATH"
export PATH
if $CVSCONNECT_CVS "\$@" >$CVSCONNECT_BASE/\$\$.stdout 2>$CVSCONNECT_BASE/\$\$.stderr
then
cat $CVSCONNECT_BASE/\$\$.stdout
cat $CVSCONNECT_BASE/\$\$.stderr >&2
rm $CVSCONNECT_BASE/\$\$.stdout $CVSCONNECT_BASE/\$\$.stderr
exit 0
else
#rm $CVSCONNECT_BASE/\$\$.stdout $CVSCONNECT_BASE/\$\$.stderr
$CVSCONNECT_BASE/_disconnect \${CVSCONNECT_CONNECTION:-default}
$CVSCONNECT_CVS "\$@"
exit \$?
fi
End
chmod 755 $CVSCONNECT_BASE/bin/cvs
root="`${cvs_client} -p $cvsroot`"
CVS_RSH="${cvsconnect_client}"
CVSROOT=":ext:dummy@dummy.invalid:$root"
export CVS_RSH CVSROOT
echo "CVSCONNECT_BASE=$CVSCONNECT_BASE"
echo "CVSCONNECT_CONNECTION=$CVSCONNECT_CONNECTION"
echo "CVS_RSH=$CVS_RSH"
echo "CVSROOT=$CVSROOT"
PATH=$CVSCONNECT_BASE/bin:$PATH "${@-${SHELL:-/bin/sh}}"
status=$?
for f in $CVSCONNECT_BASE/*.pid
do
pid=`cat $f 2>/dev/null` && rm $f 2>/dev/null && kill $pid
done
rm -rf $CVSCONNECT_BASE
exit $status
|