xref: /onnv-gate/usr/src/tools/scripts/sccsrm.sh (revision 0:68f95e015346)
1#!/usr/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 (c) 1993-1998 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28#
29#	This script is to be used to remove files from any CodeManager
30#	workspace.  It will do this by moving the specified file,
31#	and its corresponding s-dot file, to a .del-<file>-`date`
32# 	format.
33#
34#	The only way to remove files under the CodeManager is
35#	through the rename mechanism - it is not enough to
36#	simply 'rm' the file.
37#
38
39USAGE="usage: sccsrm [-f] <filename> ..."
40
41message() {
42   if [ ${F_FLAG} -eq 0 ]; then
43      echo "$*"
44   fi
45}
46
47#
48# LC_ALL=C is set so that the this script will work no matter
49# which localization you have installed on your machine.  Some
50# localizations can cause the output of 'date' and other commands
51# to vary.
52#
53LC_ALL="C"; export LC_ALL
54
55date=`/usr/bin/date +%h-%d-%y`
56F_FLAG=0
57
58
59#
60# Parse options...
61#
62set -- `getopt f $*`
63if [ $? != 0 ]; then
64   echo $USAGE
65   exit 2
66fi
67
68
69for i in $*
70do
71   case $i in
72   -f) F_FLAG=1; shift;;
73   --) shift; break;;
74   esac
75done
76
77if [ $# -eq 0 ]; then
78   message $USAGE
79   exit 1
80fi
81
82#
83# Process s-dot files.
84#
85for file in $*
86do
87   new_file="${file}-${date}"
88   #
89   # if there is a deleted file of the same name we then append the pid
90   # to the name.
91   if [ -f SCCS/s..del-${new_file} -o -d .del-${new_file} ]; then
92      new_file="${new_file}.$$"
93   fi
94   if [ -f SCCS/s.$file ]; then
95      if [ -f SCCS/p.${file} ]; then
96         if [ ${F_FLAG} -eq 0 ]; then
97	    echo "warning: ${file} is checked out for editing, all edits will be lost - continue (y/n)"
98	    read ans
99	    while [ `expr $ans : "^[YyNn]"` -eq 0 ]
100	    do
101	       echo "warning: ${file} is checked out for editing, all edits will be lost - continue (y/n)"
102	       read ans
103	    done
104	 else
105	    ans="y"
106	 fi
107	 if [ `expr $ans : "^[Yy]"` -eq 1 ]; then
108            rm -f SCCS/p.${file}
109	    rm -f ${file}
110	 else
111	    continue
112	 fi
113      fi
114      if [ -f ${file} ]; then
115         mv ${file} .del-${new_file}
116      fi
117      mv SCCS/s.${file} SCCS/s..del-${new_file}
118   elif [ -d ${file} -a ${file} != "SCCS" ]; then
119      mv ${file} .del-${new_file}
120   else
121      message "${file}: not an SCCS file"
122   fi
123done
124
125
126
127