Skip to content

Instantly share code, notes, and snippets.

@statico
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statico/4d112da69970467c113f to your computer and use it in GitHub Desktop.
Save statico/4d112da69970467c113f to your computer and use it in GitHub Desktop.
perforce-setup.sh
#!/usr/bin/env bash
set -e
get_p4_url() {
local os=$(uname -s)
if [[ "$os" =~ Linux ]]; then
echo "http://cdist2.perforce.com/perforce/r14.2/bin.linux26x86_64/p4"
else
echo "http://cdist2.perforce.com/perforce/r14.2/bin.macosx105x86/p4"
fi
}
main() {
echo
echo "What is your Assembla username?"
local username="$( grep P4USER ~/.p4config 2>/dev/null | cut -d= -f2 )"
if [ -n "$username" ]; then
local prompt="[$username] > "
else
local prompt="> "
fi
local temp
read -e -p "$prompt" temp
if [ -n "$temp" ]; then
username=$temp
fi
cat >~/.p4config <<END
P4PORT=perforce.assembla.com:1666
P4HOST=artillerydepot
P4CHARSET=utf8
P4USER=$username
END
# Preserve any existing data in .p4ignore.
local tempfile=$(mktemp -t p4ignore)
[ -e ~/.p4ignore ] && cat ~/.p4ignore >$tempfile
cat >>$tempfile <<END
.DS_Store
.mayaSwatches
incrementalSave
workspace.mel
END
cat $tempfile | sort | uniq >~/.p4ignore
rm $tempfile
echo
echo "If prompted, enter your LOCAL COMPUTER PASSWORD (not your Assembla password)."
read -e -n 1 -p "Ready? (hit enter to continue) "
sudo mkdir -p /usr/local/bin
local p4url=$(get_p4_url)
curl -s -o /tmp/p4 "$p4url"
chmod +x /tmp/p4
sudo mv /tmp/p4 /usr/local/bin/p4
export PATH=/usr/local/bin/p4:$PATH
p4 set P4CONFIG=$HOME/.p4config
p4 set P4IGNORE=$HOME/.p4ignore
echo
if p4 info >/dev/null 2>&1 ; then
echo "Done!"
echo
echo "You can close this window."
echo "(p4 has been installed in /usr/local/bin and a ~/.p4config has been created)"
else
echo "ERROR! Ask an engineer for help! ('p4 info' failed)"
fi
echo
}
main "$@"
@statico
Copy link
Author

statico commented Oct 31, 2014

NOTE: Perforce instructions use a short URL, e.g. bash <(curl -sL http://goo.gl/IsiVMV)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment