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