install.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. user="$(id -un 2>/dev/null || true)"
  36. sh_c='sh -c'
  37. if [ "$user" != 'root' ]; then
  38. if command_exists sudo; then
  39. sh_c='sudo sh -c'
  40. elif command_exists su; then
  41. sh_c='su -c'
  42. else
  43. echo >&2 'Error: this installer needs the ability to run commands as root.'
  44. echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
  45. exit 1
  46. fi
  47. fi
  48. curl=''
  49. if command_exists curl; then
  50. curl='curl -sL'
  51. elif command_exists wget; then
  52. curl='wget -qO-'
  53. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  54. curl='busybox wget -qO-'
  55. fi
  56. # perform some very rudimentary platform detection
  57. lsb_dist=''
  58. if command_exists lsb_release; then
  59. lsb_dist="$(lsb_release -si)"
  60. fi
  61. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  62. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  63. fi
  64. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  65. lsb_dist='Debian'
  66. fi
  67. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  68. lsb_dist='Fedora'
  69. fi
  70. case "$lsb_dist" in
  71. Fedora)
  72. (
  73. set -x
  74. $sh_c 'sleep 3; yum -y -q install docker-io'
  75. )
  76. if command_exists docker && [ -e /var/run/docker.sock ]; then
  77. (
  78. set -x
  79. $sh_c 'docker run busybox echo "Docker has been successfully installed!"'
  80. ) || true
  81. fi
  82. your_user=your-user
  83. [ "$user" != 'root' ] && your_user="$user"
  84. echo
  85. echo 'If you would like to use Docker as a non-root user, you should now consider'
  86. echo 'adding your user to the "docker" group with something like:'
  87. echo
  88. echo ' sudo usermod -aG docker' $your_user
  89. echo
  90. echo 'Remember that you will have to log out and back in for this to take effect!'
  91. echo
  92. exit 0
  93. ;;
  94. Ubuntu|Debian)
  95. export DEBIAN_FRONTEND=noninteractive
  96. did_apt_get_update=
  97. apt_get_update() {
  98. if [ -z "$did_apt_get_update" ]; then
  99. ( set -x; $sh_c 'sleep 3; apt-get update' )
  100. did_apt_get_update=1
  101. fi
  102. }
  103. # aufs is preferred over devicemapper; try to ensure the driver is available.
  104. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  105. kern_extras="linux-image-extra-$(uname -r)"
  106. apt_get_update
  107. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  108. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  109. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  110. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  111. ( set -x; sleep 10 )
  112. fi
  113. fi
  114. if [ ! -e /usr/lib/apt/methods/https ]; then
  115. apt_get_update
  116. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https' )
  117. fi
  118. if [ -z "$curl" ]; then
  119. apt_get_update
  120. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl' )
  121. curl='curl -sL'
  122. fi
  123. (
  124. set -x
  125. if [ "https://get.docker.io/" = "$url" ]; then
  126. $sh_c "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9"
  127. elif [ "https://test.docker.io/" = "$url" ]; then
  128. $sh_c "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 740B314AE3941731B942C66ADF4FD13717AAD7D6"
  129. else
  130. $sh_c "$curl ${url}gpg | apt-key add -"
  131. fi
  132. $sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list"
  133. $sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker'
  134. )
  135. if command_exists docker && [ -e /var/run/docker.sock ]; then
  136. (
  137. set -x
  138. $sh_c 'docker run busybox echo "Docker has been successfully installed!"'
  139. ) || true
  140. fi
  141. your_user=your-user
  142. [ "$user" != 'root' ] && your_user="$user"
  143. echo
  144. echo 'If you would like to use Docker as a non-root user, you should now consider'
  145. echo 'adding your user to the "docker" group with something like:'
  146. echo
  147. echo ' sudo usermod -aG docker' $your_user
  148. echo
  149. echo 'Remember that you will have to log out and back in for this to take effect!'
  150. echo
  151. exit 0
  152. ;;
  153. Gentoo)
  154. if [ "$url" = "https://test.docker.io/" ]; then
  155. echo >&2
  156. echo >&2 ' You appear to be trying to install the latest nightly build in Gentoo.'
  157. echo >&2 ' The portage tree should contain the latest stable release of Docker, but'
  158. echo >&2 ' if you want something more recent, you can always use the live ebuild'
  159. echo >&2 ' provided in the "docker" overlay available via layman. For more'
  160. echo >&2 ' instructions, please see the following URL:'
  161. echo >&2 ' https://github.com/tianon/docker-overlay#using-this-overlay'
  162. echo >&2 ' After adding the "docker" overlay, you should be able to:'
  163. echo >&2 ' emerge -av =app-emulation/docker-9999'
  164. echo >&2
  165. exit 1
  166. fi
  167. (
  168. set -x
  169. $sh_c 'sleep 3; emerge app-emulation/docker'
  170. )
  171. exit 0
  172. ;;
  173. esac
  174. echo >&2
  175. echo >&2 ' Either your platform is not easily detectable, is not supported by this'
  176. echo >&2 ' installer script (yet - PRs welcome!), or does not yet have a package for'
  177. echo >&2 ' Docker. Please visit the following URL for more detailed installation'
  178. echo >&2 ' instructions:'
  179. echo >&2
  180. echo >&2 ' http://docs.docker.io/en/latest/installation/'
  181. echo >&2
  182. exit 1