#!/bin/bash #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE #------------------------------------------------------------------------------ set -u # p4login generates a login ticket for the SDP super user. It is called # from cron scripts, and so does not normally generate output to stdout or # stderr. # # Normally output (stdout and stderr) is logged in $LOGS/p4login.log, # unless unless SDP_INSTANCE isn't defined, in which case it bails # immediately. # # An exit code of 0 indicates a valid login ticket exists, while a # non-zero exit code indicates a failure to login. export SDP_INSTANCE=${SDP_INSTANCE:-Undefined} export SDP_INSTANCE=${1:-$SDP_INSTANCE} if [[ $SDP_INSTANCE == Undefined ]]; then echo "Instance parameter not supplied." echo "You must supply the Perforce instance as a parameter to this script." exit 1 fi . /p4/common/bin/p4_vars $SDP_INSTANCE declare -i SDP_ALWAYS_LOGIN=${SDP_ALWAYS_LOGIN:-1} declare DateFormat='%a %Y-%m-%d %H:%M:%S %Z' declare Cmd= function bail () { echo -e "\nError: ${1:-Unknown Error}"; exit ${2:-1}; } [[ $SDP_INSTANCE == Undefined ]] && bail "Error: SDP_INSTANCE not defined." declare TicketExpiration=$($P4BIN -ztag -F %TicketExpiration% -p $P4PORT -u $P4USER login -s 2>/dev/null) declare Log=$LOGS/p4login.log echo "$(date +'%a %Y-%m-%d %H:%M:%S %Z'): Checking login status." > $Log if [[ $TicketExpiration =~ [0-9]+ ]]; then # A 'long-term' ticket is one that expires more than a month (31 days + 1 second) from now. if [[ $TicketExpiration -ge 2678401 ]]; then echo "$(date +'%a %Y-%m-%d %H:%M:%S %Z'): Verified: User $P4USER logged into $P4PORT with a long-term ticket. Login not required." >> $Log if [[ $SDP_ALWAYS_LOGIN -eq 1 ]]; then echo "Doing login anyway as SDP_ALWAYS_LOGIN is enabled." >> $Log Cmd="$P4BIN -p $P4PORT -u $P4USER -s login -a" echo Running: $Cmd >> $Log $Cmd < /p4/common/bin/adminpass >> $Log 2>&1 fi exit 0 else echo "$(date +'%a %Y-%m-%d %H:%M:%S %Z'): Warning: User $P4USER logged into $P4PORT with a short-term ticket. Attempting to extend." >> $Log Cmd="$P4BIN -p $P4PORT -u $P4USER -s login -a" echo Running: $Cmd >> $Log $Cmd < /p4/common/bin/adminpass >> $Log 2>&1 exit $? fi else echo "$(date +'%a %Y-%m-%d %H:%M:%S %Z'): Warning: User $P4USER is not logged into $P4PORT. Attempting to login." >> $Log Cmd="$P4BIN -p $P4PORT -u $P4USER -s login -a" echo Running: $Cmd >> $Log $Cmd < /p4/common/bin/adminpass >> $Log 2>&1 exit $? fi
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19278 | trina | "Forking branch Main of perforce-software-sdp to trina-sdp." | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/bin/p4login | |||||
#7 | 18530 | Russell C. Jackson (Rusty) | Update main from dev. | ||
#6 | 15865 | Russell C. Jackson (Rusty) | Removed space between $ and Log | ||
#5 | 15856 | C. Thomas Tyler |
Replaced the big license comment block with a shortened form referencing the LICENSE file included with the SDP package, and also by the URL for the license file in The Workshop. |
||
#4 | 15609 | C. Thomas Tyler | Pushing SDP 2015.1.15607 (2015/09/02). | ||
#3 | 13908 | C. Thomas Tyler | Pushing SDP 2015.1.13906. | ||
#2 | 12171 | Russell C. Jackson (Rusty) | Merge in changes to remove the need for p4master_run. | ||
#1 | 10148 | C. Thomas Tyler | Promoted the Perforce Server Deployment Package to The Workshop. |