github.com/DaoCloud/dao@v0.0.0-20161212064103-c3dbfd13ee36/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" ] && [ "$lsb_dist" != "raspbian" ]; 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 armv6l|armv7l) 133 ;; 134 *) 135 cat >&2 <<-'EOF' 136 Error: you are not using a 64bit platform or a Raspberry Pi (armv6l/armv7l). 137 Docker currently only supports 64bit platforms or a Raspberry Pi (armv6l/armv7l). 138 EOF 139 exit 1 140 ;; 141 esac 142 143 if command_exists docker; then 144 version="$(docker -v | awk -F '[ ,]+' '{ print $3 }')" 145 MAJOR_W=1 146 MINOR_W=10 147 148 semverParse $version 149 150 shouldWarn=0 151 if [ $major -lt $MAJOR_W ]; then 152 shouldWarn=1 153 fi 154 155 if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then 156 shouldWarn=1 157 fi 158 159 cat >&2 <<-'EOF' 160 Warning: the "docker" command appears to already exist on this system. 161 162 If you already have Docker installed, this script can cause trouble, which is 163 why we're displaying this warning and provide the opportunity to cancel the 164 installation. 165 166 If you installed the current Docker package using this script and are using it 167 EOF 168 169 if [ $shouldWarn -eq 1 ]; then 170 cat >&2 <<-'EOF' 171 again to update Docker, we urge you to migrate your image store before upgrading 172 to v1.10+. 173 174 You can find instructions for this here: 175 https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration 176 EOF 177 else 178 cat >&2 <<-'EOF' 179 again to update Docker, you can safely ignore this message. 180 EOF 181 fi 182 183 cat >&2 <<-'EOF' 184 185 You may press Ctrl+C now to abort this script. 186 EOF 187 ( set -x; sleep 20 ) 188 fi 189 190 user="$(id -un 2>/dev/null || true)" 191 192 sh_c='sh -c' 193 if [ "$user" != 'root' ]; then 194 if command_exists sudo; then 195 sh_c='sudo -E sh -c' 196 elif command_exists su; then 197 sh_c='su -c' 198 else 199 cat >&2 <<-'EOF' 200 Error: this installer needs the ability to run commands as root. 201 We are unable to find either "sudo" or "su" available to make this happen. 202 EOF 203 exit 1 204 fi 205 fi 206 207 curl='' 208 if command_exists curl; then 209 curl='curl -sSL' 210 elif command_exists wget; then 211 curl='wget -qO-' 212 elif command_exists busybox && busybox --list-modules | grep -q wget; then 213 curl='busybox wget -qO-' 214 fi 215 216 # check to see which repo they are trying to install from 217 if [ -z "$repo" ]; then 218 repo='main' 219 if [ "https://test.docker.com/" = "$url" ]; then 220 repo='testing' 221 elif [ "https://experimental.docker.com/" = "$url" ]; then 222 repo='experimental' 223 fi 224 fi 225 226 # perform some very rudimentary platform detection 227 lsb_dist='' 228 dist_version='' 229 if command_exists lsb_release; then 230 lsb_dist="$(lsb_release -si)" 231 fi 232 if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then 233 lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" 234 fi 235 if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then 236 lsb_dist='debian' 237 fi 238 if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then 239 lsb_dist='fedora' 240 fi 241 if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then 242 lsb_dist='oracleserver' 243 fi 244 if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then 245 lsb_dist='centos' 246 fi 247 if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then 248 lsb_dist='redhat' 249 fi 250 if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then 251 lsb_dist="$(. /etc/os-release && echo "$ID")" 252 fi 253 254 lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" 255 256 # Special case redhatenterpriseserver 257 if [ "${lsb_dist}" = "redhatenterpriseserver" ]; then 258 # Set it to redhat, it will be changed to centos below anyways 259 lsb_dist='redhat' 260 fi 261 262 case "$lsb_dist" in 263 264 ubuntu) 265 if command_exists lsb_release; then 266 dist_version="$(lsb_release --codename | cut -f2)" 267 fi 268 if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then 269 dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" 270 fi 271 ;; 272 273 debian|raspbian) 274 dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" 275 case "$dist_version" in 276 8) 277 dist_version="jessie" 278 ;; 279 7) 280 dist_version="wheezy" 281 ;; 282 esac 283 ;; 284 285 oracleserver) 286 # need to switch lsb_dist to match yum repo URL 287 lsb_dist="oraclelinux" 288 dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" 289 ;; 290 291 fedora|centos|redhat) 292 dist_version="$(rpm -q --whatprovides ${lsb_dist}-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//' | sort | tail -1)" 293 ;; 294 295 *) 296 if command_exists lsb_release; then 297 dist_version="$(lsb_release --codename | cut -f2)" 298 fi 299 if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then 300 dist_version="$(. /etc/os-release && echo "$VERSION_ID")" 301 fi 302 ;; 303 304 305 esac 306 307 # Check if this is a forked Linux distro 308 check_forked 309 310 # Run setup for each distro accordingly 311 case "$lsb_dist" in 312 amzn) 313 ( 314 set -x 315 $sh_c 'sleep 3; yum -y -q install docker' 316 ) 317 echo_docker_as_nonroot 318 exit 0 319 ;; 320 321 'opensuse project'|opensuse) 322 echo 'Going to perform the following operations:' 323 if [ "$repo" != 'main' ]; then 324 echo ' * add repository obs://Virtualization:containers' 325 fi 326 echo ' * install Docker' 327 $sh_c 'echo "Press CTRL-C to abort"; sleep 3' 328 329 if [ "$repo" != 'main' ]; then 330 # install experimental packages from OBS://Virtualization:containers 331 ( 332 set -x 333 zypper -n ar -f obs://Virtualization:containers Virtualization:containers 334 rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2 335 ) 336 fi 337 ( 338 set -x 339 zypper -n install docker 340 ) 341 echo_docker_as_nonroot 342 exit 0 343 ;; 344 'suse linux'|sle[sd]) 345 echo 'Going to perform the following operations:' 346 if [ "$repo" != 'main' ]; then 347 echo ' * add repository obs://Virtualization:containers' 348 echo ' * install experimental Docker using packages NOT supported by SUSE' 349 else 350 echo ' * add the "Containers" module' 351 echo ' * install Docker using packages supported by SUSE' 352 fi 353 $sh_c 'echo "Press CTRL-C to abort"; sleep 3' 354 355 if [ "$repo" != 'main' ]; then 356 # install experimental packages from OBS://Virtualization:containers 357 echo >&2 'Warning: installing experimental packages from OBS, these packages are NOT supported by SUSE' 358 ( 359 set -x 360 zypper -n ar -f obs://Virtualization:containers/SLE_12 Virtualization:containers 361 rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2 362 ) 363 else 364 # Add the containers module 365 # Note well-1: the SLE machine must already be registered against SUSE Customer Center 366 # Note well-2: the `-r ""` is required to workaround a known issue of SUSEConnect 367 ( 368 set -x 369 SUSEConnect -p sle-module-containers/12/x86_64 -r "" 370 ) 371 fi 372 ( 373 set -x 374 zypper -n install docker 375 ) 376 echo_docker_as_nonroot 377 exit 0 378 ;; 379 380 ubuntu|debian|raspbian) 381 export DEBIAN_FRONTEND=noninteractive 382 383 did_apt_get_update= 384 apt_get_update() { 385 if [ -z "$did_apt_get_update" ]; then 386 ( set -x; $sh_c 'sleep 3; apt-get update' ) 387 did_apt_get_update=1 388 fi 389 } 390 391 if [ "$lsb_dist" = "raspbian" ]; then 392 # Create Raspbian specific systemd drop-in file, use overlay by default 393 ( set -x; $sh_c "mkdir -p /etc/systemd/system/docker.service.d" ) 394 ( set -x; $sh_c "echo '[Service]\nExecStart=\nExecStart=/usr/bin/dockerd --storage-driver overlay -H fd://' > /etc/systemd/system/docker.service.d/overlay.conf" ) 395 else 396 # aufs is preferred over devicemapper; try to ensure the driver is available. 397 if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then 398 if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then 399 kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual" 400 401 apt_get_update 402 ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true 403 404 if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then 405 echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)' 406 echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!' 407 ( set -x; sleep 10 ) 408 fi 409 else 410 echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual' 411 echo >&2 ' package. We have no AUFS support. Consider installing the packages' 412 echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.' 413 ( set -x; sleep 10 ) 414 fi 415 fi 416 fi 417 418 # install apparmor utils if they're missing and apparmor is enabled in the kernel 419 # otherwise Docker will fail to start 420 if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then 421 if command -v apparmor_parser >/dev/null 2>&1; then 422 echo 'apparmor is enabled in the kernel and apparmor utils were already installed' 423 else 424 echo 'apparmor is enabled in the kernel, but apparmor_parser is missing. Trying to install it..' 425 apt_get_update 426 ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' ) 427 fi 428 fi 429 430 if [ ! -e /usr/lib/apt/methods/https ]; then 431 apt_get_update 432 ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' ) 433 fi 434 if [ -z "$curl" ]; then 435 apt_get_update 436 ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' ) 437 curl='curl -sSL' 438 fi 439 if [ ! -e /usr/bin/gpg ]; then 440 apt_get_update 441 ( set -x; $sh_c 'sleep 3; apt-get install -y -q gnupg2 || apt-get install -y -q gnupg' ) 442 fi 443 444 ( 445 set -x 446 for key_server in $key_servers ; do 447 $sh_c "apt-key adv --keyserver hkp://${key_server}:80 --recv-keys ${gpg_fingerprint}" && break 448 done 449 $sh_c "apt-key adv -k ${gpg_fingerprint} >/dev/null" 450 $sh_c "mkdir -p /etc/apt/sources.list.d" 451 $sh_c "echo deb \[arch=$(dpkg --print-architecture)\] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list" 452 $sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine' 453 ) 454 echo_docker_as_nonroot 455 exit 0 456 ;; 457 458 fedora|centos|redhat|oraclelinux) 459 if [ "${lsb_dist}" = "redhat" ]; then 460 # we use the centos repository for both redhat and centos releases 461 lsb_dist='centos' 462 fi 463 $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF 464 [docker-${repo}-repo] 465 name=Docker ${repo} Repository 466 baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version} 467 enabled=1 468 gpgcheck=1 469 gpgkey=${yum_url}/gpg 470 EOF 471 if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then 472 ( 473 set -x 474 $sh_c 'sleep 3; dnf -y -q install docker-engine' 475 ) 476 else 477 ( 478 set -x 479 $sh_c 'sleep 3; yum -y -q install docker-engine' 480 ) 481 fi 482 echo_docker_as_nonroot 483 exit 0 484 ;; 485 gentoo) 486 if [ "$url" = "https://test.docker.com/" ]; then 487 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output 488 cat >&2 <<-'EOF' 489 490 You appear to be trying to install the latest nightly build in Gentoo.' 491 The portage tree should contain the latest stable release of Docker, but' 492 if you want something more recent, you can always use the live ebuild' 493 provided in the "docker" overlay available via layman. For more' 494 instructions, please see the following URL:' 495 496 https://github.com/tianon/docker-overlay#using-this-overlay' 497 498 After adding the "docker" overlay, you should be able to:' 499 500 emerge -av =app-emulation/docker-9999' 501 502 EOF 503 exit 1 504 fi 505 506 ( 507 set -x 508 $sh_c 'sleep 3; emerge app-emulation/docker' 509 ) 510 exit 0 511 ;; 512 esac 513 514 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output 515 cat >&2 <<-'EOF' 516 517 Either your platform is not easily detectable, is not supported by this 518 installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have 519 a package for Docker. Please visit the following URL for more detailed 520 installation instructions: 521 522 https://docs.docker.com/engine/installation/ 523 524 EOF 525 exit 1 526 } 527 528 # wrapped up in a function so that we have some protection against only getting 529 # half the file during "curl | sh" 530 do_install