Skip to content

Instantly share code, notes, and snippets.

@doubleotoo
Created June 24, 2013 19:51
Show Gist options
  • Save doubleotoo/5852989 to your computer and use it in GitHub Desktop.
Save doubleotoo/5852989 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#-------------------------------------------------------------------------------
# Default values
#-------------------------------------------------------------------------------
: ${GIT_VERSION:=$1}
echo "[INFO] Git '$GIT_VERSION'"
: ${GCC_HOME:=}
if [ -z "${GCC_HOME}" ]; then
echo "[FATAL] \$GCC_HOME is not set"
exit 1
fi
GCC_VERSION="$(gcc -dumpversion)"
: ${DESTDIR:=$(pwd)}
: ${PREFIX:=${DESTDIR}/${GIT_VERSION}/gcc/${GCC_VERSION}}
: ${WORKSPACE:=${PREFIX}/workspace}
#-------------------------------------------------------------------------------
# Sanity Checks
#-------------------------------------------------------------------------------
if [ -z "${GIT_VERSION}" ]; then
echo "Usage: $0 <version: x.x.x.x>"
exit 1
fi
#-------------------------------------------------------------------------------
# Meta Information
#-------------------------------------------------------------------------------
GIT_SRCDIR="${WORKSPACE}/git-${GIT_VERSION}"
GIT_TARBALL="git-${GIT_VERSION}.tar.gz"
GIT_DOWNLOAD_URL="https://git-core.googlecode.com/files/${GIT_TARBALL}"
#-------------------------------------------------------------------------------
# Workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# [LLVM] Download and unpack
#-------------------------------------------------------------------------------
if [ ! -f "$GIT_TARBALL" ]; then
echo "[INFO] Downloading GIT '$GIT_DOWNLOAD_URL'"
wget --no-check-certificate "$GIT_DOWNLOAD_URL" || exit 1
else
echo "[INFO] [SKIP] Git tarball already exists: '$GIT_TARBALL'"
fi
if [ ! -d "$GIT_SRCDIR" ]; then
echo "[INFO] Unpacking Git tarball: '$GIT_TARBALL'"
tar xvzf "$GIT_TARBALL" || exit 1
else
echo "[INFO] [SKIP] Git source code already exists: '$GIT_SRCDIR'"
fi
#-------------------------------------------------------------------------------
# Build and install
#-------------------------------------------------------------------------------
cd "${GIT_SRCDIR}"
if [ ! -e "${PREFIX}/bin" ]; then
echo "[INFO] Configuring Git"
echo "[INFO] Installing to '$PREFIX'"
echo "[INFO] \$GCC_HOME='${GCC_HOME}'"
"${GIT_SRCDIR}/configure" --prefix="$PREFIX" || exit 1
make -j all || exit 1
make -j install || exit 1
echo "[INFO] Creating Git environment setup file"
cat > "${PREFIX}/setup.sh" <<-EOF
#!/bin/bash
#
# Automatically generated by $0 on $(date)
export GIT_HOME="${PREFIX}"
export PATH="\${GIT_HOME}/bin:\${PATH}"
export GIT_GCC_HOME="${GCC_HOME}"
EOF
#-----------------------------------------------
# Set Permissions
#-----------------------------------------------
echo "[INFO] Setting group permissions of '${PREFIX}'"
chmod -R g+r "${PREFIX}"
find "${PREFIX}" -type d -exec chmod g+x {} \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment