Skip to content

Instantly share code, notes, and snippets.

@AlexBaranowski
Last active April 13, 2018 09:50
Show Gist options
  • Save AlexBaranowski/68f014d1ec8ec1115598dbc9b4870285 to your computer and use it in GitHub Desktop.
Save AlexBaranowski/68f014d1ec8ec1115598dbc9b4870285 to your computer and use it in GitHub Desktop.
Install the newest GIT on EuroLinux/Scientific Linux/RHEL/Oracle Linux/CentOS/. Taken from this article: https://pl.euro-linux.com/git-podstawowe-narzedzie-pracy-dewelopera-czesc-ii-troche-komend-troche-praktyki/
#!/bin/bash
# The MIT License (MIT)
# Copyright (c) 2017 EuroLinux
# Author: Alex Baranowski
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
MY_LOGFILE="/var/log/git_installation.log"
MY_REQUIRED_COMMAND='yum tee sed wget'
check_running_as_root(){
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privilages. Please run it as root or via sudo."
exit 1
fi
}
check_required_commands(){
for my_command in $REQUIRED_COMMAND; do
hash $my_command 2>/dev/null || { echo "Script requires $my_command command! Aborting."; exit 1; }
done
}
rpm_mods(){
echo "Removing git rpm if installed, install necessary rpm packages." | tee $MY_LOGFILE
yum remove -y git
yum install -y curl-devel expat-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker gettext
}
get_newest_stable_git_version(){
# NOTE: reading tags with regex is the simplest but definitely not the best way
page="https://git-scm.com/downloads"
tag_open="span class=\"version\""
tag_end="span"
git_current_v=$(curl -s $page | sed -n "/<$tag_open>/,/<\/$tag_end>/p" | grep -Eo '[0-9\.]*')
echo "Getting the newest git git-${git_current_v}" | tee $MY_LOGFILE
echo "Getting git-${git_current_v} and unpacking it into /usr/src/" | tee $MY_LOGFILE
wget https://www.kernel.org/pub/software/scm/git/git-${git_current_v}.tar.gz -O /tmp/git-latest.tar.gz
tar xvzf /tmp/git-latest.tar.gz -C /usr/src/
cd /usr/src/git-${git_current_v}/
./configure
make
make install
}
set -e # Script stops on first error
check_running_as_root
check_required_commands
rpm_mods
get_newest_stable_git_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment