Skip to content

Instantly share code, notes, and snippets.

@ipsycodex
Created May 2, 2019 11:20
Show Gist options
  • Select an option

  • Save ipsycodex/6417ed487dd08eb7bc150c200b0cbe9b to your computer and use it in GitHub Desktop.

Select an option

Save ipsycodex/6417ed487dd08eb7bc150c200b0cbe9b to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Script to boostrap g4 on a client
#
#
# Don't need pip/virtualenv anymore, so skip it.
#
check_pip () {
if ! which pip >/dev/null 2>&1; then
echo "You need to install pip:"
echo "sudo easy_install pip"
exit 1
fi
if ! which virtualenv >/dev/null 2>&1; then
echo "You need to install virtualenv:"
echo "sudo pip install virtualenv"
exit 1
fi
VEVERS=$(virtualenv --version)
if [ $? -ne 0 ]; then
echo >&2
echo "*** WARNING: It seems virtualenv is installed but broken on your system ***" >&2
echo "*** If the installer fails, run 'sudo pip install virtualenv==1.10.1' ***" >&2
echo "*** and try it again. ***" >&2
echo >&2
elif [ "$VEVERS" != "1.10.1" ]; then
echo >&2
echo "*** WARNING: Your virtualenv is at version $VEVERS, which may be broken ***" >&2
echo "*** If the installer fails, run 'sudo pip install virtualenv==1.10.1' ***" >&2
echo "*** and try it again. ***" >&2
echo >&2
fi
}
update_profile () {
echo
echo "Adding \$HOME/bin to your \$PATH in $1 ..."
echo 'export PATH="$HOME/bin:$PATH"' >> "$1"
echo "Run 'source $1' or open a new terminal."
echo
}
if [ -e /opt/boxen/env.sh ]; then
source /opt/boxen/env.sh
fi
export PATH="$PATH:/usr/local/bin"
hash -r
set -e
## Dont need this anymore bc we ship a lightweight shim to virtualenv-1.11.6
## with the tool!
# check_pip
G4="$HOME/.g4"
G4_REPO="ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/g4"
if [ -e "$G4/.git" ]; then
rm -rf "$G4"
fi
mkdir -p "$G4" "$HOME/bin"
echo "Installing g4 ..."
git clone -q $G4_REPO "$G4"
cat > "$HOME/bin/g4" <<EOF
#!/bin/bash
export G4="$G4"
exec "$G4/bin/g4" "\$@"
EOF
chmod +x "$HOME/bin/g4"
(cd "$G4" && make venv)
echo Done.
# Add $HOME/bin to your $PATH if it isn't there already
hash -r
if ! which g4 >/dev/null 2>&1; then
# Most shells will use ~/.profile if the shell specific one is missing
# eg, ~/.bash_profile, ~/.zprofile
profile="$HOME/.profile"
case "$SHELL" in
/bin/bash)
[ -e "$HOME/.bash_profile" ] && profile="$HOME/.bash_profile" ;;
/bin/zsh)
[ -e "$HOME/.zprofile" ] && profile="$HOME/.zprofile" ;;
*)
echo "Couldn't determing what shell you're using SHELL=$SHELL. Guessing profile is $profile" ;;
esac
update_profile "$profile"
source "$profile"
fi
# Run it to show the usage
$HOME/bin/g4 || true
# If we had to fix the profile, open a new shell so we keep the environment
[ -n "$profile" ] && $SHELL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment