Skip to content

Instantly share code, notes, and snippets.

@ambakshi
Last active November 12, 2015 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambakshi/d1ceb8a37dc6afebcc73 to your computer and use it in GitHub Desktop.
Save ambakshi/d1ceb8a37dc6afebcc73 to your computer and use it in GitHub Desktop.
bootstrap-p4p.sh
#!/bin/bash
#
# GCE startup script for a Perforce Proxy. Set the metadata keys to
# env-vars you'd like to set (for example, P4PORT=xyz:1666)
#
# Amit Bakshi
# 11/11/2015
set -ex
if [ `id -u` -ne 0 ]; then
sudo exec /bin/bash "$0" "$@" || exit 1
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y bash-completion make gcc git ctags vim-nox curl wget build-essential \
libevent-dev ncurses-base tack libtinfo5 ncurses-dev
# Find metadata keys that are all CPAS and turn them into env-vars
for meta in $(/usr/share/google/get_metadata_value attributes/); do
if echo $meta | grep -qv [-a-z]; then
eval $(echo export $meta="$(/usr/share/google/get_metadata_value attributes/$meta)")
fi
done
# Install puppet-agent (puppet 4.x)
wget https://apt.puppetlabs.com/puppetlabs-release-pc1-wheezy.deb
dpkg -i puppetlabs-release-pc1-wheezy.deb
apt-get update -y
apt-get install -y puppet-agent puppetdb-terminus vim-puppet puppet-lint ruby bundler
# Install Perforce 2015.2
curl -sSL http://cdist2.perforce.com/perforce/r15.2/bin.linux26x86_64/helix-versioning-engine.tgz | tar zxvf - -C /usr/local/bin/
curl -sSL http://bit.ly/devbootstrap | bash
## Mount a device as the cache
if [ ! -d "$P4PCACHE" ]; then
mkdir -p "$P4PCACHE"
fi
DEVICE="${DEVICE:-sdb}"
if test -b "/dev/${DEVICE}" && ! mountpoint -q "$P4PCACHE"; then
device_mounted="$(lsblk | awk '/^'$DEVICE'/{print $7}')"
if [ $? -eq 0 ] && [ "$device_mounted" = "" ]; then
/usr/share/google/safe_format_and_mount "/dev/${DEVICE}" "${P4PCACHE}"
tune2fs -L P4PCACHE "/dev/${DEVICE}"
echo "LABEL=P4PCACHE $P4PCACHE ext4 discard,defaults 0 0" | tee -a /etc/fstab
fi
fi
## Grab statically compiled tmux 2.1
curl -sSL http://yum.baksh.io/files/tmux-2.1.bz2 | tar jxvf - -C /usr/local/
ln -sfn /usr/local/tmux/tmux /usr/local/bin/
# My tmux's notion of terminfo is whack
rmdir /usr/share/terminfo && ln -sfn /lib/terminfo /usr/share/ || :
cd /
hash -r
tmux new-session -d -s main
tmux new-window -t main -n p4p /usr/local/bin/p4p -r $P4PCACHE -t $P4TARGET -p $P4PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment