Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Created October 22, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirafrank/1160d3d26e6d19af63c700b543bc96d9 to your computer and use it in GitHub Desktop.
Save pirafrank/1160d3d26e6d19af63c700b543bc96d9 to your computer and use it in GitHub Desktop.
Easy script to download, compile and install Git. Tested in Debian 7 and 8.
#!/bin/bash
# user vars
GIT_VERSION="2.9.1"
# script vars
WORKDIR="/tmp/git_temp"
CUR_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# the actual script
if [[ $EUID -ne 0 ]]; then
echo "Error: you need to run this script with root priviledges"
exit 1
fi
echo "
----------------------------
Starting GIT script...
----------------------------
"
echo "Completely uninstalling git if previously installed..."
if [ $(dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
echo "git found ($(git --version)). Purging..."
apt-get remove --purge -y git git-man git-daemon-run git-daemon-sysvinit \
git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn
else
echo "Nothing to uninstall: git is not installed"
fi
mkdir -p $WORKDIR
cd $WORKDIR
echo "---------> Downloading sources..."
wget ftp://ftp.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.xz
echo "Extracting..."
tar -xJf git-${GIT_VERSION}.tar.xz
cd $WORKDIR/git-${GIT_VERSION}
echo "---------> Installing deps..."
apt-get install -y build-essential libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf
echo "---------> Configuring..."
make configure
./configure --prefix=/usr --with-gitconfig=/etc/gitconfig
echo "---------> Compiling..."
make
echo "---------> Installing..."
make install
echo "---------> Cleaning up..."
rm -rf $WORKDIR
# handling unknown errors causing git not to be installed
if [ -z "`which git 2>/dev/null`" ]; then
echo "ERROR: Unknown error, git wasn't installed. Aborting..."
exit 1
fi
echo "----- Done. -----
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment