noTypeChange.sh #3

  • //
  • guest/
  • amo/
  • scripts/
  • triggers/
  • noTypeChange.sh
  • View
  • Commits
  • Open Download .zip Download (1 KB)
#!/bin/bash
# ==========
# $File: //guest/amo/scripts/triggers/noTypeChange.sh $
# $Revision: #3 $
# $Change: 26331 $
#
# $Author: amo $
# $DateTimeTZ: 2020/02/19 09:57:16 -0800 PST $
# ----------
# PURPOSE: 
# Bash script called from pre-command trigger, firing when 'p4 add/edit/reopen' is run.
# This checks the arguments passed to the command ('argsQuoted' trigger script variable), checking for the flag that allows a type change ('-t'). 
# If found, the command is rejected with a sensible warning message. 
# 
# Example trigger entry:
# notypechange command pre-user-(add|edit|reopen) "%//scripts/triggers/noTypeChange.sh% %user% %client% %serverid% %command% %argsQuoted%"
#
# ----------
# Next steps:
# - enhance the trigger - more control/error-handling/logging?
# - find a use for (or simply remove) 'user', 'client', 'server'; at present, only command and argsQuoted are used.

user=$1
client=$2
server=$3
cmd=$4
argsQuoted=$5

echo $argsQuoted | grep -e "-t" > /dev/null;
out=$?

if [ $out = 0 ]; then
	echo Use of '-t' flag with $cmd is disallowed. 
	exit 1;
fi

exit 0
# Change User Description Committed
#3 26331 Adam Morriss keyword and executable
#2 26330 Adam Morriss Switching to executable file
#1 25125 Adam Morriss Small command-trigger script to block '-t' on add/edit/reopen.

Includes suggested trigger definition, and a header to explain the purpose.