- #!/bin/sh
- ############################################################ IDENT(1)
- #
- # $Title: Script to check status of p4 pull for local p4d $
- #
- ############################################################ CONFIGURATION
- #
- # User to perform verify as
- #
- P4D_USER= # overide with -u user
- #
- # Local perforce server settings
- # NB: Taken from rc.conf(5) on FreeBSD
- #
- P4D_PORT=$( sysrc -n p4d_port 2> /dev/null ) # override with -p port
- ############################################################ GLOBALS
- pgm="${0##*/}" # Program basename
- #
- # Global exit status
- #
- SUCCESS=0
- FAILURE=1
- #
- # Command-line options
- #
- VERBOSE= # -v
- ############################################################ FUNCTIONS
- die()
- {
- local fmt="$1"
- exec >&2
- if [ "$fmt" ]; then
- shift 1 # fmt
- printf "$fmt\n" "$@"
- fi
- exit $FAILURE
- }
- usage()
- {
- exec >&2
- local optfmt="\t%-8s %s\n"
- printf "Usage: %s [-p port] [-u user] [-v]\n" "$pgm"
- printf "OPTIONS:\n"
- printf "$optfmt" "-p port" "Server port (default local system's p4d)."
- printf "$optfmt" "-u user" "Perform verify as user (default $P4D_USER)."
- printf "$optfmt" "-v" "Verbose. Show individual pull transfers."
- exit $FAILURE
- }
- ############################################################ MAIN
- #
- # Command-line options
- #
- while getopts p:u:v flag; do
- case "$flag" in
- p) P4D_PORT="$OPTARG" ;;
- u) P4D_USER="$OPTARG" ;;
- v) VERBOSE=1 ;;
- *) usage
- esac
- done
- shift $(( $OPTIND - 1 ))
- #
- # Make sure we have HOST:PORT for the local p4d
- #
- if [ "$P4D_PORT" ]; then
- : good to go # I.e., FreeBSD (see rc.conf(5)) or `-p port' given
- elif [ "$UNAME_s" = "FreeBSD" ]; then
- : skip below # rc.conf(5) drives the setting
- elif [ -f "/etc/init.d/p4d" ]; then # I.e., Linux
- eval "$( { exec >&- 2>&-
- eval "$( awk 'gsub(/exit/,":")||1' /etc/init.d/p4d )"
- if [ "$p4d_port_interface" -a ! "$p4d_port" ]; then
- p4d_port=$( ifconfig "$p4d_port_interface" | awk '
- sub(/inet addr:/, "") { print addr = $1; exit}
- END { exit !addr }
- ' ) && p4d_port="$p4d_port:1666"
- fi
- echo "P4D_PORT=${p4d_port%%[!0-9a-zA-Z.\[\]:-]}" >&3
- } 3>&1 )"
- else # I.e., Other Linux
- export SUDO_PROMPT="[sudo] Password:"
- P4D_PORT=$( sudo lsof -nPi 4:1666 -a -c p4d | awk '
- sub(/\(LISTEN\)$/, "") { print p4d_port = $NF }
- END { exit !p4d_port }
- ' ) || die "p4d is not running."
- fi
- #
- # Make sure local p4d is running
- #
- err=$( p4 ${P4D_PORT:+-p "$P4D_PORT"} ${P4D_USER:+-u "$P4D_USER"} \
- info -s 2>&1 ) || die "%s" "$err"
- #
- # Run verbose pull status (if-desired)
- #
- if [ "$VERBOSE" ]; then
- echo ">>> pull transfers for ${P4D_PORT:-${P4PORT:-perforce:1666}}:"
- p4 ${P4D_PORT:+-p "$P4D_PORT"} ${P4D_USER:+-u "$P4D_USER"} pull -l
- exit
- fi
- # NOTREACHED if `-v' given
- #
- # Get pull status
- #
- echo ">>> pull status for ${P4D_PORT:-${P4PORT:-perforce:1666}}:"
- p4 ${P4D_PORT:+-p "$P4D_PORT"} ${P4D_USER:+-u "$P4D_USER"} pull -l -j || exit
- p4 ${P4D_PORT:+-p "$P4D_PORT"} ${P4D_USER:+-u "$P4D_USER"} pull -l -s || exit
- exit $SUCCESS
- ################################################################################
- # END
- ################################################################################
- #
- # $Copyright: 2015 Devin Teske. All rights reserved. $
- #
- # $Header: //guest/freebsdfrau/p4t/libexec/pull_status#1 $
- #
- ################################################################################
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16365 | freebsdfrau | Import p4t - p4d admin tool | 9 years ago |