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