Skip to content

Instantly share code, notes, and snippets.

@allaryin
Created April 22, 2016 20:01
Show Gist options
  • Save allaryin/dbd453f42900310dd115d9a2b132eebf to your computer and use it in GitHub Desktop.
Save allaryin/dbd453f42900310dd115d9a2b132eebf to your computer and use it in GitHub Desktop.
A couple of simple p4 management scripts.
#!/bin/sh
# Reference: https://www.perforce.com/perforce-packages
# - This includes the expected key fingerprint, etc...
wget http://package.perforce.com/perforce.pubkey
if [ $? -ne 0 -o ! -f perforce.pubkey ]; then
echo "Unable to download public key, aborting."
fi
gpg --with-fingerprint perforce.pubkey | tee perforce.fingerprint
grep 'E581 31C0 AEA7 B082 C6DC 4C93 7123 CB76 0FF1 8869' perforce.fingerprint
if [ $? -ne 0 ]; then
echo "GPG fingerprint failed, aborting installation."
fi
cat perforce.pubkey | sudo apt-key add -
rm perforce.pubkey perforce.fingerprint
VERSION=`lsb_release -c -s`
case $VERSION in
# P4 ships binaries for debian 7, so let's try those if possible
# -- ACTUALLY -- the debian repo is busted ;)
wheezy)
VERSION='precise'
;;
#jessie)
# VERSION='wheezy'
# ;;
# P4 only ships binaries for ubuntu 12.04 and 14.04 so far...
# unless we're running 12.04, we should try the 14.04 deb
precise)
;;
*)
VERSION='trusty'
esac
apt-add-repository "deb http://package.perforce.com/apt/ubuntu ${VERSION} release"
aptitude update && aptitude install helix-cli
#!/bin/sh
#
# This is written under the assumption that p4broker was installed via the
# official package distribution (and not some custom way). All broker nodes
# have configuration that lives in ${BASE_DIR}/${NODE_NAME}/broker.cfg.
#
# This broker.cfg file should be split into two separate components that live
# in the individual node directory:
# - header.inc
# - maintenance.inc
#
# The header is the normal broker config during regular operation.
#
# The maintenance is a file that will be apprended to the header whenever
# maintenance is on. It should contain the word 'maintenance' SOMEWHERE in it,
# and similarly the header file should NOT contain the word. This is used to
# determine the current state of the node's config.
P4_USER="perforce"
BASE_DIR="/opt/perforce/servers"
if [ ! -w "${BASE_DIR}" ]; then
echo "Unable to write to ${BASE_DIR}, try again as '${P4_USER}' or 'root'"
exit 1
fi
cd ${BASE_DIR}
CMD="$1"
if [ ! -z "$2" ]; then
NODES="$2"
else
NODES=*
fi
for NODE in ${NODES}; do
if [ ! -d "${NODE}" ]; then
echo "${NODE}: no such node"
continue
fi
grep 'maintenance' ${NODE}/broker.conf 2>&1 >/dev/null
if [ $? -eq 0 ]; then
STATE='on'
else
STATE='off'
fi
if [ "${STATE}" = "${CMD}" ]; then
echo "${NODE}: maint mode is already ${STATE}"
continue
fi
case $CMD in
on)
cd ${NODE}
cat header.inc maintenance.inc > broker.conf
echo "${NODE}: maint mode turned ON"
;;
off)
cd ${NODE}
cat header.inc > broker.conf
echo "${NODE}: maint mode turned off"
;;
status)
echo "${NODE}: ${STATE}"
;;
*)
echo "$0 <status|on|off> [node]\n"
echo "If no node is specified, then all nodes will be affected."
break
;;
esac
cd ${BASE_DIR}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment