Skip to content

Instantly share code, notes, and snippets.

@justintoo
Created September 11, 2015 21:07
Show Gist options
  • Save justintoo/a06e5941d9601e68f29d to your computer and use it in GitHub Desktop.
Save justintoo/a06e5941d9601e68f29d to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#-------------------------------------------------------------------------------
# Default values
#-------------------------------------------------------------------------------
: ${GIT_VERSION:=$1}
echo "[INFO] git '$GIT_VERSION'"
: ${DESTDIR:=$(pwd)}
: ${PREFIX:=${DESTDIR}/${GIT_VERSION}}
: ${WORKSPACE:=${PREFIX}/workspace}
#-------------------------------------------------------------------------------
# Sanity Checks
#-------------------------------------------------------------------------------
if [ -z "${GIT_VERSION}" ]; then
echo "Usage: $0 <version: x.xx>"
exit 1
fi
#-------------------------------------------------------------------------------
# Meta Information
#-------------------------------------------------------------------------------
GIT_SRCDIR="${WORKSPACE}/git-${GIT_VERSION}"
GIT_TARBALL="git-${GIT_VERSION}.tar.gz"
GIT_DOWNLOAD_URL="https://www.kernel.org/pub/software/scm/git/${GIT_TARBALL}"
#-------------------------------------------------------------------------------
# Workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# Download and unpack
#-------------------------------------------------------------------------------
if [ ! -f "$GIT_TARBALL" -a ! -f "${GIT_TARBALL%.xz}" ]; 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 xzvf "${GIT_TARBALL}"
else
echo "[INFO] [SKIP] git source code already exists: '$GIT_SRCDIR'"
fi
#-------------------------------------------------------------------------------
# Build and install
#-------------------------------------------------------------------------------
cd "${GIT_SRCDIR}" || exit 1
if [ ! -e "${PREFIX}/bin" ]; then
echo "[INFO] Configuring git"
echo "[INFO] Installing to '$PREFIX'"
"${GIT_SRCDIR}/configure" --prefix="$PREFIX" || exit 1
make -j all || exit 1
make -j install || exit 1
fi
echo "[INFO] Creating git environment setup file"
cat > "${PREFIX}/setup.sh" <<-EOF
#!/bin/bash
#
# Automatically generated by $0 on $(date)
export GIT_VERSION="${GIT_VERSION}"
export GIT_HOME="${PREFIX}"
export PATH="\${GIT_HOME}/bin:\${PATH}"
export LD_LIBRARY_PATH="\${GIT_HOME}/lib:\${LD_LIBRARY_PATH}"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment