github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/hack/install.sh (about)

     1  #!/bin/sh
     2  set -e
     3  #
     4  # This script is meant for quick & easy install via:
     5  #   'curl -sSL https://get.docker.com/ | sh'
     6  # or:
     7  #   'wget -qO- https://get.docker.com/ | sh'
     8  #
     9  # For test builds (ie. release candidates):
    10  #   'curl -fsSL https://test.docker.com/ | sh'
    11  # or:
    12  #   'wget -qO- https://test.docker.com/ | sh'
    13  #
    14  # For experimental builds:
    15  #   'curl -fsSL https://experimental.docker.com/ | sh'
    16  # or:
    17  #   'wget -qO- https://experimental.docker.com/ | sh'
    18  #
    19  # Docker Maintainers:
    20  #   To update this script on https://get.docker.com,
    21  #   use hack/release.sh during a normal release,
    22  #   or the following one-liner for script hotfixes:
    23  #     aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index
    24  #
    25  
    26  url="https://get.docker.com/"
    27  apt_url="https://apt.dockerproject.org"
    28  yum_url="https://yum.dockerproject.org"
    29  gpg_fingerprint="58118E89F3A912897C070ADBF76221572C52609D"
    30  
    31  key_servers="
    32  ha.pool.sks-keyservers.net
    33  pgp.mit.edu
    34  keyserver.ubuntu.com
    35  "
    36  
    37  mirror=''
    38  while [ $# -gt 0 ]; do
    39  	case "$1" in
    40  		--mirror)
    41  			mirror="$2"
    42  			shift
    43  			;;
    44  		*)
    45  			echo "Illegal option $1"
    46  			;;
    47  	esac
    48  	shift $(( $# > 0 ? 1 : 0 ))
    49  done
    50  
    51  case "$mirror" in
    52  	AzureChinaCloud)
    53  		apt_url="https://mirror.azure.cn/docker-engine/apt"
    54  		yum_url="https://mirror.azure.cn/docker-engine/yum"
    55  		;;
    56  esac
    57  
    58  command_exists() {
    59  	command -v "$@" > /dev/null 2>&1
    60  }
    61  
    62  echo_docker_as_nonroot() {
    63  	if command_exists docker && [ -e /var/run/docker.sock ]; then
    64  		(
    65  			set -x
    66  			$sh_c 'docker version'
    67  		) || true
    68  	fi
    69  	your_user=your-user
    70  	[ "$user" != 'root' ] && your_user="$user"
    71  	# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
    72  	cat <<-EOF
    73  
    74  	If you would like to use Docker as a non-root user, you should now consider
    75  	adding your user to the "docker" group with something like:
    76  
    77  	  sudo usermod -aG docker $your_user
    78  
    79  	Remember that you will have to log out and back in for this to take effect!
    80  
    81  	EOF
    82  }
    83  
    84  # Check if this is a forked Linux distro
    85  check_forked() {
    86  
    87  	# Check for lsb_release command existence, it usually exists in forked distros
    88  	if command_exists lsb_release; then
    89  		# Check if the `-u` option is supported
    90  		set +e
    91  		lsb_release -a -u > /dev/null 2>&1
    92  		lsb_release_exit_code=$?
    93  		set -e
    94  
    95  		# Check if the command has exited successfully, it means we're in a forked distro
    96  		if [ "$lsb_release_exit_code" = "0" ]; then
    97  			# Print info about current distro
    98  			cat <<-EOF
    99  			You're using '$lsb_dist' version '$dist_version'.
   100  			EOF
   101  
   102  			# Get the upstream release info
   103  			lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]')
   104  			dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]')
   105  
   106  			# Print info about upstream distro
   107  			cat <<-EOF
   108  			Upstream release is '$lsb_dist' version '$dist_version'.
   109  			EOF
   110  		else
   111  			if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
   112  				# We're Debian and don't even know it!
   113  				lsb_dist=debian
   114  				dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
   115  				case "$dist_version" in
   116  					8|'Kali Linux 2')
   117  						dist_version="jessie"
   118  					;;
   119  					7)
   120  						dist_version="wheezy"
   121  					;;
   122  				esac
   123  			fi
   124  		fi
   125  	fi
   126  }
   127  
   128  rpm_import_repository_key() {
   129  	local key=$1; shift
   130  	local tmpdir=$(mktemp -d)
   131  	chmod 600 "$tmpdir"
   132  	for key_server in $key_servers ; do
   133  		gpg --homedir "$tmpdir" --keyserver "$key_server" --recv-keys "$key" && break
   134  	done
   135  	gpg --homedir "$tmpdir" -k "$key" >/dev/null
   136  	gpg --homedir "$tmpdir" --export --armor "$key" > "$tmpdir"/repo.key
   137  	rpm --import "$tmpdir"/repo.key
   138  	rm -rf "$tmpdir"
   139  }
   140  
   141  semverParse() {
   142  	major="${1%%.*}"
   143  	minor="${1#$major.}"
   144  	minor="${minor%%.*}"
   145  	patch="${1#$major.$minor.}"
   146  	patch="${patch%%[-.]*}"
   147  }
   148  
   149  do_install() {
   150  	case "$(uname -m)" in
   151  		*64)
   152  			;;
   153  		armv6l|armv7l)
   154  			;;
   155  		*)
   156  			cat >&2 <<-'EOF'
   157  			Error: you are not using a 64bit platform or a Raspberry Pi (armv6l/armv7l).
   158  			Docker currently only supports 64bit platforms or a Raspberry Pi (armv6l/armv7l).
   159  			EOF
   160  			exit 1
   161  			;;
   162  	esac
   163  
   164  	if command_exists docker; then
   165  		version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
   166  		MAJOR_W=1
   167  		MINOR_W=10
   168  
   169  		semverParse $version
   170  
   171  		shouldWarn=0
   172  		if [ $major -lt $MAJOR_W ]; then
   173  			shouldWarn=1
   174  		fi
   175  
   176  		if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then
   177  			shouldWarn=1
   178  		fi
   179  
   180  		cat >&2 <<-'EOF'
   181  			Warning: the "docker" command appears to already exist on this system.
   182  
   183  			If you already have Docker installed, this script can cause trouble, which is
   184  			why we're displaying this warning and provide the opportunity to cancel the
   185  			installation.
   186  
   187  			If you installed the current Docker package using this script and are using it
   188  		EOF
   189  
   190  		if [ $shouldWarn -eq 1 ]; then
   191  			cat >&2 <<-'EOF'
   192  			again to update Docker, we urge you to migrate your image store before upgrading
   193  			to v1.10+.
   194  
   195  			You can find instructions for this here:
   196  			https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
   197  			EOF
   198  		else
   199  			cat >&2 <<-'EOF'
   200  			again to update Docker, you can safely ignore this message.
   201  			EOF
   202  		fi
   203  
   204  		cat >&2 <<-'EOF'
   205  
   206  			You may press Ctrl+C now to abort this script.
   207  		EOF
   208  		( set -x; sleep 20 )
   209  	fi
   210  
   211  	user="$(id -un 2>/dev/null || true)"
   212  
   213  	sh_c='sh -c'
   214  	if [ "$user" != 'root' ]; then
   215  		if command_exists sudo; then
   216  			sh_c='sudo -E sh -c'
   217  		elif command_exists su; then
   218  			sh_c='su -c'
   219  		else
   220  			cat >&2 <<-'EOF'
   221  			Error: this installer needs the ability to run commands as root.
   222  			We are unable to find either "sudo" or "su" available to make this happen.
   223  			EOF
   224  			exit 1
   225  		fi
   226  	fi
   227  
   228  	curl=''
   229  	if command_exists curl; then
   230  		curl='curl -sSL'
   231  	elif command_exists wget; then
   232  		curl='wget -qO-'
   233  	elif command_exists busybox && busybox --list-modules | grep -q wget; then
   234  		curl='busybox wget -qO-'
   235  	fi
   236  
   237  	# check to see which repo they are trying to install from
   238  	if [ -z "$repo" ]; then
   239  		repo='main'
   240  		if [ "https://test.docker.com/" = "$url" ]; then
   241  			repo='testing'
   242  		elif [ "https://experimental.docker.com/" = "$url" ]; then
   243  			repo='experimental'
   244  		fi
   245  	fi
   246  
   247  	# perform some very rudimentary platform detection
   248  	lsb_dist=''
   249  	dist_version=''
   250  	if command_exists lsb_release; then
   251  		lsb_dist="$(lsb_release -si)"
   252  	fi
   253  	if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
   254  		lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
   255  	fi
   256  	if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
   257  		lsb_dist='debian'
   258  	fi
   259  	if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
   260  		lsb_dist='fedora'
   261  	fi
   262  	if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then
   263  		lsb_dist='oracleserver'
   264  	fi
   265  	if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then
   266  		lsb_dist='centos'
   267  	fi
   268  	if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then
   269  		lsb_dist='redhat'
   270  	fi
   271  	if [ -z "$lsb_dist" ] && [ -r /etc/photon-release ]; then
   272  		lsb_dist='photon'
   273  	fi
   274  	if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
   275  		lsb_dist="$(. /etc/os-release && echo "$ID")"
   276  	fi
   277  
   278  	lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
   279  
   280  	# Special case redhatenterpriseserver
   281  	if [ "${lsb_dist}" = "redhatenterpriseserver" ]; then
   282          	# Set it to redhat, it will be changed to centos below anyways
   283          	lsb_dist='redhat'
   284  	fi
   285  
   286  	case "$lsb_dist" in
   287  
   288  		ubuntu)
   289  			if command_exists lsb_release; then
   290  				dist_version="$(lsb_release --codename | cut -f2)"
   291  			fi
   292  			if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
   293  				dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
   294  			fi
   295  		;;
   296  
   297  		debian|raspbian)
   298  			dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
   299  			case "$dist_version" in
   300  				8)
   301  					dist_version="jessie"
   302  				;;
   303  				7)
   304  					dist_version="wheezy"
   305  				;;
   306  			esac
   307  		;;
   308  
   309  		oracleserver)
   310  			# need to switch lsb_dist to match yum repo URL
   311  			lsb_dist="oraclelinux"
   312  			dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
   313  		;;
   314  
   315  		fedora|centos|redhat)
   316  			dist_version="$(rpm -q --whatprovides ${lsb_dist}-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//' | sort | tail -1)"
   317  		;;
   318  
   319  		"vmware photon")
   320  			lsb_dist="photon"
   321  			dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   322  		;;
   323  
   324  		*)
   325  			if command_exists lsb_release; then
   326  				dist_version="$(lsb_release --codename | cut -f2)"
   327  			fi
   328  			if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   329  				dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   330  			fi
   331  		;;
   332  
   333  
   334  	esac
   335  
   336  	# Check if this is a forked Linux distro
   337  	check_forked
   338  
   339  	# Run setup for each distro accordingly
   340  	case "$lsb_dist" in
   341  		amzn)
   342  			(
   343  			set -x
   344  			$sh_c 'sleep 3; yum -y -q install docker'
   345  			)
   346  			echo_docker_as_nonroot
   347  			exit 0
   348  			;;
   349  
   350  		'opensuse project'|opensuse)
   351  			echo 'Going to perform the following operations:'
   352  			if [ "$repo" != 'main' ]; then
   353  				echo '  * add repository obs://Virtualization:containers'
   354  			fi
   355  			echo '  * install Docker'
   356  			$sh_c 'echo "Press CTRL-C to abort"; sleep 3'
   357  
   358  			if [ "$repo" != 'main' ]; then
   359  				# install experimental packages from OBS://Virtualization:containers
   360  				(
   361  					set -x
   362  					zypper -n ar -f obs://Virtualization:containers Virtualization:containers
   363  					rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
   364  				)
   365  			fi
   366  			(
   367  				set -x
   368  				zypper -n install docker
   369  			)
   370  			echo_docker_as_nonroot
   371  			exit 0
   372  			;;
   373  		'suse linux'|sle[sd])
   374  			echo 'Going to perform the following operations:'
   375  			if [ "$repo" != 'main' ]; then
   376  				echo '  * add repository obs://Virtualization:containers'
   377  				echo '  * install experimental Docker using packages NOT supported by SUSE'
   378  			else
   379  				echo '  * add the "Containers" module'
   380  				echo '  * install Docker using packages supported by SUSE'
   381  			fi
   382  			$sh_c 'echo "Press CTRL-C to abort"; sleep 3'
   383  
   384  			if [ "$repo" != 'main' ]; then
   385  				# install experimental packages from OBS://Virtualization:containers
   386  				echo >&2 'Warning: installing experimental packages from OBS, these packages are NOT supported by SUSE'
   387  				(
   388  					set -x
   389  					zypper -n ar -f obs://Virtualization:containers/SLE_12 Virtualization:containers
   390  					rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
   391  				)
   392  			else
   393  				# Add the containers module
   394  				# Note well-1: the SLE machine must already be registered against SUSE Customer Center
   395  				# Note well-2: the `-r ""` is required to workaround a known issue of SUSEConnect
   396  				(
   397  					set -x
   398  					SUSEConnect -p sle-module-containers/12/x86_64 -r ""
   399  				)
   400  			fi
   401  			(
   402  				set -x
   403  				zypper -n install docker
   404  			)
   405  			echo_docker_as_nonroot
   406  			exit 0
   407  			;;
   408  
   409  		ubuntu|debian|raspbian)
   410  			export DEBIAN_FRONTEND=noninteractive
   411  
   412  			did_apt_get_update=
   413  			apt_get_update() {
   414  				if [ -z "$did_apt_get_update" ]; then
   415  					( set -x; $sh_c 'sleep 3; apt-get update' )
   416  					did_apt_get_update=1
   417  				fi
   418  			}
   419  
   420  			if [ "$lsb_dist" != "raspbian" ]; then
   421  				# aufs is preferred over devicemapper; try to ensure the driver is available.
   422  				if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
   423  					if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then
   424  						kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
   425  
   426  						apt_get_update
   427  						( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
   428  
   429  						if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
   430  							echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
   431  							echo >&2 ' but we still have no AUFS.  Docker may not work. Proceeding anyways!'
   432  							( set -x; sleep 10 )
   433  						fi
   434  					else
   435  						echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
   436  						echo >&2 ' package.  We have no AUFS support.  Consider installing the packages'
   437  						echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
   438  						( set -x; sleep 10 )
   439  					fi
   440  				fi
   441  			fi
   442  
   443  			# install apparmor utils if they're missing and apparmor is enabled in the kernel
   444  			# otherwise Docker will fail to start
   445  			if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
   446  				if command -v apparmor_parser >/dev/null 2>&1; then
   447  					echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
   448  				else
   449  					echo 'apparmor is enabled in the kernel, but apparmor_parser is missing. Trying to install it..'
   450  					apt_get_update
   451  					( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
   452  				fi
   453  			fi
   454  
   455  			if [ ! -e /usr/lib/apt/methods/https ]; then
   456  				apt_get_update
   457  				( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
   458  			fi
   459  			if [ -z "$curl" ]; then
   460  				apt_get_update
   461  				( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
   462  				curl='curl -sSL'
   463  			fi
   464  			if [ ! -e /usr/bin/gpg ]; then
   465  				apt_get_update
   466  				( set -x; $sh_c 'sleep 3; apt-get install -y -q gnupg2 || apt-get install -y -q gnupg' )
   467  			fi
   468  
   469  			(
   470  			set -x
   471  			for key_server in $key_servers ; do
   472  				$sh_c "apt-key adv --keyserver hkp://${key_server}:80 --recv-keys ${gpg_fingerprint}" && break
   473  			done
   474  			$sh_c "apt-key adv -k ${gpg_fingerprint} >/dev/null"
   475  			$sh_c "mkdir -p /etc/apt/sources.list.d"
   476  			$sh_c "echo deb \[arch=$(dpkg --print-architecture)\] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
   477  			$sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine'
   478  			)
   479  			echo_docker_as_nonroot
   480  			exit 0
   481  			;;
   482  
   483  		fedora|centos|redhat|oraclelinux|photon)
   484  			if [ "${lsb_dist}" = "redhat" ]; then
   485  				# we use the centos repository for both redhat and centos releases
   486  				lsb_dist='centos'
   487  			fi
   488  			$sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
   489  			[docker-${repo}-repo]
   490  			name=Docker ${repo} Repository
   491  			baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version}
   492  			enabled=1
   493  			gpgcheck=1
   494  			gpgkey=${yum_url}/gpg
   495  			EOF
   496  			if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
   497  				(
   498  					set -x
   499  					$sh_c 'sleep 3; dnf -y -q install docker-engine'
   500  				)
   501  			elif [ "$lsb_dist" = "photon" ]; then
   502  				(
   503  					set -x
   504  					$sh_c 'sleep 3; tdnf -y install docker-engine'
   505  				)
   506  			else
   507  				(
   508  					set -x
   509  					$sh_c 'sleep 3; yum -y -q install docker-engine'
   510  				)
   511  			fi
   512  			echo_docker_as_nonroot
   513  			exit 0
   514  			;;
   515  		gentoo)
   516  			if [ "$url" = "https://test.docker.com/" ]; then
   517  				# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
   518  				cat >&2 <<-'EOF'
   519  
   520  				  You appear to be trying to install the latest nightly build in Gentoo.'
   521  				  The portage tree should contain the latest stable release of Docker, but'
   522  				  if you want something more recent, you can always use the live ebuild'
   523  				  provided in the "docker" overlay available via layman.  For more'
   524  				  instructions, please see the following URL:'
   525  
   526  				    https://github.com/tianon/docker-overlay#using-this-overlay'
   527  
   528  				  After adding the "docker" overlay, you should be able to:'
   529  
   530  				    emerge -av =app-emulation/docker-9999'
   531  
   532  				EOF
   533  				exit 1
   534  			fi
   535  
   536  			(
   537  				set -x
   538  				$sh_c 'sleep 3; emerge app-emulation/docker'
   539  			)
   540  			exit 0
   541  			;;
   542  	esac
   543  
   544  	# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
   545  	cat >&2 <<-'EOF'
   546  
   547  	  Either your platform is not easily detectable, is not supported by this
   548  	  installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
   549  	  a package for Docker.  Please visit the following URL for more detailed
   550  	  installation instructions:
   551  
   552  	    https://docs.docker.com/engine/installation/
   553  
   554  	EOF
   555  	exit 1
   556  }
   557  
   558  # wrapped up in a function so that we have some protection against only getting
   559  # half the file during "curl | sh"
   560  do_install