install.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 -fsSL https://test.docker.com/ | sh'
  11. # or:
  12. # 'wget -qO- https://test.docker.com/ | sh'
  13. #
  14. # For experimental builds:
  15. # 'curl -fsSL 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. # aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index
  24. #
  25. url="https://get.docker.com/"
  26. apt_url="https://apt.dockerproject.org"
  27. yum_url="https://yum.dockerproject.org"
  28. docker_key="-----BEGIN PGP PUBLIC KEY BLOCK-----
  29. Version: GnuPG v1
  30. mQINBFWln24BEADrBl5p99uKh8+rpvqJ48u4eTtjeXAWbslJotmC/CakbNSqOb9o
  31. ddfzRvGVeJVERt/Q/mlvEqgnyTQy+e6oEYN2Y2kqXceUhXagThnqCoxcEJ3+KM4R
  32. mYdoe/BJ/J/6rHOjq7Omk24z2qB3RU1uAv57iY5VGw5p45uZB4C4pNNsBJXoCvPn
  33. TGAs/7IrekFZDDgVraPx/hdiwopQ8NltSfZCyu/jPpWFK28TR8yfVlzYFwibj5WK
  34. dHM7ZTqlA1tHIG+agyPf3Rae0jPMsHR6q+arXVwMccyOi+ULU0z8mHUJ3iEMIrpT
  35. X+80KaN/ZjibfsBOCjcfiJSB/acn4nxQQgNZigna32velafhQivsNREFeJpzENiG
  36. HOoyC6qVeOgKrRiKxzymj0FIMLru/iFF5pSWcBQB7PYlt8J0G80lAcPr6VCiN+4c
  37. NKv03SdvA69dCOj79PuO9IIvQsJXsSq96HB+TeEmmL+xSdpGtGdCJHHM1fDeCqkZ
  38. hT+RtBGQL2SEdWjxbF43oQopocT8cHvyX6Zaltn0svoGs+wX3Z/H6/8P5anog43U
  39. 65c0A+64Jj00rNDr8j31izhtQMRo892kGeQAaaxg4Pz6HnS7hRC+cOMHUU4HA7iM
  40. zHrouAdYeTZeZEQOA7SxtCME9ZnGwe2grxPXh/U/80WJGkzLFNcTKdv+rwARAQAB
  41. tDdEb2NrZXIgUmVsZWFzZSBUb29sIChyZWxlYXNlZG9ja2VyKSA8ZG9ja2VyQGRv
  42. Y2tlci5jb20+iQIcBBABCgAGBQJWw7vdAAoJEFyzYeVS+w0QHysP/i37m4SyoOCV
  43. cnybl18vzwBEcp4VCRbXvHvOXty1gccVIV8/aJqNKgBV97lY3vrpOyiIeB8ETQeg
  44. srxFE7t/Gz0rsLObqfLEHdmn5iBJRkhLfCpzjeOnyB3Z0IJB6UogO/msQVYe5CXJ
  45. l6uwr0AmoiCBLrVlDAktxVh9RWch0l0KZRX2FpHu8h+uM0/zySqIidlYfLa3y5oH
  46. scU+nGU1i6ImwDTD3ysZC5jp9aVfvUmcESyAb4vvdcAHR+bXhA/RW8QHeeMFliWw
  47. 7Z2jYHyuHmDnWG2yUrnCqAJTrWV+OfKRIzzJFBs4e88ru5h2ZIXdRepw/+COYj34
  48. LyzxR2cxr2u/xvxwXCkSMe7F4KZAphD+1ws61FhnUMi/PERMYfTFuvPrCkq4gyBj
  49. t3fFpZ2NR/fKW87QOeVcn1ivXl9id3MMs9KXJsg7QasT7mCsee2VIFsxrkFQ2jNp
  50. D+JAERRn9Fj4ArHL5TbwkkFbZZvSi6fr5h2GbCAXIGhIXKnjjorPY/YDX6X8AaHO
  51. W1zblWy/CFr6VFl963jrjJgag0G6tNtBZLrclZgWhOQpeZZ5Lbvz2ZA5CqRrfAVc
  52. wPNW1fObFIRtqV6vuVluFOPCMAAnOnqR02w9t17iVQjO3oVN0mbQi9vjuExXh1Yo
  53. ScVetiO6LSmlQfVEVRTqHLMgXyR/EMo7iQIcBBABCgAGBQJXSWBlAAoJEFyzYeVS
  54. +w0QeH0QAI6btAfYwYPuAjfRUy9qlnPhZ+xt1rnwsUzsbmo8K3XTNh+l/R08nu0d
  55. sczw30Q1wju28fh1N8ay223+69f0+yICaXqR18AbGgFGKX7vo0gfEVaxdItUN3eH
  56. NydGFzmeOKbAlrxIMECnSTG/TkFVYO9Ntlv9vSN2BupmTagTRErxLZKnVsWRzp+X
  57. elwlgU5BCZ6U6Ze8+bIc6F1bZstf17X8i6XNV/rOCLx2yP0hn1osoljoLPpW8nzk
  58. wvqYsYbCA28lMt1aqe0UWvRCqR0zxlKn17NZQqjbxcajEMCajoQ01MshmO5GWePV
  59. iv2abCZ/iaC5zKqVT3deMJHLq7lum6qhA41E9gJH9QoqT+qgadheeFfoC1QP7cke
  60. +tXmYg2R39p3l5Hmm+JQbP4f9V5mpWExvHGCSbcatr35tnakIJZugq2ogzsm1djC
  61. Sz9222RXl9OoFqsm1bNzA78+/cOt5N2cyhU0bM2T/zgh42YbDD+JDU/HSmxUIpU+
  62. wrGvZGM2FU/up0DRxOC4U1fL6HHlj8liNJWfEg3vhougOh66gGF9ik5j4eIlNoz6
  63. lst+gmvlZQ9/9hRDeoG+AbhZeIlQ4CCw+Y1j/+fUxIzKHPVK+aFJd+oJVNvbojJW
  64. /SgDdSMtFwqOvXyYcHl30Ws0gZUeDyAmNGZeJ3kFklnApDmeKK+OiQIiBBABCgAM
  65. BQJXe5zTBYMHhh+AAAoJEDG4FaMBBnSp7YMQAJqrXoBonZAq07B6qUaT3aBCgnY4
  66. JshbXmFb/XrrS75f7YJDPx2fJJdqrbYDIHHgOjzxvp3ngPpOpJzI5sYmkaugeoCO
  67. /KHu/+39XqgTB7fguzapRfbvuWp+qzPcHSdb9opnagfzKAze3DQnnLiwCPlsyvGp
  68. zC4KzXgV2ze/4raaOye1kK7O0cHyapmn/q/TR3S8YapyXq5VpLThwJAw1SRDu0Yx
  69. eXIAQiIfaSxT79EktoioW2CSV8/djt+gBjXnKYJJA8P1zzX7GNt/Rc2YG0Ot4v6t
  70. BW16xqFTg+n5JzbeK5cZ1jbIXXfCcaZJyiM2MzYGhSJ9+EV7JYF05OAIWE4SGTRj
  71. XMquQ2oMLSwMCPQHm+FCD9PXQ0tHYx6tKT34wksdmoWsdejl/n3NS+178mG1WI/l
  72. N079h3im2gRwOykMou/QWs3vGw/xDoOYHPV2gJ7To9BLVnVK/hROgdFLZFeyRScN
  73. zwKm57HmYMFA74tX601OiHhk1ymP2UUc25oDWpLXlfcRULJJlo/KfZZF3pmKwIq3
  74. CilGayFUi1NNwuavG76EcAVtVFUVFFIITwkhkuRbBHIytzEHYosFgD5/acK0Pauq
  75. JnwrwKv0nWq3aK7nKiALAD+iZvPNjFZau3/APqLEmvmRnAElmugcHsWREFxMMjMM
  76. VgYFiYKUAJO8u46eiQI4BBMBAgAiBQJVpZ9uAhsvBgsJCAcDAgYVCAIJCgsEFgID
  77. AQIeAQIXgAAKCRD3YiFXLFJgnbRfEAC9Uai7Rv20QIDlDogRzd+Vebg4ahyoUdj0
  78. CH+nAk40RIoq6G26u1e+sdgjpCa8jF6vrx+smpgd1HeJdmpahUX0XN3X9f9qU9oj
  79. 9A4I1WDalRWJh+tP5WNv2ySy6AwcP9QnjuBMRTnTK27pk1sEMg9oJHK5p+ts8hlS
  80. C4SluyMKH5NMVy9c+A9yqq9NF6M6d6/ehKfBFFLG9BX+XLBATvf1ZemGVHQusCQe
  81. bTGv0C0V9yqtdPdRWVIEhHxyNHATaVYOafTj/EF0lDxLl6zDT6trRV5n9F1VCEh4
  82. Aal8L5MxVPcIZVO7NHT2EkQgn8CvWjV3oKl2GopZF8V4XdJRl90U/WDv/6cmfI08
  83. GkzDYBHhS8ULWRFwGKobsSTyIvnbk4NtKdnTGyTJCQ8+6i52s+C54PiNgfj2ieNn
  84. 6oOR7d+bNCcG1CdOYY+ZXVOcsjl73UYvtJrO0Rl/NpYERkZ5d/tzw4jZ6FCXgggA
  85. /Zxcjk6Y1ZvIm8Mt8wLRFH9Nww+FVsCtaCXJLP8DlJLASMD9rl5QS9Ku3u7ZNrr5
  86. HWXPHXITX660jglyshch6CWeiUATqjIAzkEQom/kEnOrvJAtkypRJ59vYQOedZ1s
  87. FVELMXg2UCkD/FwojfnVtjzYaTCeGwFQeqzHmM241iuOmBYPeyTY5veF49aBJA1g
  88. EJOQTvBR8Q==
  89. =Yhur
  90. -----END PGP PUBLIC KEY BLOCK-----
  91. "
  92. mirror=''
  93. while [ $# -gt 0 ]; do
  94. case "$1" in
  95. --mirror)
  96. mirror="$2"
  97. shift
  98. ;;
  99. *)
  100. echo "Illegal option $1"
  101. ;;
  102. esac
  103. shift $(( $# > 0 ? 1 : 0 ))
  104. done
  105. case "$mirror" in
  106. AzureChinaCloud)
  107. apt_url="https://mirror.azure.cn/docker-engine/apt"
  108. yum_url="https://mirror.azure.cn/docker-engine/yum"
  109. ;;
  110. esac
  111. command_exists() {
  112. command -v "$@" > /dev/null 2>&1
  113. }
  114. echo_docker_as_nonroot() {
  115. if command_exists docker && [ -e /var/run/docker.sock ]; then
  116. (
  117. set -x
  118. $sh_c 'docker version'
  119. ) || true
  120. fi
  121. your_user=your-user
  122. [ "$user" != 'root' ] && your_user="$user"
  123. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
  124. cat <<-EOF
  125. If you would like to use Docker as a non-root user, you should now consider
  126. adding your user to the "docker" group with something like:
  127. sudo usermod -aG docker $your_user
  128. Remember that you will have to log out and back in for this to take effect!
  129. WARNING: Adding a user to the "docker" group will grant the ability to run
  130. containers which can be used to obtain root privileges on the
  131. docker host.
  132. Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
  133. for more information.
  134. EOF
  135. }
  136. # Check if this is a forked Linux distro
  137. check_forked() {
  138. # Check for lsb_release command existence, it usually exists in forked distros
  139. if command_exists lsb_release; then
  140. # Check if the `-u` option is supported
  141. set +e
  142. lsb_release -a -u > /dev/null 2>&1
  143. lsb_release_exit_code=$?
  144. set -e
  145. # Check if the command has exited successfully, it means we're in a forked distro
  146. if [ "$lsb_release_exit_code" = "0" ]; then
  147. # Print info about current distro
  148. cat <<-EOF
  149. You're using '$lsb_dist' version '$dist_version'.
  150. EOF
  151. # Get the upstream release info
  152. lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  153. dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  154. # Print info about upstream distro
  155. cat <<-EOF
  156. Upstream release is '$lsb_dist' version '$dist_version'.
  157. EOF
  158. else
  159. if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
  160. # We're Debian and don't even know it!
  161. lsb_dist=debian
  162. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  163. case "$dist_version" in
  164. 9)
  165. dist_version="stretch"
  166. ;;
  167. 8|'Kali Linux 2')
  168. dist_version="jessie"
  169. ;;
  170. 7)
  171. dist_version="wheezy"
  172. ;;
  173. esac
  174. fi
  175. fi
  176. fi
  177. }
  178. semverParse() {
  179. major="${1%%.*}"
  180. minor="${1#$major.}"
  181. minor="${minor%%.*}"
  182. patch="${1#$major.$minor.}"
  183. patch="${patch%%[-.]*}"
  184. }
  185. do_install() {
  186. architecture=$(uname -m)
  187. case $architecture in
  188. # officially supported
  189. amd64|x86_64)
  190. ;;
  191. # unofficially supported with available repositories
  192. armv6l|armv7l)
  193. ;;
  194. # unofficially supported without available repositories
  195. aarch64|arm64|ppc64le|s390x)
  196. cat 1>&2 <<-EOF
  197. Error: This install script does not support $architecture, because no
  198. $architecture package exists in Docker's repositories.
  199. Other install options include checking your distribution's package repository
  200. for a version of Docker, or building Docker from source.
  201. EOF
  202. exit 1
  203. ;;
  204. # not supported
  205. *)
  206. cat >&2 <<-EOF
  207. Error: $architecture is not a recognized platform.
  208. EOF
  209. exit 1
  210. ;;
  211. esac
  212. if command_exists docker; then
  213. version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
  214. MAJOR_W=1
  215. MINOR_W=10
  216. semverParse $version
  217. shouldWarn=0
  218. if [ $major -lt $MAJOR_W ]; then
  219. shouldWarn=1
  220. fi
  221. if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then
  222. shouldWarn=1
  223. fi
  224. cat >&2 <<-'EOF'
  225. Warning: the "docker" command appears to already exist on this system.
  226. If you already have Docker installed, this script can cause trouble, which is
  227. why we're displaying this warning and provide the opportunity to cancel the
  228. installation.
  229. If you installed the current Docker package using this script and are using it
  230. EOF
  231. if [ $shouldWarn -eq 1 ]; then
  232. cat >&2 <<-'EOF'
  233. again to update Docker, we urge you to migrate your image store before upgrading
  234. to v1.10+.
  235. You can find instructions for this here:
  236. https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
  237. EOF
  238. else
  239. cat >&2 <<-'EOF'
  240. again to update Docker, you can safely ignore this message.
  241. EOF
  242. fi
  243. cat >&2 <<-'EOF'
  244. You may press Ctrl+C now to abort this script.
  245. EOF
  246. ( set -x; sleep 20 )
  247. fi
  248. user="$(id -un 2>/dev/null || true)"
  249. sh_c='sh -c'
  250. if [ "$user" != 'root' ]; then
  251. if command_exists sudo; then
  252. sh_c='sudo -E sh -c'
  253. elif command_exists su; then
  254. sh_c='su -c'
  255. else
  256. cat >&2 <<-'EOF'
  257. Error: this installer needs the ability to run commands as root.
  258. We are unable to find either "sudo" or "su" available to make this happen.
  259. EOF
  260. exit 1
  261. fi
  262. fi
  263. curl=''
  264. if command_exists curl; then
  265. curl='curl -sSL'
  266. elif command_exists wget; then
  267. curl='wget -qO-'
  268. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  269. curl='busybox wget -qO-'
  270. fi
  271. # check to see which repo they are trying to install from
  272. if [ -z "$repo" ]; then
  273. repo='main'
  274. if [ "https://test.docker.com/" = "$url" ]; then
  275. repo='testing'
  276. elif [ "https://experimental.docker.com/" = "$url" ]; then
  277. repo='experimental'
  278. fi
  279. fi
  280. # perform some very rudimentary platform detection
  281. lsb_dist=''
  282. dist_version=''
  283. if command_exists lsb_release; then
  284. lsb_dist="$(lsb_release -si)"
  285. fi
  286. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  287. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  288. fi
  289. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  290. lsb_dist='debian'
  291. fi
  292. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  293. lsb_dist='fedora'
  294. fi
  295. if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then
  296. lsb_dist='oracleserver'
  297. fi
  298. if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then
  299. lsb_dist='centos'
  300. fi
  301. if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then
  302. lsb_dist='redhat'
  303. fi
  304. if [ -z "$lsb_dist" ] && [ -r /etc/photon-release ]; then
  305. lsb_dist='photon'
  306. fi
  307. if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
  308. lsb_dist="$(. /etc/os-release && echo "$ID")"
  309. fi
  310. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  311. # Special case redhatenterpriseserver
  312. if [ "${lsb_dist}" = "redhatenterpriseserver" ]; then
  313. # Set it to redhat, it will be changed to centos below anyways
  314. lsb_dist='redhat'
  315. fi
  316. case "$lsb_dist" in
  317. ubuntu)
  318. if command_exists lsb_release; then
  319. dist_version="$(lsb_release --codename | cut -f2)"
  320. fi
  321. if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
  322. dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
  323. fi
  324. ;;
  325. debian|raspbian)
  326. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  327. case "$dist_version" in
  328. 8)
  329. dist_version="jessie"
  330. ;;
  331. 7)
  332. dist_version="wheezy"
  333. ;;
  334. esac
  335. ;;
  336. oracleserver)
  337. # need to switch lsb_dist to match yum repo URL
  338. lsb_dist="oraclelinux"
  339. dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
  340. ;;
  341. fedora|centos|redhat)
  342. dist_version="$(rpm -q --whatprovides ${lsb_dist}-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//' | sort | tail -1)"
  343. ;;
  344. "vmware photon")
  345. lsb_dist="photon"
  346. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  347. ;;
  348. *)
  349. if command_exists lsb_release; then
  350. dist_version="$(lsb_release --codename | cut -f2)"
  351. fi
  352. if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
  353. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  354. fi
  355. ;;
  356. esac
  357. # Check if this is a forked Linux distro
  358. check_forked
  359. # Run setup for each distro accordingly
  360. case "$lsb_dist" in
  361. ubuntu|debian|raspbian)
  362. export DEBIAN_FRONTEND=noninteractive
  363. did_apt_get_update=
  364. apt_get_update() {
  365. if [ -z "$did_apt_get_update" ]; then
  366. ( set -x; $sh_c 'sleep 3; apt-get update' )
  367. did_apt_get_update=1
  368. fi
  369. }
  370. if [ "$lsb_dist" != "raspbian" ]; then
  371. # aufs is preferred over devicemapper; try to ensure the driver is available.
  372. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  373. if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then
  374. kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
  375. apt_get_update
  376. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  377. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  378. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  379. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  380. ( set -x; sleep 10 )
  381. fi
  382. else
  383. echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
  384. echo >&2 ' package. We have no AUFS support. Consider installing the packages'
  385. echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
  386. ( set -x; sleep 10 )
  387. fi
  388. fi
  389. fi
  390. # install apparmor utils if they're missing and apparmor is enabled in the kernel
  391. # otherwise Docker will fail to start
  392. if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
  393. if command -v apparmor_parser >/dev/null 2>&1; then
  394. echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
  395. else
  396. echo 'apparmor is enabled in the kernel, but apparmor_parser is missing. Trying to install it..'
  397. apt_get_update
  398. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
  399. fi
  400. fi
  401. if [ ! -e /usr/lib/apt/methods/https ]; then
  402. apt_get_update
  403. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
  404. fi
  405. if [ -z "$curl" ]; then
  406. apt_get_update
  407. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
  408. curl='curl -sSL'
  409. fi
  410. if ! command -v gpg > /dev/null; then
  411. apt_get_update
  412. ( set -x; $sh_c 'sleep 3; apt-get install -y -q gnupg2 || apt-get install -y -q gnupg' )
  413. fi
  414. # dirmngr is a separate package in ubuntu yakkety; see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1634464
  415. if ! command -v dirmngr > /dev/null; then
  416. apt_get_update
  417. ( set -x; $sh_c 'sleep 3; apt-get install -y -q dirmngr' )
  418. fi
  419. (
  420. set -x
  421. echo "$docker_key" | apt-key add -
  422. $sh_c "mkdir -p /etc/apt/sources.list.d"
  423. $sh_c "echo deb \[arch=$(dpkg --print-architecture)\] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
  424. $sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine'
  425. )
  426. echo_docker_as_nonroot
  427. exit 0
  428. ;;
  429. fedora|centos|redhat|oraclelinux|photon)
  430. if [ "${lsb_dist}" = "redhat" ]; then
  431. # we use the centos repository for both redhat and centos releases
  432. lsb_dist='centos'
  433. fi
  434. $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
  435. [docker-${repo}-repo]
  436. name=Docker ${repo} Repository
  437. baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version}
  438. enabled=1
  439. gpgcheck=1
  440. gpgkey=${yum_url}/gpg
  441. EOF
  442. if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
  443. (
  444. set -x
  445. $sh_c 'sleep 3; dnf -y -q install docker-engine'
  446. )
  447. elif [ "$lsb_dist" = "photon" ]; then
  448. (
  449. set -x
  450. $sh_c 'sleep 3; tdnf -y install docker-engine'
  451. )
  452. else
  453. (
  454. set -x
  455. $sh_c 'sleep 3; yum -y -q install docker-engine'
  456. )
  457. fi
  458. echo_docker_as_nonroot
  459. exit 0
  460. ;;
  461. esac
  462. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  463. cat >&2 <<-'EOF'
  464. Either your platform is not easily detectable, is not supported by this
  465. installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
  466. a package for Docker. Please visit the following URL for more detailed
  467. installation instructions:
  468. https://docs.docker.com/engine/installation/
  469. EOF
  470. exit 1
  471. }
  472. # wrapped up in a function so that we have some protection against only getting
  473. # half the file during "curl | sh"
  474. do_install