Skip to content

Instantly share code, notes, and snippets.

@amitizle
Created June 4, 2019 11:12
Show Gist options
  • Save amitizle/f8e3174d8d7e8943fddc3372fbd10f68 to your computer and use it in GitHub Desktop.
Save amitizle/f8e3174d8d7e8943fddc3372fbd10f68 to your computer and use it in GitHub Desktop.
Install a newer curl version from Github releases
#!/usr/bin/env bash
set -e
# Ubuntu 16.04's curl is very ultra amzingly old. That's why.
LOGGER_RED='\033[0;31m'
LOGGER_GREEN='\033[0;32m'
LOGGER_YELLOW='\033[0;33m'
LOGGER_NC='\033[0m' # No Color
CURL_VERSION="${1:-7.65.0}"
CURL_TMP_DIR=$(mktemp -d)
CURL_TMP_FILE="${CURL_TMP_DIR}/curl.tar.gz"
CURL_CURRENT_VERSION="$(curl --version | grep -Po 'curl \d+\.\d+\.\d+')"
log_info() {
printf "${LOGGER_GREEN}%s%s${LOGGER_NC}\n" "$(log_timestamp)" "$1"
}
log_warn() {
printf "${LOGGER_YELLOW}%s%s${LOGGER_NC}\n" "$(log_timestamp)" "$1"
}
log_error() {
printf "${LOGGER_RED}%s%s${LOGGER_NC}\n" "$(log_timestamp)" "$1"
}
log_timestamp() {
local retval="[$(date --iso-8601=seconds)] "
echo "$retval"
}
if [ "$CURL_CURRENT_VERSION" = "curl ${CURL_VERSION}" ]
then
log_info "curl version ${CURL_VERSION} is already installed"
exit 0
fi
log_info "Installing dependencies, sudo will be needed"
sudo apt-get -qq -y install build-essential nghttp2 libnghttp2-dev libssl-dev libcurl3 curl
cleanup() {
rm -rf "$CURL_TMP_DIR"
}
log_info "Downloading curl release from github"
curl -sL \
"https://github.com/curl/curl/releases/download/curl-${CURL_VERSION//\./_}/curl-${CURL_VERSION}.tar.gz" \
-o "$CURL_TMP_FILE"
log_info "extracting curl tarball to ${CURL_TMP_DIR}"
tar xf "$CURL_TMP_FILE" -C "$CURL_TMP_DIR" --strip-components=1
log_info "comiling curl in ${CURL_TMP_DIR}"
pushd "$CURL_TMP_DIR"
./configure
make
log_info "running 'sudo make install'"
sudo make install
popd
cleanup
sudo apt-get -qq -y remove curl libcurl3-dbg libcurl3-gnutls libcurl3-nss
/usr/local/bin/curl --version || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment