Skip to content

Instantly share code, notes, and snippets.

@stevearc
Forked from statico/perforce-setup.sh
Last active August 29, 2015 14:08
Show Gist options
  • Save stevearc/996bfa69f1053e47250d to your computer and use it in GitHub Desktop.
Save stevearc/996bfa69f1053e47250d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash -e
get_p4_url() {
local os=$(uname -o)
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
read -e -p "$prompt" username
cat >~/.p4config <<END
P4PORT=perforce.assembla.com:1666
P4HOST=artillerydepot
P4CHARSET=utf8
P4USER=$username
END
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
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
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment