Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.27 KB | None | 0 0
  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. # s3cmd put --acl-public -P hack/install.sh s3://get.docker.com/index
  24. #
  25.  
  26. url='https://get.docker.com/'
  27. docker_version=1.12.3
  28.  
  29. command_exists() {
  30. command -v "$@" > /dev/null 2>&1
  31. }
  32.  
  33. echo_docker_as_nonroot() {
  34. if command_exists docker && [ -e /var/run/docker.sock ]; then
  35. (
  36. set -x
  37. $sh_c 'docker version'
  38. ) || true
  39. fi
  40. your_user=your-user
  41. [ "$user" != 'root' ] && your_user="$user"
  42. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
  43. cat <<-EOF
  44.  
  45. If you would like to use Docker as a non-root user, you should now consider
  46. adding your user to the "docker" group with something like:
  47.  
  48. sudo usermod -aG docker $your_user
  49.  
  50. Remember that you will have to log out and back in for this to take effect!
  51.  
  52. EOF
  53. }
  54.  
  55. # Check if this is a forked Linux distro
  56. check_forked() {
  57.  
  58. # Check for lsb_release command existence, it usually exists in forked distros
  59. if command_exists lsb_release; then
  60. # Check if the `-u` option is supported
  61. set +e
  62. lsb_release -a -u > /dev/null 2>&1
  63. lsb_release_exit_code=$?
  64. set -e
  65.  
  66. # Check if the command has exited successfully, it means we're in a forked distro
  67. if [ "$lsb_release_exit_code" = "0" ]; then
  68. # Print info about current distro
  69. cat <<-EOF
  70. You're using '$lsb_dist' version '$dist_version'.
  71. EOF
  72.  
  73. # Get the upstream release info
  74. lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  75. dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  76.  
  77. # Print info about upstream distro
  78. cat <<-EOF
  79. Upstream release is '$lsb_dist' version '$dist_version'.
  80. EOF
  81. else
  82. if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ]; then
  83. # We're Debian and don't even know it!
  84. lsb_dist=debian
  85. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  86. case "$dist_version" in
  87. 8|'Kali Linux 2')
  88. dist_version="jessie"
  89. ;;
  90. 7)
  91. dist_version="wheezy"
  92. ;;
  93. esac
  94. fi
  95. fi
  96. fi
  97. }
  98.  
  99. rpm_import_repository_key() {
  100. local key=$1; shift
  101. local tmpdir=$(mktemp -d)
  102. chmod 600 "$tmpdir"
  103. gpg --homedir "$tmpdir" --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"
  104. gpg --homedir "$tmpdir" --export --armor "$key" > "$tmpdir"/repo.key
  105. rpm --import "$tmpdir"/repo.key
  106. rm -rf "$tmpdir"
  107. }
  108.  
  109. semverParse() {
  110. major="${1%%.*}"
  111. minor="${1#$major.}"
  112. minor="${minor%%.*}"
  113. patch="${1#$major.$minor.}"
  114. patch="${patch%%[-.]*}"
  115. }
  116.  
  117. do_install() {
  118. case "$(uname -m)" in
  119. *64)
  120. ;;
  121. *)
  122. cat >&2 <<-'EOF'
  123. Error: you are not using a 64bit platform.
  124. Docker currently only supports 64bit platforms.
  125. EOF
  126. exit 1
  127. ;;
  128. esac
  129.  
  130. if command_exists docker; then
  131. version="$(docker -v | awk -F '[ ,]+' '{ print $3 }')"
  132. MAJOR_W=1
  133. MINOR_W=10
  134.  
  135. semverParse $version
  136.  
  137. shouldWarn=0
  138. if [ $major -lt $MAJOR_W ]; then
  139. shouldWarn=1
  140. fi
  141.  
  142. if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then
  143. shouldWarn=1
  144. fi
  145.  
  146. cat >&2 <<-'EOF'
  147. Warning: the "docker" command appears to already exist on this system.
  148.  
  149. If you already have Docker installed, this script can cause trouble, which is
  150. why we're displaying this warning and provide the opportunity to cancel the
  151. installation.
  152.  
  153. If you installed the current Docker package using this script and are using it
  154. EOF
  155.  
  156. if [ $shouldWarn -eq 1 ]; then
  157. cat >&2 <<-'EOF'
  158. again to update Docker, we urge you to migrate your image store before upgrading
  159. to v1.10+.
  160.  
  161. You can find instructions for this here:
  162. https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
  163. EOF
  164. else
  165. cat >&2 <<-'EOF'
  166. again to update Docker, you can safely ignore this message.
  167. EOF
  168. fi
  169.  
  170. cat >&2 <<-'EOF'
  171.  
  172. You may press Ctrl+C now to abort this script.
  173. EOF
  174. ( set -x; sleep 20 )
  175. fi
  176.  
  177. user="$(id -un 2>/dev/null || true)"
  178.  
  179. sh_c='sh -c'
  180. if [ "$user" != 'root' ]; then
  181. if command_exists sudo; then
  182. sh_c='sudo -E sh -c'
  183. elif command_exists su; then
  184. sh_c='su -c'
  185. else
  186. cat >&2 <<-'EOF'
  187. Error: this installer needs the ability to run commands as root.
  188. We are unable to find either "sudo" or "su" available to make this happen.
  189. EOF
  190. exit 1
  191. fi
  192. fi
  193.  
  194. curl=''
  195. if command_exists curl; then
  196. curl='curl -sSL'
  197. elif command_exists wget; then
  198. curl='wget -qO-'
  199. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  200. curl='busybox wget -qO-'
  201. fi
  202.  
  203. # check to see which repo they are trying to install from
  204. repo='main'
  205. if [ "https://test.docker.com/" = "$url" ]; then
  206. repo='testing'
  207. elif [ "https://experimental.docker.com/" = "$url" ]; then
  208. repo='experimental'
  209. fi
  210.  
  211. # perform some very rudimentary platform detection
  212. lsb_dist=''
  213. dist_version=''
  214. if command_exists lsb_release; then
  215. lsb_dist="$(lsb_release -si)"
  216. fi
  217. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  218. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  219. fi
  220. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  221. lsb_dist='debian'
  222. fi
  223. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  224. lsb_dist='fedora'
  225. fi
  226. if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then
  227. lsb_dist='oracleserver'
  228. fi
  229. if [ -z "$lsb_dist" ]; then
  230. if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then
  231. lsb_dist='centos'
  232. fi
  233. fi
  234. if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
  235. lsb_dist="$(. /etc/os-release && echo "$ID")"
  236. fi
  237.  
  238. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  239.  
  240. case "$lsb_dist" in
  241.  
  242. ubuntu)
  243. if command_exists lsb_release; then
  244. dist_version="$(lsb_release --codename | cut -f2)"
  245. fi
  246. if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
  247. dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
  248. fi
  249. ;;
  250.  
  251. debian)
  252. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  253. case "$dist_version" in
  254. 8)
  255. dist_version="jessie"
  256. ;;
  257. 7)
  258. dist_version="wheezy"
  259. ;;
  260. esac
  261. ;;
  262.  
  263. oracleserver)
  264. # need to switch lsb_dist to match yum repo URL
  265. lsb_dist="oraclelinux"
  266. dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
  267. ;;
  268.  
  269. fedora|centos)
  270. dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
  271. ;;
  272.  
  273. *)
  274. if command_exists lsb_release; then
  275. dist_version="$(lsb_release --codename | cut -f2)"
  276. fi
  277. if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
  278. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  279. fi
  280. ;;
  281.  
  282.  
  283. esac
  284.  
  285. # Check if this is a forked Linux distro
  286. check_forked
  287.  
  288. # Run setup for each distro accordingly
  289. case "$lsb_dist" in
  290. amzn)
  291. (
  292. set -x
  293. $sh_c 'sleep 3; yum -y -q install docker'
  294. )
  295. echo_docker_as_nonroot
  296. exit 0
  297. ;;
  298.  
  299. 'opensuse project'|opensuse)
  300. echo 'Going to perform the following operations:'
  301. if [ "$repo" != 'main' ]; then
  302. echo ' * add repository obs://Virtualization:containers'
  303. fi
  304. echo ' * install Docker'
  305. $sh_c 'echo "Press CTRL-C to abort"; sleep 3'
  306.  
  307. if [ "$repo" != 'main' ]; then
  308. # install experimental packages from OBS://Virtualization:containers
  309. (
  310. set -x
  311. zypper -n ar -f obs://Virtualization:containers Virtualization:containers
  312. rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
  313. )
  314. fi
  315. (
  316. set -x
  317. zypper -n install docker
  318. )
  319. echo_docker_as_nonroot
  320. exit 0
  321. ;;
  322. 'suse linux'|sle[sd])
  323. echo 'Going to perform the following operations:'
  324. if [ "$repo" != 'main' ]; then
  325. echo ' * add repository obs://Virtualization:containers'
  326. echo ' * install experimental Docker using packages NOT supported by SUSE'
  327. else
  328. echo ' * add the "Containers" module'
  329. echo ' * install Docker using packages supported by SUSE'
  330. fi
  331. $sh_c 'echo "Press CTRL-C to abort"; sleep 3'
  332.  
  333. if [ "$repo" != 'main' ]; then
  334. # install experimental packages from OBS://Virtualization:containers
  335. echo >&2 'Warning: installing experimental packages from OBS, these packages are NOT supported by SUSE'
  336. (
  337. set -x
  338. zypper -n ar -f obs://Virtualization:containers/SLE_12 Virtualization:containers
  339. rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
  340. )
  341. else
  342. # Add the containers module
  343. # Note well-1: the SLE machine must already be registered against SUSE Customer Center
  344. # Note well-2: the `-r ""` is required to workaround a known issue of SUSEConnect
  345. (
  346. set -x
  347. SUSEConnect -p sle-module-containers/12/x86_64 -r ""
  348. )
  349. fi
  350. (
  351. set -x
  352. zypper -n install docker
  353. )
  354. echo_docker_as_nonroot
  355. exit 0
  356. ;;
  357.  
  358. ubuntu|debian)
  359. export DEBIAN_FRONTEND=noninteractive
  360.  
  361. did_apt_get_update=
  362. apt_get_update() {
  363. if [ -z "$did_apt_get_update" ]; then
  364. ( set -x; $sh_c 'sleep 3; apt-get update' )
  365. did_apt_get_update=1
  366. fi
  367. }
  368.  
  369. # aufs is preferred over devicemapper; try to ensure the driver is available.
  370. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  371. if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then
  372. kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
  373.  
  374. apt_get_update
  375. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  376.  
  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.  
  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 missing'
  397. apt_get_update
  398. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
  399. fi
  400. fi
  401.  
  402. if [ ! -e /usr/lib/apt/methods/https ]; then
  403. apt_get_update
  404. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
  405. fi
  406. if [ -z "$curl" ]; then
  407. apt_get_update
  408. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
  409. curl='curl -sSL'
  410. fi
  411. (
  412. set -x
  413. $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"
  414. $sh_c "mkdir -p /etc/apt/sources.list.d"
  415. $sh_c "echo deb [arch=$(dpkg --print-architecture)] https://apt.dockerproject.org/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
  416. $sh_c "sleep 3; apt-get update; apt-get install -y -q docker-engine=${docker_version}-0~${dist_version}"
  417. )
  418. echo_docker_as_nonroot
  419. exit 0
  420. ;;
  421.  
  422. fedora|centos|oraclelinux)
  423. $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
  424. [docker-${repo}-repo]
  425. name=Docker ${repo} Repository
  426. baseurl=https://yum.dockerproject.org/repo/${repo}/${lsb_dist}/${dist_version}
  427. enabled=1
  428. gpgcheck=1
  429. gpgkey=https://yum.dockerproject.org/gpg
  430. EOF
  431. if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
  432. (
  433. set -x
  434. $sh_c "sleep 3; dnf -y -q install docker-engine-${docker_version}"
  435. )
  436. else
  437. (
  438. set -x
  439. $sh_c "sleep 3; yum -y -q install docker-engine-${docker_version}"
  440. )
  441. fi
  442. echo_docker_as_nonroot
  443. exit 0
  444. ;;
  445. gentoo)
  446. if [ "$url" = "https://test.docker.com/" ]; then
  447. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  448. cat >&2 <<-'EOF'
  449.  
  450. You appear to be trying to install the latest nightly build in Gentoo.'
  451. The portage tree should contain the latest stable release of Docker, but'
  452. if you want something more recent, you can always use the live ebuild'
  453. provided in the "docker" overlay available via layman. For more'
  454. instructions, please see the following URL:'
  455.  
  456. https://github.com/tianon/docker-overlay#using-this-overlay'
  457.  
  458. After adding the "docker" overlay, you should be able to:'
  459.  
  460. emerge -av =app-emulation/docker-9999'
  461.  
  462. EOF
  463. exit 1
  464. fi
  465.  
  466. (
  467. set -x
  468. $sh_c 'sleep 3; emerge app-emulation/docker'
  469. )
  470. exit 0
  471. ;;
  472. esac
  473.  
  474. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  475. cat >&2 <<-'EOF'
  476.  
  477. Either your platform is not easily detectable, is not supported by this
  478. installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
  479. a package for Docker. Please visit the following URL for more detailed
  480. installation instructions:
  481.  
  482. https://docs.docker.com/engine/installation/
  483.  
  484. EOF
  485. exit 1
  486. }
  487.  
  488. # wrapped up in a function so that we have some protection against only getting
  489. # half the file during "curl | sh"
  490. do_install
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement