github.com/damirazo/docker@v1.9.0/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  	# Check for lsb_release command existence, it usually exists in forked distros
    57  	if command_exists lsb_release; then
    58  		# Check if the `-u` option is supported
    59  		set +e
    60  		lsb_release -a -u > /dev/null 2>&1
    61  		lsb_release_exit_code=$?
    62  		set -e
    63  
    64  		# Check if the command has exited successfully, it means we're in a forked distro
    65  		if [ "$lsb_release_exit_code" = "0" ]; then
    66  			# Print info about current distro
    67  			cat <<-EOF
    68  			You're using '$lsb_dist' version '$dist_version'.
    69  			EOF
    70  
    71  			# Get the upstream release info
    72  			lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]')
    73  			dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]')
    74  
    75  			# Print info about upstream distro
    76  			cat <<-EOF
    77  			Upstream release is '$lsb_dist' version '$dist_version'.
    78  			EOF
    79  		fi
    80  	fi
    81  }
    82  
    83  do_install() {
    84  	case "$(uname -m)" in
    85  		*64)
    86  			;;
    87  		*)
    88  			cat >&2 <<-'EOF'
    89  			Error: you are not using a 64bit platform.
    90  			Docker currently only supports 64bit platforms.
    91  			EOF
    92  			exit 1
    93  			;;
    94  	esac
    95  
    96  	if command_exists docker; then
    97  		cat >&2 <<-'EOF'
    98  			Warning: the "docker" command appears to already exist on this system.
    99  
   100  			If you already have Docker installed, this script can cause trouble, which is
   101  			why we're displaying this warning and provide the opportunity to cancel the
   102  			installation.
   103  
   104  			If you installed the current Docker package using this script and are using it
   105  			again to update Docker, you can safely ignore this message.
   106  
   107  			You may press Ctrl+C now to abort this script.
   108  		EOF
   109  		( set -x; sleep 20 )
   110  	fi
   111  
   112  	user="$(id -un 2>/dev/null || true)"
   113  
   114  	sh_c='sh -c'
   115  	if [ "$user" != 'root' ]; then
   116  		if command_exists sudo; then
   117  			sh_c='sudo -E sh -c'
   118  		elif command_exists su; then
   119  			sh_c='su -c'
   120  		else
   121  			cat >&2 <<-'EOF'
   122  			Error: this installer needs the ability to run commands as root.
   123  			We are unable to find either "sudo" or "su" available to make this happen.
   124  			EOF
   125  			exit 1
   126  		fi
   127  	fi
   128  
   129  	curl=''
   130  	if command_exists curl; then
   131  		curl='curl -sSL'
   132  	elif command_exists wget; then
   133  		curl='wget -qO-'
   134  	elif command_exists busybox && busybox --list-modules | grep -q wget; then
   135  		curl='busybox wget -qO-'
   136  	fi
   137  
   138  	# check to see which repo they are trying to install from
   139  	repo='main'
   140  	if [ "https://test.docker.com/" = "$url" ]; then
   141  		repo='testing'
   142  	elif [ "https://experimental.docker.com/" = "$url" ]; then
   143  		repo='experimental'
   144  	fi
   145  
   146  	# perform some very rudimentary platform detection
   147  	lsb_dist=''
   148  	dist_version=''
   149  	if command_exists lsb_release; then
   150  		lsb_dist="$(lsb_release -si)"
   151  	fi
   152  	if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
   153  		lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
   154  	fi
   155  	if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
   156  		lsb_dist='debian'
   157  	fi
   158  	if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
   159  		lsb_dist='fedora'
   160  	fi
   161  	if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then
   162  		lsb_dist='oracleserver'
   163  	fi
   164  	if [ -z "$lsb_dist" ]; then
   165  		if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then
   166  			lsb_dist='centos'
   167  		fi
   168  	fi
   169  	if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
   170  		lsb_dist="$(. /etc/os-release && echo "$ID")"
   171  	fi
   172  
   173  	lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
   174  
   175  	case "$lsb_dist" in
   176  
   177  		ubuntu)
   178  			if command_exists lsb_release; then
   179  				dist_version="$(lsb_release --codename | cut -f2)"
   180  			fi
   181  			if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
   182  				dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
   183  			fi
   184  		;;
   185  
   186  		debian)
   187  			dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
   188  			case "$dist_version" in
   189  				8)
   190  					dist_version="jessie"
   191  				;;
   192  				7)
   193  					dist_version="wheezy"
   194  				;;
   195  			esac
   196  		;;
   197  
   198  		oracleserver)
   199  			# need to switch lsb_dist to match yum repo URL
   200  			lsb_dist="oraclelinux"
   201  			dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
   202  		;;
   203  
   204  		fedora|centos)
   205  			dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
   206  		;;
   207  
   208  		*)
   209  			if command_exists lsb_release; then
   210  				dist_version="$(lsb_release --codename | cut -f2)"
   211  			fi
   212  			if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   213  				dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   214  			fi
   215  		;;
   216  
   217  
   218  	esac
   219  
   220  	# Check if this is a forked Linux distro
   221  	check_forked
   222  
   223  	# Run setup for each distro accordingly
   224  	case "$lsb_dist" in
   225  		amzn)
   226  			(
   227  			set -x
   228  			$sh_c 'sleep 3; yum -y -q install docker'
   229  			)
   230  			echo_docker_as_nonroot
   231  			exit 0
   232  			;;
   233  
   234  		'opensuse project'|opensuse|'suse linux'|sle[sd])
   235  			(
   236  				set -x
   237  				$sh_c 'sleep 3; zypper -n install docker'
   238  			)
   239  			echo_docker_as_nonroot
   240  			exit 0
   241  			;;
   242  
   243  		ubuntu|debian)
   244  			export DEBIAN_FRONTEND=noninteractive
   245  
   246  			did_apt_get_update=
   247  			apt_get_update() {
   248  				if [ -z "$did_apt_get_update" ]; then
   249  					( set -x; $sh_c 'sleep 3; apt-get update' )
   250  					did_apt_get_update=1
   251  				fi
   252  			}
   253  
   254  			# aufs is preferred over devicemapper; try to ensure the driver is available.
   255  			if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
   256  				if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -q '^ii' 2>/dev/null; then
   257  					kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
   258  
   259  					apt_get_update
   260  					( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
   261  
   262  					if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
   263  						echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
   264  						echo >&2 ' but we still have no AUFS.  Docker may not work. Proceeding anyways!'
   265  						( set -x; sleep 10 )
   266  					fi
   267  				else
   268  					echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
   269  					echo >&2 ' package.  We have no AUFS support.  Consider installing the packages'
   270  					echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
   271  					( set -x; sleep 10 )
   272  				fi
   273  			fi
   274  
   275  			# install apparmor utils if they're missing and apparmor is enabled in the kernel
   276  			# otherwise Docker will fail to start
   277  			if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
   278  				if command -v apparmor_parser >/dev/null 2>&1; then
   279  					echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
   280  				else
   281  					echo 'apparmor is enabled in the kernel, but apparmor_parser missing'
   282  					apt_get_update
   283  					( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
   284  				fi
   285  			fi
   286  
   287  			if [ ! -e /usr/lib/apt/methods/https ]; then
   288  				apt_get_update
   289  				( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
   290  			fi
   291  			if [ -z "$curl" ]; then
   292  				apt_get_update
   293  				( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
   294  				curl='curl -sSL'
   295  			fi
   296  			(
   297  			set -x
   298  			$sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"
   299  			$sh_c "mkdir -p /etc/apt/sources.list.d"
   300  			$sh_c "echo deb https://apt.dockerproject.org/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
   301  			$sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine'
   302  			)
   303  			echo_docker_as_nonroot
   304  			exit 0
   305  			;;
   306  
   307  		fedora|centos|oraclelinux)
   308  			$sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
   309  			[docker-${repo}-repo]
   310  			name=Docker ${repo} Repository
   311  			baseurl=https://yum.dockerproject.org/repo/${repo}/${lsb_dist}/${dist_version}
   312  			enabled=1
   313  			gpgcheck=1
   314  			gpgkey=https://yum.dockerproject.org/gpg
   315  			EOF
   316  			if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
   317  				(
   318  					set -x
   319  					$sh_c 'sleep 3; dnf -y -q install docker-engine'
   320  				)
   321  			else
   322  				(
   323  					set -x
   324  					$sh_c 'sleep 3; yum -y -q install docker-engine'
   325  				)
   326  			fi
   327  			echo_docker_as_nonroot
   328  			exit 0
   329  			;;
   330  		gentoo)
   331  			if [ "$url" = "https://test.docker.com/" ]; then
   332  				# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
   333  				cat >&2 <<-'EOF'
   334  
   335  				  You appear to be trying to install the latest nightly build in Gentoo.'
   336  				  The portage tree should contain the latest stable release of Docker, but'
   337  				  if you want something more recent, you can always use the live ebuild'
   338  				  provided in the "docker" overlay available via layman.  For more'
   339  				  instructions, please see the following URL:'
   340  
   341  				    https://github.com/tianon/docker-overlay#using-this-overlay'
   342  
   343  				  After adding the "docker" overlay, you should be able to:'
   344  
   345  				    emerge -av =app-emulation/docker-9999'
   346  
   347  				EOF
   348  				exit 1
   349  			fi
   350  
   351  			(
   352  				set -x
   353  				$sh_c 'sleep 3; emerge app-emulation/docker'
   354  			)
   355  			exit 0
   356  			;;
   357  	esac
   358  
   359  	# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
   360  	cat >&2 <<-'EOF'
   361  
   362  	  Either your platform is not easily detectable, is not supported by this
   363  	  installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
   364  	  a package for Docker.  Please visit the following URL for more detailed
   365  	  installation instructions:
   366  
   367  	    https://docs.docker.com/en/latest/installation/
   368  
   369  	EOF
   370  	exit 1
   371  }
   372  
   373  # wrapped up in a function so that we have some protection against only getting
   374  # half the file during "curl | sh"
   375  do_install