Last active
August 29, 2015 14:08
-
-
Save whymarrh/d8d4539567d49fc4d017 to your computer and use it in GitHub Desktop.
Installation script for Git on OS X (modified from timcharper/git_osx_installer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e -o pipefail | |
LATEST_GIT_VERSION=$(curl http://git-scm.com/ 2>&1 | grep -A 2 '<span class="version">' | grep '[[:digit:]].[[:digit:]]' | tr -d ' ') | |
GIT_VERSION="${1:-$LATEST_GIT_VERSION}" | |
PREFIX="/usr/local/git" | |
SUDO="sudo" | |
NOW_SECONDS=$(date +%s) | |
THE_ABYSS="/dev/null" | |
echo "Building Git v${GIT_VERSION}" | |
if [[ -d "$PREFIX" ]] | |
then | |
echo "Moving your current installation of Git out of the way" | |
$SUDO mv "$PREFIX" "${PREFIX}_${NOW_SECONDS}" | |
echo "Your old Git installation is to ${PREFIX}_${NOW_SECONDS}" | |
fi | |
BUILD_DIR="foo${NOW_SECONDS}" | |
mkdir -p "$BUILD_DIR" | |
export TARGET_VERSION="10.6" | |
export TARGET_FLAGS="-mmacosx-version-min=$TARGET_VERSION -isysroot $SDK_PATH -DMACOSX_DEPLOYMENT_TARGET=$TARGET_VERSION" | |
export CFLAGS="$TARGET_FLAGS -arch i386 -arch x86_64" | |
export LDFLAGS="$TARGET_FLAGS -arch i386 -arch x86_64" | |
export C_INCLUDE_PATH="/usr/include" | |
export CPLUS_INCLUDE_PATH="/usr/include" | |
export LD_LIBRARY_PATH="/usr/lib" | |
pushd "$BUILD_DIR" > "$THE_ABYSS" | |
if [[ ! -f "git-$GIT_VERSION.tar.gz" ]] | |
then | |
echo "Downloading the source" | |
curl -sO "https://www.kernel.org/pub/software/scm/git/git-$GIT_VERSION.tar.gz" | |
fi | |
if [[ ! -d "git-$GIT_VERSION" ]] | |
then | |
echo "Extracting the downloaded source" | |
tar zxf "git-$GIT_VERSION.tar.gz" | |
fi | |
pushd "git-$GIT_VERSION" > "$THE_ABYSS" | |
echo "Compiling'n'stuff" | |
$SUDO make -j32 NO_GETTEXT=1 NO_DARWIN_PORTS=1 prefix="$PREFIX" all strip install | |
$SUDO mkdir -p "$PREFIX/contrib/completion" | |
$SUDO cp contrib/completion/git-completion.bash "$PREFIX/contrib/completion/" | |
$SUDO cp contrib/completion/git-completion.zsh "$PREFIX/contrib/completion/" | |
$SUDO cp contrib/completion/git-prompt.sh "$PREFIX/contrib/completion/" | |
$SUDO mkdir -p "$PREFIX/lib/perl5/site_perl" | |
$SUDO cp perl/private-Error.pm "$PREFIX/lib/perl5/site_perl/Error.pm" | |
popd > "$THE_ABYSS" | |
$SUDO mkdir -p "$PREFIX/share/man" | |
GIT_MANPAGES_ARCHIVE="git-manpages-${GIT_VERSION}.tar.gz" | |
echo "Downloading the manpages" | |
curl -sO "https://www.kernel.org/pub/software/scm/git/$GIT_MANPAGES_ARCHIVE" | |
echo "Extracting the downloaded manpages" | |
if ( ! $SUDO tar xzf "$GIT_MANPAGES_ARCHIVE" -C "$PREFIX/share/man" ); then | |
echo "Extracting the man pages failed" | |
exit 1 | |
fi | |
$SUDO chmod -R go+rx "$PREFIX/share/man" | |
popd > "$THE_ABYSS" | |
$SUDO rm -fr "$BUILD_DIR" | |
if [[ -d /etc/paths.d ]] | |
then | |
$SUDO sh -c "echo '$PREFIX/bin' > /etc/paths.d/git" | |
fi | |
if [[ -d /etc/manpaths.d ]] | |
then | |
$SUDO sh -c "echo '$PREFIX/share/man' > /etc/manpaths.d/git" | |
fi | |
$SUDO sh -c "echo .DS_Store >> '$PREFIX/share/git-core/templates/info/exclude'" | |
$SUDO chown -R root:wheel "$PREFIX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment