Skip to content

Instantly share code, notes, and snippets.

@andkirby
Last active June 25, 2020 17:12
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 andkirby/16e3c7e4be8bac4c6b3bd0ae8f713552 to your computer and use it in GitHub Desktop.
Save andkirby/16e3c7e4be8bac4c6b3bd0ae8f713552 to your computer and use it in GitHub Desktop.
Downloader for Git Bash for Windows
#!/usr/bin/env bash
##################################################################
# Automatically download Git Bash for Windows portable version #
##################################################################
# Quick running:
# curl -Ls https://gist.githubusercontent.com/andkirby/16e3c7e4be8bac4c6b3bd0ae8f713552/raw/git-downloader | bash
##################################################################
set -o pipefail
set -o errexit
set -o nounset
#set -o xtrace
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
readonly __dir __file
if [ -z "${${EXEPATH}" ]; then
echo "Sorry, it does not look like you use Git Bash for Windows." >&2
exit 2
fi
api_releases=$(curl --silent --location https://api.github.com/repos/git-for-windows/git/releases/latest)
app_bitness=64
download_url=$(echo ${api_releases} | grep -Eo 'https://[^" ]+Portable[^" ]+64[^ "]+\.exe')
download_file=$(echo ${download_url} | awk -F '/' '{print $NF}')
release_version=$(echo ${download_url} | grep -Eo '\/v.*?\/' | tr -d '\/v')
current_version=$(git --version | grep -Eo '[0-9.]+[^ ]+')
if [[ "${current_version}" == "${release_version}" ]]; then
echo "You have the Git For Windows same version (${current_version})." >&2
exit 3
fi
if [[ ! -e ${HOME}/${download_file} ]]; then
curl --silent --location --output ${HOME}/${download_file} ${download_url}
fi
echo "Downloaded File: ${HOME}/${download_file}"
echo "You Git path: ${EXEPATH}"
echo "Close GitBush and run the package:"
echo
echo " "$(echo ${HOME}/${download_file} | sed -r 's|/(\w)/|\1:/|')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment