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