#!/bin/bash
# Set the password for the specified user in perforce
INSTANCE=${1:-Unset}
USER=${2:-Unset}
PASSWD=${3:-Unset}
TYPE=${4:-standard}
function bail() { echo -e "${1:-Unknown Error}\n" >&2; exit ${2:-1}; }
if [[ "$INSTANCE" == "Unset" ]] || [[ "$USER" == "Unset" ]] || [[ "$PASSWD" == "Unset" ]]; then
bail "Arguments are required."
fi
source /p4/common/bin/p4_vars $INSTANCE
P4="/usr/local/bin/p4"
$P4 --field "Type=$TYPE" --field "AuthMethod=perforce" user -f -o $USER | $P4 user -f -i
result=$(echo "$PASSWD,$PASSWD" | tr ',' '\n' | $P4 passwd $USER 2>&1)
if [[ $result =~ "invalid or unset" ]]; then
exit 0
fi