github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/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 # 10 # Docker Maintainers: 11 # To update this script on https://get.docker.com, 12 # use hack/release.sh during a normal release, 13 # or the following one-liner for script hotfixes: 14 # s3cmd put --acl-public -P hack/install.sh s3://get.docker.com/index 15 # 16 17 url='https://get.docker.com/' 18 19 command_exists() { 20 command -v "$@" > /dev/null 2>&1 21 } 22 23 echo_docker_as_nonroot() { 24 your_user=your-user 25 [ "$user" != 'root' ] && your_user="$user" 26 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output 27 cat <<-EOF 28 29 If you would like to use Docker as a non-root user, you should now consider 30 adding your user to the "docker" group with something like: 31 32 sudo usermod -aG docker $your_user 33 34 Remember that you will have to log out and back in for this to take effect! 35 36 EOF 37 } 38 39 do_install() { 40 case "$(uname -m)" in 41 *64) 42 ;; 43 *) 44 cat >&2 <<-'EOF' 45 Error: you are not using a 64bit platform. 46 Docker currently only supports 64bit platforms. 47 EOF 48 exit 1 49 ;; 50 esac 51 52 if command_exists docker; then 53 cat >&2 <<-'EOF' 54 Warning: the "docker" command appears to already exist on this system. 55 56 If you already have Docker installed, this script can cause trouble, which is 57 why we're displaying this warning and provide the opportunity to cancel the 58 installation. 59 60 If you installed the current Docker package using this script and are using it 61 again to update Docker, you can safely ignore this message. 62 63 You may press Ctrl+C now to abort this script. 64 EOF 65 ( set -x; sleep 20 ) 66 fi 67 68 user="$(id -un 2>/dev/null || true)" 69 70 sh_c='sh -c' 71 if [ "$user" != 'root' ]; then 72 if command_exists sudo; then 73 sh_c='sudo -E sh -c' 74 elif command_exists su; then 75 sh_c='su -c' 76 else 77 cat >&2 <<-'EOF' 78 Error: this installer needs the ability to run commands as root. 79 We are unable to find either "sudo" or "su" available to make this happen. 80 EOF 81 exit 1 82 fi 83 fi 84 85 curl='' 86 if command_exists curl; then 87 curl='curl -sSL' 88 elif command_exists wget; then 89 curl='wget -qO-' 90 elif command_exists busybox && busybox --list-modules | grep -q wget; then 91 curl='busybox wget -qO-' 92 fi 93 94 # perform some very rudimentary platform detection 95 lsb_dist='' 96 if command_exists lsb_release; then 97 lsb_dist="$(lsb_release -si)" 98 fi 99 if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then 100 lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" 101 fi 102 if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then 103 lsb_dist='debian' 104 fi 105 if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then 106 lsb_dist='fedora' 107 fi 108 if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then 109 lsb_dist="$(. /etc/os-release && echo "$ID")" 110 fi 111 112 lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" 113 case "$lsb_dist" in 114 amzn|fedora|centos) 115 if [ "$lsb_dist" = 'amzn' ]; then 116 ( 117 set -x 118 $sh_c 'sleep 3; yum -y -q install docker' 119 ) 120 else 121 ( 122 set -x 123 $sh_c 'sleep 3; yum -y -q install docker-io' 124 ) 125 fi 126 if command_exists docker && [ -e /var/run/docker.sock ]; then 127 ( 128 set -x 129 $sh_c 'docker version' 130 ) || true 131 fi 132 echo_docker_as_nonroot 133 exit 0 134 ;; 135 136 'opensuse project'|opensuse|'suse linux'|sled) 137 ( 138 set -x 139 $sh_c 'sleep 3; zypper -n install docker' 140 ) 141 if command_exists docker && [ -e /var/run/docker.sock ]; then 142 ( 143 set -x 144 $sh_c 'docker version' 145 ) || true 146 fi 147 echo_docker_as_nonroot 148 exit 0 149 ;; 150 151 ubuntu|debian|linuxmint|'elementary os'|kali) 152 export DEBIAN_FRONTEND=noninteractive 153 154 did_apt_get_update= 155 apt_get_update() { 156 if [ -z "$did_apt_get_update" ]; then 157 ( set -x; $sh_c 'sleep 3; apt-get update' ) 158 did_apt_get_update=1 159 fi 160 } 161 162 # aufs is preferred over devicemapper; try to ensure the driver is available. 163 if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then 164 if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -q '^ii' 2>/dev/null; then 165 kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual" 166 167 apt_get_update 168 ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true 169 170 if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then 171 echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)' 172 echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!' 173 ( set -x; sleep 10 ) 174 fi 175 else 176 echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual' 177 echo >&2 ' package. We have no AUFS support. Consider installing the packages' 178 echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.' 179 ( set -x; sleep 10 ) 180 fi 181 fi 182 183 # install apparmor utils if they're missing and apparmor is enabled in the kernel 184 # otherwise Docker will fail to start 185 if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then 186 if command -v apparmor_parser &> /dev/null; then 187 echo 'apparmor is enabled in the kernel and apparmor utils were already installed' 188 else 189 echo 'apparmor is enabled in the kernel, but apparmor_parser missing' 190 apt_get_update 191 ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' ) 192 fi 193 fi 194 195 if [ ! -e /usr/lib/apt/methods/https ]; then 196 apt_get_update 197 ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' ) 198 fi 199 if [ -z "$curl" ]; then 200 apt_get_update 201 ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' ) 202 curl='curl -sSL' 203 fi 204 ( 205 set -x 206 if [ "https://get.docker.com/" = "$url" ]; then 207 $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9" 208 elif [ "https://test.docker.com/" = "$url" ]; then 209 $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 740B314AE3941731B942C66ADF4FD13717AAD7D6" 210 elif [ "https://experimental.docker.com/" = "$url" ]; then 211 $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys E33FF7BF5C91D50A6F91FFFD4CC38D40F9A96B49" 212 else 213 $sh_c "$curl ${url}gpg | apt-key add -" 214 fi 215 $sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list" 216 $sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker' 217 ) 218 if command_exists docker && [ -e /var/run/docker.sock ]; then 219 ( 220 set -x 221 $sh_c 'docker version' 222 ) || true 223 fi 224 echo_docker_as_nonroot 225 exit 0 226 ;; 227 228 gentoo) 229 if [ "$url" = "https://test.docker.com/" ]; then 230 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output 231 cat >&2 <<-'EOF' 232 233 You appear to be trying to install the latest nightly build in Gentoo.' 234 The portage tree should contain the latest stable release of Docker, but' 235 if you want something more recent, you can always use the live ebuild' 236 provided in the "docker" overlay available via layman. For more' 237 instructions, please see the following URL:' 238 239 https://github.com/tianon/docker-overlay#using-this-overlay' 240 241 After adding the "docker" overlay, you should be able to:' 242 243 emerge -av =app-emulation/docker-9999' 244 245 EOF 246 exit 1 247 fi 248 249 ( 250 set -x 251 $sh_c 'sleep 3; emerge app-emulation/docker' 252 ) 253 exit 0 254 ;; 255 esac 256 257 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output 258 cat >&2 <<-'EOF' 259 260 Either your platform is not easily detectable, is not supported by this 261 installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have 262 a package for Docker. Please visit the following URL for more detailed 263 installation instructions: 264 265 https://docs.docker.com/en/latest/installation/ 266 267 EOF 268 exit 1 269 } 270 271 # wrapped up in a function so that we have some protection against only getting 272 # half the file during "curl | sh" 273 do_install