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