xref: /onnv-gate/usr/src/tools/scripts/sccscp.sh (revision 0:68f95e015346)
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 1993-1998, 2003 Sun Microsystems, Inc.
25# All rights reserved.
26# Use is subject to license terms.
27#
28#pragma ident	"%Z%%M%	%I%	%E% SMI"
29#
30#	This script is to be used to copy SCCS files and SCCS
31#	directory structures within a CodeManager workspace
32#	You specify the 'clear file' or directory to sccscp, it
33#	will duplicate the coresponding s-dot file(s),
34#	and do an SCCS GET operation on the newly
35#	created s-dot file.
36#
37#
38
39#
40# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
41# under certain circumstances, which can really screw things up; unset it.
42#
43unset CDPATH
44
45R_FLAG=0
46G_FLAG=0
47E_FLAG=0
48
49usage()
50{
51	echo "usage:	sccscp [-r] filename1 [ filename2...] target"
52	echo "	-r copy a directory and all of its files"
53	echo "	-g copy the sdot file, but do not sccs-get it"
54	echo "	-e copy most recent delta if file is currently checked out."
55	echo "	-d debug mode"
56} #usage()
57
58
59#
60# function to return that last arguement passed to it.
61# I use this in place of array indexing - which shell
62# does not do well.
63#
64getlast()
65{
66	for arg in $*
67	do
68	:
69	done
70	echo "$arg"
71} # getlast()
72
73
74
75#
76# copy_file(source, destination)
77#
78copy_file()
79{
80	f1=`basename $1`
81	d1=`dirname $1`
82	s1="$d1/SCCS/s.$f1"
83	p1="$d1/SCCS/p.$f1"
84	f2=`basename $2`
85	d2=`dirname $2`
86	s2="$d2/SCCS/s.$f2"
87	#
88	# is the file currently checked out?
89	#
90	if [ "(" -f $p1 ")" -a "(" $E_FLAG -eq "0" ")" ]; then
91		echo "sccscp: $f1 currently checked out - not copied"
92		return
93	fi
94	#
95	# Does the destination directory have an SCCS directory,
96	# if not we will create it!
97	#
98	if [ ! -d $d2/SCCS ]; then
99		mkdir $d2/SCCS
100	fi
101	cp $s1 $s2
102	if [ $G_FLAG -eq "0" ]; then
103		PWD=`pwd`
104		cd $d2
105	   	echo "sccs get $d2/$f2"
106 	   	sccs get $f2
107		cd $PWD
108	fi
109} # copy_file()
110
111
112#
113# copy_dir(source, destination)
114#
115copy_dir()
116{
117	PWD=`pwd`
118
119	if [ -d $2 ]; then
120		destdir=$2/`basename $1`
121	else
122		destdir=$2
123	fi
124
125	cd $1
126
127	find . -name "s.*" -print | grep '/SCCS/s\.' \
128	| while read sdot
129	do
130		sdot=`echo $sdot | sed -e "s/^\.\///"`
131		d2=$PWD/$destdir/`dirname $sdot`
132		f2=`basename $sdot | sed -e "s/^s\.//" `
133		if [ "(" -f $PWD/$1/`dirname $sdot`/p.$f2 ")" -a \
134		     "(" $E_FLAG -eq "0" ")" ]; then
135			d1=`basename $sdot`
136			d1=`basename $d1`
137			echo "sccscp: $d1/$f2 currently checked out - not copied"
138			continue
139		fi
140		if [ ! -d $d2 ]; then
141			mkdir -p $d2
142		fi
143		cp $PWD/$1/$sdot $PWD/$destdir/$sdot
144		if [ $G_FLAG -eq "0" ]; then
145			dir=`dirname $destdir/$sdot`
146			dir=`dirname $dir`
147			cd $PWD/$dir
148			echo "sccs get $dir/$f2"
149			sccs get $f2
150		fi
151	done
152
153	cd $PWD
154} # copy_dir()
155
156if [ -f /usr/sccs/admin ]; then
157	ADMIN=/usr/sccs/admin
158	PRS=/usr/sccs/prs
159else
160	ADMIN=/usr/ccs/bin/admin
161	PRS=/usr/ccs/bin/prs
162fi
163
164
165#
166# Parse options...
167#
168set -- `getopt edgr $*`
169if [ $? != 0 ]; then
170	usage
171	exit 2
172fi
173
174for i in $*
175do
176	case $i in
177	-r) R_FLAG=1; shift;;
178	-d) set -x; shift;;
179	-g) G_FLAG=1; shift;;
180	-e) E_FLAG=1; shift;;
181	--) shift; break;;
182	esac
183done
184
185if [ $# -lt 2 ]; then
186	echo "sccscp: Insufficient arguments (${#})"
187	usage
188	exit 1
189fi
190
191lastarg=`getlast $*`
192
193if [ "(" $# -gt 2 ")" -a "(" ! -d $lastarg ")" ]; then
194	echo "sccscp: Target must be a directory"
195	usage
196	exit 1
197fi
198
199while [ $# -gt 1 ]
200do
201	if [ ! -r $1 ]; then
202		echo "sccscp: cannot access $1"
203		shift
204		continue
205	fi
206	if [ -d $lastarg ]; then
207		dest=$lastarg/`basename $1`
208	else
209		dest=$lastarg
210	fi
211	if [ -d $1 ]; then
212		if [ $R_FLAG -eq 0 ]; then
213			echo "sccscp: <$1> directory"
214		else
215			copy_dir $1 $dest
216		fi
217	else
218		copy_file $1 $dest
219	fi
220	shift
221done
222
223