install.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/bin/sh
  2. set -e
  3. #
  4. # This script is meant for quick & easy install via:
  5. # 'curl -sL https://get.docker.io/ | sh'
  6. # or:
  7. # 'wget -qO- https://get.docker.io/ | sh'
  8. #
  9. #
  10. # Docker Maintainers:
  11. # To update this script on https://get.docker.io,
  12. # use hack/release.sh during a normal release,
  13. # or the following one-liner for script hotfixes:
  14. # s3cmd put --acl-public -P hack/install.sh s3://get.docker.io/index
  15. #
  16. url='https://get.docker.io/'
  17. command_exists() {
  18. command -v "$@" > /dev/null 2>&1
  19. }
  20. case "$(uname -m)" in
  21. *64)
  22. ;;
  23. *)
  24. echo >&2 'Error: you are not using a 64bit platform.'
  25. echo >&2 'Docker currently only supports 64bit platforms.'
  26. exit 1
  27. ;;
  28. esac
  29. if command_exists docker || command_exists lxc-docker; then
  30. echo >&2 'Warning: "docker" or "lxc-docker" command appears to already exist.'
  31. echo >&2 'Please ensure that you do not already have docker installed.'
  32. echo >&2 'You may press Ctrl+C now to abort this process and rectify this situation.'
  33. ( set -x; sleep 20 )
  34. fi
  35. sh_c='sh -c'
  36. if [ "$(whoami 2>/dev/null || true)" != 'root' ]; then
  37. if command_exists sudo; then
  38. sh_c='sudo sh -c'
  39. elif command_exists su; then
  40. sh_c='su -c'
  41. else
  42. echo >&2 'Error: this installer needs the ability to run commands as root.'
  43. echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
  44. exit 1
  45. fi
  46. fi
  47. curl=''
  48. if command_exists curl; then
  49. curl='curl -sL'
  50. elif command_exists wget; then
  51. curl='wget -qO-'
  52. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  53. curl='busybox wget -qO-'
  54. fi
  55. # perform some very rudimentary platform detection
  56. lsb_dist=''
  57. if command_exists lsb_release; then
  58. lsb_dist="$(lsb_release -si)"
  59. fi
  60. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  61. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  62. fi
  63. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  64. lsb_dist='Debian'
  65. fi
  66. case "$lsb_dist" in
  67. Ubuntu|Debian)
  68. export DEBIAN_FRONTEND=noninteractive
  69. did_apt_get_update=
  70. apt_get_update() {
  71. if [ -z "$did_apt_get_update" ]; then
  72. ( set -x; $sh_c 'sleep 3; apt-get update' )
  73. did_apt_get_update=1
  74. fi
  75. }
  76. # TODO remove this section once device-mapper lands
  77. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  78. kern_extras="linux-image-extra-$(uname -r)"
  79. apt_get_update
  80. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  81. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  82. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  83. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  84. ( set -x; sleep 10 )
  85. fi
  86. fi
  87. if [ ! -e /usr/lib/apt/methods/https ]; then
  88. apt_get_update
  89. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https' )
  90. fi
  91. if [ -z "$curl" ]; then
  92. apt_get_update
  93. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl' )
  94. curl='curl -sL'
  95. fi
  96. (
  97. set -x
  98. if [ "https://get.docker.io/" = "$url" ]; then
  99. $sh_c "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9"
  100. elif [ "https://test.docker.io/" = "$url" ]; then
  101. $sh_c "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 740B314AE3941731B942C66ADF4FD13717AAD7D6"
  102. else
  103. $sh_c "$curl ${url}gpg | apt-key add -"
  104. fi
  105. $sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list"
  106. $sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker'
  107. )
  108. if command_exists docker && [ -e /var/run/docker.sock ]; then
  109. (
  110. set -x
  111. $sh_c 'docker run busybox echo "Docker has been successfully installed!"'
  112. ) || true
  113. fi
  114. exit 0
  115. ;;
  116. Gentoo)
  117. if [ "$url" = "https://test.docker.io/" ]; then
  118. echo >&2
  119. echo >&2 ' You appear to be trying to install the latest nightly build in Gentoo.'
  120. echo >&2 ' The portage tree should contain the latest stable release of Docker, but'
  121. echo >&2 ' if you want something more recent, you can always use the live ebuild'
  122. echo >&2 ' provided in the "docker" overlay available via layman. For more'
  123. echo >&2 ' instructions, please see the following URL:'
  124. echo >&2 ' https://github.com/tianon/docker-overlay#using-this-overlay'
  125. echo >&2 ' After adding the "docker" overlay, you should be able to:'
  126. echo >&2 ' emerge -av =app-emulation/docker-9999'
  127. echo >&2
  128. exit 1
  129. fi
  130. (
  131. set -x
  132. $sh_c 'sleep 3; emerge app-emulation/docker'
  133. )
  134. exit 0
  135. ;;
  136. esac
  137. echo >&2
  138. echo >&2 ' Either your platform is not easily detectable, is not supported by this'
  139. echo >&2 ' installer script (yet - PRs welcome!), or does not yet have a package for'
  140. echo >&2 ' Docker. Please visit the following URL for more detailed installation'
  141. echo >&2 ' instructions:'
  142. echo >&2
  143. echo >&2 ' http://docs.docker.io/en/latest/installation/'
  144. echo >&2
  145. exit 1