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