deleteP4User.sh #1

  • //
  • guest/
  • david_weintraub/
  • deleteP4User.sh
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#! /bin/ksh
# deleteP4User
########################################################################

########################################################################
# DELETE PERFORCE USER
#
# Programmed by David Weintraub
# Date: 13-Dec-2005
# Purpose: To Delete a Perforce User, their clients, and drop them from
#          their groups.
#
########################################################################

########################################################################
# CONSTANTS
#
tempFile="deleteUser.$$.temp"
p4LogFile="./p4UserLog.txt"
#
########################################################################

########################################################################
# GET USER ID
#
if [ "" = "$1" ]
then
    print -n "User's NBK ID? "
    read nbkId
else
    nbkId=$1
fi

#
#   ####Verify the Id
#

name=$(p4 users| sed -ne "/^$nbkId /s/^[^(]*(\([^)]*\).*/\1/p")
if ! [ "$name" ]
then
    print "User \"$nbkId\" does not exist"
    exit 2
fi

print -n "Do you want to delete the user \"$name\" ($nbkId)? "
typeset -uL1 answer 
read answer
if [ "Y" != "$answer" ]
then
    print "Not Deleting User $name. Aborting."
    print "Answer was \"$answer\""
    exit 0
fi
#
########################################################################

########################################################################
# LOG THE USER INTO THE P4 USER LOG
#
p4 edit $p4LogFile
print "$(date): Deleting P4 User $name ($nbkId) by user $(logname)" >> $p4LogFile
p4submit -d "Deleting user $name ($nbkId)"
#
########################################################################

########################################################################
# DELETE USER CLIENTS
#
print "Deleting $name's Perforce Client Views..."
for client in $(p4 clients | awk '$0 ~ /^Client '$nbkId'/ {print $2}')
do
    p4 client -fd $client
done
#
########################################################################

########################################################################
# DELETE USER FROM GROUPS
#
print "Deleting $name from all Perforce Groups..."
for group in $(p4 groups)
do
    print "    Deleting from Group $group"
    p4 group -o $group | grep -v "	$nbkId" > $tempFile
    p4 group -i < $tempFile
done
rm $tempFile
#
########################################################################

########################################################################
# DELETE USER ID
#
p4 user -df $nbkId
#
########################################################################

########################################################################
# DONE
#
print "User $nbkId ($name) Deleted from Perforce"
#
########################################################################
# Change User Description Committed
#1 5710 David Weintraub Initial Stuff for my depot