xref: /onnv-gate/usr/src/tools/scripts/sccsrm.sh (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/sh
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# CDDL HEADER START
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*0Sstevel@tonic-gate# with the License.
9*0Sstevel@tonic-gate#
10*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*0Sstevel@tonic-gate# See the License for the specific language governing permissions
13*0Sstevel@tonic-gate# and limitations under the License.
14*0Sstevel@tonic-gate#
15*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*0Sstevel@tonic-gate#
21*0Sstevel@tonic-gate# CDDL HEADER END
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate#
24*0Sstevel@tonic-gate# Copyright (c) 1993-1998 by Sun Microsystems, Inc.
25*0Sstevel@tonic-gate# All rights reserved.
26*0Sstevel@tonic-gate#
27*0Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate#
29*0Sstevel@tonic-gate#	This script is to be used to remove files from any CodeManager
30*0Sstevel@tonic-gate#	workspace.  It will do this by moving the specified file,
31*0Sstevel@tonic-gate#	and its corresponding s-dot file, to a .del-<file>-`date`
32*0Sstevel@tonic-gate# 	format.
33*0Sstevel@tonic-gate#
34*0Sstevel@tonic-gate#	The only way to remove files under the CodeManager is
35*0Sstevel@tonic-gate#	through the rename mechanism - it is not enough to
36*0Sstevel@tonic-gate#	simply 'rm' the file.
37*0Sstevel@tonic-gate#
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gateUSAGE="usage: sccsrm [-f] <filename> ..."
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gatemessage() {
42*0Sstevel@tonic-gate   if [ ${F_FLAG} -eq 0 ]; then
43*0Sstevel@tonic-gate      echo "$*"
44*0Sstevel@tonic-gate   fi
45*0Sstevel@tonic-gate}
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate#
48*0Sstevel@tonic-gate# LC_ALL=C is set so that the this script will work no matter
49*0Sstevel@tonic-gate# which localization you have installed on your machine.  Some
50*0Sstevel@tonic-gate# localizations can cause the output of 'date' and other commands
51*0Sstevel@tonic-gate# to vary.
52*0Sstevel@tonic-gate#
53*0Sstevel@tonic-gateLC_ALL="C"; export LC_ALL
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gatedate=`/usr/bin/date +%h-%d-%y`
56*0Sstevel@tonic-gateF_FLAG=0
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate#
60*0Sstevel@tonic-gate# Parse options...
61*0Sstevel@tonic-gate#
62*0Sstevel@tonic-gateset -- `getopt f $*`
63*0Sstevel@tonic-gateif [ $? != 0 ]; then
64*0Sstevel@tonic-gate   echo $USAGE
65*0Sstevel@tonic-gate   exit 2
66*0Sstevel@tonic-gatefi
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gatefor i in $*
70*0Sstevel@tonic-gatedo
71*0Sstevel@tonic-gate   case $i in
72*0Sstevel@tonic-gate   -f) F_FLAG=1; shift;;
73*0Sstevel@tonic-gate   --) shift; break;;
74*0Sstevel@tonic-gate   esac
75*0Sstevel@tonic-gatedone
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gateif [ $# -eq 0 ]; then
78*0Sstevel@tonic-gate   message $USAGE
79*0Sstevel@tonic-gate   exit 1
80*0Sstevel@tonic-gatefi
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate#
83*0Sstevel@tonic-gate# Process s-dot files.
84*0Sstevel@tonic-gate#
85*0Sstevel@tonic-gatefor file in $*
86*0Sstevel@tonic-gatedo
87*0Sstevel@tonic-gate   new_file="${file}-${date}"
88*0Sstevel@tonic-gate   #
89*0Sstevel@tonic-gate   # if there is a deleted file of the same name we then append the pid
90*0Sstevel@tonic-gate   # to the name.
91*0Sstevel@tonic-gate   if [ -f SCCS/s..del-${new_file} -o -d .del-${new_file} ]; then
92*0Sstevel@tonic-gate      new_file="${new_file}.$$"
93*0Sstevel@tonic-gate   fi
94*0Sstevel@tonic-gate   if [ -f SCCS/s.$file ]; then
95*0Sstevel@tonic-gate      if [ -f SCCS/p.${file} ]; then
96*0Sstevel@tonic-gate         if [ ${F_FLAG} -eq 0 ]; then
97*0Sstevel@tonic-gate	    echo "warning: ${file} is checked out for editing, all edits will be lost - continue (y/n)"
98*0Sstevel@tonic-gate	    read ans
99*0Sstevel@tonic-gate	    while [ `expr $ans : "^[YyNn]"` -eq 0 ]
100*0Sstevel@tonic-gate	    do
101*0Sstevel@tonic-gate	       echo "warning: ${file} is checked out for editing, all edits will be lost - continue (y/n)"
102*0Sstevel@tonic-gate	       read ans
103*0Sstevel@tonic-gate	    done
104*0Sstevel@tonic-gate	 else
105*0Sstevel@tonic-gate	    ans="y"
106*0Sstevel@tonic-gate	 fi
107*0Sstevel@tonic-gate	 if [ `expr $ans : "^[Yy]"` -eq 1 ]; then
108*0Sstevel@tonic-gate            rm -f SCCS/p.${file}
109*0Sstevel@tonic-gate	    rm -f ${file}
110*0Sstevel@tonic-gate	 else
111*0Sstevel@tonic-gate	    continue
112*0Sstevel@tonic-gate	 fi
113*0Sstevel@tonic-gate      fi
114*0Sstevel@tonic-gate      if [ -f ${file} ]; then
115*0Sstevel@tonic-gate         mv ${file} .del-${new_file}
116*0Sstevel@tonic-gate      fi
117*0Sstevel@tonic-gate      mv SCCS/s.${file} SCCS/s..del-${new_file}
118*0Sstevel@tonic-gate   elif [ -d ${file} -a ${file} != "SCCS" ]; then
119*0Sstevel@tonic-gate      mv ${file} .del-${new_file}
120*0Sstevel@tonic-gate   else
121*0Sstevel@tonic-gate      message "${file}: not an SCCS file"
122*0Sstevel@tonic-gate   fi
123*0Sstevel@tonic-gatedone
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate
127