ambakshi
10/19/2014 - 11:58 PM

Get the latest docker

Get the latest docker

#!/bin/bash
#
#
# Download the latest docker release and
# make sure /etc/sysconfig/docker is set
# to use it.
#

set -e

command_exists() {
	command -v "$@" > /dev/null 2>&1
}

user="$(id -un 2>/dev/null || true)"

curl=''
if command_exists curl; then
	curl='curl -sSL'
elif command_exists wget; then
	curl='wget -qO-'
elif command_exists busybox && busybox --list-modules | grep -q wget; then
	curl='busybox wget -qO-'
fi

DOCKER_LATEST_URL="$($curl -sSL https://get.docker.io/builds/ | grep -Eow 'https://get.docker.com/builds/Linux/x86_64/[^ ]+' | grep 'docker-[1-9]\.[2-9]\.[0-9]*$')"

if [ -z "$DOCKER_LATEST_URL" ]; then
  echo >&2 "Failed to find the latest docker release"
  exit 1
fi

SYSCONF="$(/bin/ls /etc/{sysconfig,default}/docker 2>/dev/null)"
if [ -n "$SYSCONF" ]; then
   . "$SYSCONF"
fi

# $exec is the name of the docker executable in the sysconfig file
DOCKER=${exec:-/usr/local/bin/docker}
$curl "$DOCKER_LATEST_URL" > $DOCKER.$$
chmod 0755 $DOCKER.$$
mv $DOCKER.$$ $DOCKER
if [ -n "$SYSCONF" ]; then
  sed -i -e '/exec=/d' $SYSCONF
  echo exec=$DOCKER | tee -a $SYSCONF
fi