Skip to content

Instantly share code, notes, and snippets.

@doubleotoo
Created November 20, 2013 18:40
Show Gist options
  • Save doubleotoo/7568584 to your computer and use it in GitHub Desktop.
Save doubleotoo/7568584 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#-------------------------------------------------------------------------------
# Default values
#-------------------------------------------------------------------------------
: ${MERCURIAL_VERSION:=$1}
echo "[INFO] MERCURIAL version '$MERCURIAL_VERSION'"
: ${PYTHON_VERSION:=}
if [ -z "${PYTHON_VERSION}" ]; then
echo "[FATAL] \$PYTHON_VERSION is not set"
exit 1
fi
: ${PYTHON_HOME:=}
if [ -z "${PYTHON_HOME}" ]; then
echo "[FATAL] \$PYTHON_HOMEis not set"
exit 1
fi
: ${DESTDIR:=$(pwd)}
: ${PREFIX:=${DESTDIR}/${MERCURIAL_VERSION}/python/${PYTHON_VERSION}}
: ${WORKSPACE:=${PREFIX}/workspace}
#-------------------------------------------------------------------------------
# Sanity Checks
#-------------------------------------------------------------------------------
if [ -z "${MERCURIAL_VERSION}" ]; then
echo "Usage: $0 <version: x.x.x>"
exit 1
fi
#-------------------------------------------------------------------------------
# Meta Information
#-------------------------------------------------------------------------------
MERCURIAL_SRCDIR="${WORKSPACE}/mercurial-${MERCURIAL_VERSION}"
MERCURIAL_TARBALL="mercurial-${MERCURIAL_VERSION}.tar.gz"
MERCURIAL_DOWNLOAD_URL="http://mercurial.selenic.com/release/${MERCURIAL_TARBALL}"
#-------------------------------------------------------------------------------
# Workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# Download and unpack
#-------------------------------------------------------------------------------
if [ ! -f "$MERCURIAL_TARBALL" -a ! -f "${MERCURIAL_TARBALL%.xz}" ]; then
echo "[INFO] Downloading MERCURIAL '$MERCURIAL_DOWNLOAD_URL'"
wget --no-check-certificate "$MERCURIAL_DOWNLOAD_URL" || exit 1
else
echo "[INFO] [SKIP] Mercurial tarball already exists: '$MERCURIAL_TARBALL'"
fi
if [ ! -d "$MERCURIAL_SRCDIR" ]; then
echo "[INFO] Unpacking Mercurial tarball: '$MERCURIAL_TARBALL'"
tar xvzf "${MERCURIAL_TARBALL}"
else
echo "[INFO] [SKIP] Mercurial source code already exists: '$MERCURIAL_SRCDIR'"
fi
#-------------------------------------------------------------------------------
# Build and install
#-------------------------------------------------------------------------------
cd "${MERCURIAL_SRCDIR}"
if [ ! -e "${PREFIX}/bin" ]; then
echo "[INFO] Configuring Mercurial"
echo "[INFO] Installing to '$PREFIX'"
echo "[INFO] \$PYTHON_VERSION='${PYTHON_VERSION}'"
make install -j PREFIX="${PREFIX}" || exit 1
fi
echo "[INFO] Creating Mercurial environment setup file"
cat > "${PREFIX}/setup.sh" <<-EOF
#!/bin/bash
#
# Automatically generated by $0 on $(date)
export MERCURIAL_PYTHON_HOME="${PYTHON_HOME}"
# Uncomment to source the version of GCC that was used to
# compile this version of Mercurial.
#source "\${MERCURIAL_PYTHON_HOME}/setup.sh" || return 1
export MERCURIAL_VERSION="${MERCURIAL_VERSION}"
export MERCURIAL_HOME="${PREFIX}"
export PATH="\${MERCURIAL_HOME}/bin:\${PATH}"
export PYTHONPATH="\${MERCURIAL_HOME}/lib/python2.7/site-packages:\${PYTHONPATH}"
EOF
#-----------------------------------------------
# Set Permissions
#-----------------------------------------------
echo "[INFO] Setting group permissions of '${PREFIX}'"
chmod -R g+r "${PREFIX}"
find "${PREFIX}" -type d -exec chmod g+x {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment