Skip to content

Instantly share code, notes, and snippets.

@kiarafbickers
Last active October 8, 2016 19:33
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 kiarafbickers/d18782a751bbedff2a2c34caded96b3d to your computer and use it in GitHub Desktop.
Save kiarafbickers/d18782a751bbedff2a2c34caded96b3d to your computer and use it in GitHub Desktop.
Git Update & Install with PGP and ShaSums
git-validated-install()
{
# Pull the latest version of Git from https://git-scm.com html
if [ -z "$latest_git_version" ]; then
if [ "`uname`" == "Darwin" ]; then
sed_regexp="-E";
else
sed_regexp="-r";
fi
latest_git_version=$(curl https://git-scm.com/ 2>&1 | grep '<span class="version">' -A 1 | tail -n 1 | sed $sed_regexp 's/ *//')
fi
# Get the version of Git locally
local_git_version=$(git --version)
local_git_version=$($local_git_version |cut -d " " -f3)
echo "Latest Git Version: $latest_git_version"
echo "Local Git Version: $local_git_version"
if [[ "$local_git_version" == "$latest_git_version" ]]; then
echo "Git is already up to date."
else
# Fetch tar
curl -O https://kernel.org/pub/software/scm/git/git-2.10.1.tar.gz
# Fetch checksums
curl -O https://kernel.org/pub/software/scm/git/sha256sums.asc
# Fetch GPG sig from keyserver network:
gpg --keyserver keyserver.ubuntu.com --recv-keys 0x632D3A06589DA6B1
# Fetch GPG sig from keyserver network:
signature=$(gpg --verify sha256sums.asc | grep "Good signature")
# *Caveat: this trusts the keyserver network and the provenance of the KeyID from the GPG signature
if [ $signature -eq 0 ]; then
echo "Signature failed!"
return 1
fi
# Install openssl
brew install openssl
# Compare checksums
cksum=$(shasum -a 256 ./git-$latest_git_version.tar.gz | cut -d" " -f1)
refsum=$(grep git-$latest_git_version.tar.gz ./sha256sums.asc | cut -d" " -f1)
if [ "$refsum" != "$cksum" ]; then
echo "Bad checksum"
return 1
fi
# Uncompressing tar archive
tar xzf "git-$latest_git_version.tar.gz"
cd "git-$latest_git_version"
# Downloading gettext
brew install gettext
# Add symlinks
export LDFLAGS=-L/usr/local/opt/gettext/lib
export CPPFLAGS=-I/usr/local/opt/gettext/include
# Define two environment variables
export CPATH="/usr/local/opt/openssl/include:/usr/local/opt/gettext/include"
export LIBRARY_PATH="/usr/local/opt/openssl/lib:/usr/local/opt/gettext/lib"
brew link gettext --force
# Clean up files
cd ..
rm -r -f "git-$latest_git_version"
rm "git-$latest_git_version.tar.gz"
rm sha256sums.asc
make
fi
}
@ahmedbargout
Copy link

hii

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