51 branding regression for boot menu
[illumos-gate.git] / usr / src / tools / scripts / sccscp.sh
blobcccd5cc1c706beb16c18b211026b5e33f74452f1
1 #!/bin/sh
3 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
24 # Copyright 1993-1998, 2003 Sun Microsystems, Inc.
25 # All rights reserved.
26 # Use is subject to license terms.
28 #pragma ident "%Z%%M% %I% %E% SMI"
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.
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.
43 unset CDPATH
45 R_FLAG=0
46 G_FLAG=0
47 E_FLAG=0
49 usage()
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()
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.
64 getlast()
66 for arg in $*
69 done
70 echo "$arg"
71 } # getlast()
76 # copy_file(source, destination)
78 copy_file()
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"
88 # is the file currently checked out?
90 if [ "(" -f $p1 ")" -a "(" $E_FLAG -eq "0" ")" ]; then
91 echo "sccscp: $f1 currently checked out - not copied"
92 return
95 # Does the destination directory have an SCCS directory,
96 # if not we will create it!
98 if [ ! -d $d2/SCCS ]; then
99 mkdir $d2/SCCS
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
109 } # copy_file()
113 # copy_dir(source, destination)
115 copy_dir()
117 PWD=`pwd`
119 if [ -d $2 ]; then
120 destdir=$2/`basename $1`
121 else
122 destdir=$2
125 cd $1
127 find . -name "s.*" -print | grep '/SCCS/s\.' \
128 | while read sdot
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
140 if [ ! -d $d2 ]; then
141 mkdir -p $d2
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
151 done
153 cd $PWD
154 } # copy_dir()
156 if [ -f /usr/sccs/admin ]; then
157 ADMIN=/usr/sccs/admin
158 PRS=/usr/sccs/prs
159 else
160 ADMIN=/usr/ccs/bin/admin
161 PRS=/usr/ccs/bin/prs
166 # Parse options...
168 set -- `getopt edgr $*`
169 if [ $? != 0 ]; then
170 usage
171 exit 2
174 for i in $*
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
183 done
185 if [ $# -lt 2 ]; then
186 echo "sccscp: Insufficient arguments (${#})"
187 usage
188 exit 1
191 lastarg=`getlast $*`
193 if [ "(" $# -gt 2 ")" -a "(" ! -d $lastarg ")" ]; then
194 echo "sccscp: Target must be a directory"
195 usage
196 exit 1
199 while [ $# -gt 1 ]
201 if [ ! -r $1 ]; then
202 echo "sccscp: cannot access $1"
203 shift
204 continue
206 if [ -d $lastarg ]; then
207 dest=$lastarg/`basename $1`
208 else
209 dest=$lastarg
211 if [ -d $1 ]; then
212 if [ $R_FLAG -eq 0 ]; then
213 echo "sccscp: <$1> directory"
214 else
215 copy_dir $1 $dest
217 else
218 copy_file $1 $dest
220 shift
221 done