Skip to content

Instantly share code, notes, and snippets.

@Stargator
Last active January 23, 2019 23:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stargator/3e5544419dab92a1e88109040b3da172 to your computer and use it in GitHub Desktop.
Save Stargator/3e5544419dab92a1e88109040b3da172 to your computer and use it in GitHub Desktop.
Script for installing git on a Linux machine (tested on Ubuntu 16.04) and requires 'sudo' permission
#!/bin/bash
set -euo pipefail
gitVersion=2.20.1
directory=/home/user
if [ -z ${1+x} ]; then echo "No argument passed, using version $gitVersion"; else gitVersion=$1; fi
# Install dependencies on CentOS/Red Hat
sudo yum install gcc autoconf automake expat-devel gettext-devel libcurl-devel openssl-devel perl-CPAN perl-devel zlib-devel asciidoc
# Install New Git Version
echo "Download dependencies and install new version of Git"
cd $directory
wget https://www.kernel.org/pub/software/scm/git/git-$gitVersion.tar.gz
wget https://www.kernel.org/pub/software/scm/git/git-manpages-$gitVersion.tar.gz
wget https://www.kernel.org/pub/software/scm/git/git-htmldocs-$gitVersion.tar.gz
tar -xf git-$gitVersion.tar.gz
# Git Section
cd git-$gitVersion
# Not Optimize
make configure
./configure --prefix=/usr
make all doc
sudo make install install-doc install-html
# Optimize
#sudo make prefix=/usr profile
#sudo make prefix=/usr PROFILE=BUILD install install-doc install-html install-info
# Manpages
echo "Setting up manpages"
cd $directory
sudo tar -xf git-manpages-$gitVersion.tar.gz \
-C /usr/share/man --no-same-owner --no-overwrite-dir
# HTML Docs
echo "Installing HTML docs"
cd $directory
sudo mkdir -vp /usr/share/doc/git-$gitVersion &&
sudo tar -xf git-htmldocs-$gitVersion.tar.gz \
-C /usr/share/doc/git-$gitVersion --no-same-owner --no-overwrite-dir &&
sudo find /usr/share/doc/git-$gitVersion -type d -exec chmod 755 {} \; &&
sudo find /usr/share/doc/git-$gitVersion -type f -exec chmod 644 {} \;
# Reorganize Files
echo "Reorganizing files"
sudo mkdir -vp /usr/share/doc/git-$gitVersion/man-pages/{html,text} &&
sudo mv /usr/share/doc/git-$gitVersion/{git*.txt,man-pages/text} &&
sudo mv /usr/share/doc/git-$gitVersion/{git*.,index.,man-pages/}html &&
sudo mkdir -vp /usr/share/doc/git-$gitVersion/technical/{html,text} &&
sudo mv /usr/share/doc/git-$gitVersion/technical/{*.txt,text} &&
sudo mv /usr/share/doc/git-$gitVersion/technical/{*.,}html &&
sudo mkdir -vp /usr/share/doc/git-$gitVersion/howto/{html,text} &&
sudo mv /usr/share/doc/git-$gitVersion/howto/{*.txt,text} &&
sudo mv /usr/share/doc/git-$gitVersion/howto/{*.,}html
# Clean up
echo "Cleaning up"
cd $directory
rm git-$gitVersion.tar.gz
echo "rm git-$gitVersion.tar.gz"
rm git-manpages-$gitVersion.tar.gz
echo "rm git-manpages-$gitVersion.tar.gz"
rm git-htmldocs-$gitVersion.tar.gz
echo "rm git-htmldocs-$gitVersion.tar.gz"
sudo rm -R --interactive=never git-$gitVersion
echo "sudo rm -R git-$gitVersion"
@Stargator
Copy link
Author

I made this for my own use, but realized it would be useful for others. Please note the two lines of statements:

sudo make prefix=/usr profile
sudo make prefix=/usr PROFILE=BUILD install install-doc install-html install-info

This will optimize the installation so once installed Git runs faster. This means it will take 2 hours or so for the entire script to finish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment