Browse code

Revamp install.sh to be usable by more people, and to use official install methods whenever possible (apt repo, portage tree, etc.), thus making it an official script and moving it to hack/

Tianon Gravi authored on 2013/09/28 13:50:24
Showing 4 changed files
1 1
deleted file mode 100755
... ...
@@ -1,61 +0,0 @@
1
-#!/bin/sh
2
-# This script is meant for quick & easy install via 'curl URL-OF-SCRIPT | sh'
3
-# Original version by Jeff Lindsay <progrium@gmail.com>
4
-# Revamped by Jerome Petazzoni <jerome@dotcloud.com>
5
-#
6
-# This script canonical location is https://get.docker.io/; to update it, run:
7
-# s3cmd put -m text/x-shellscript -P install.sh s3://get.docker.io/index
8
-
9
-echo "Ensuring basic dependencies are installed..."
10
-apt-get -qq update
11
-apt-get -qq install lxc wget
12
-
13
-echo "Looking in /proc/filesystems to see if we have AUFS support..."
14
-if grep -q aufs /proc/filesystems
15
-then
16
-    echo "Found."
17
-else
18
-    echo "Ahem, it looks like the current kernel does not support AUFS."
19
-    echo "Let's see if we can load the AUFS module with modprobe..."
20
-    if modprobe aufs
21
-    then
22
-        echo "Module loaded."
23
-    else
24
-        echo "Ahem, things didn't turn out as expected."
25
-        KPKG=linux-image-extra-$(uname -r)
26
-        echo "Trying to install $KPKG..."
27
-        if apt-get -qq install $KPKG
28
-        then
29
-            echo "Installed."
30
-        else
31
-            echo "Oops, we couldn't install the -extra kernel."
32
-            echo "Are you sure you are running a supported version of Ubuntu?"
33
-            echo "Proceeding anyway, but Docker will probably NOT WORK!"
34
-        fi
35
-    fi
36
-fi
37
-
38
-echo "Downloading docker binary to /usr/local/bin..."
39
-curl -s https://get.docker.io/builds/$(uname -s)/$(uname -m)/docker-latest \
40
-    > /usr/local/bin/docker
41
-chmod +x /usr/local/bin/docker
42
-
43
-if [ -f /etc/init/dockerd.conf ]
44
-then
45
-  echo "Upstart script already exists."
46
-else
47
-  echo "Creating /etc/init/dockerd.conf..."
48
-  cat >/etc/init/dockerd.conf <<EOF
49
-description "Docker daemon"
50
-start on filesystem and started lxc-net
51
-stop on runlevel [!2345]
52
-respawn
53
-exec /usr/local/bin/docker -d
54
-EOF
55
-fi
56
-
57
-echo "Starting dockerd..."
58
-start dockerd > /dev/null
59
-
60
-echo "Done."
61
-echo
... ...
@@ -44,10 +44,10 @@ Security Group to allow SSH.** By default all incoming ports to your
44 44
 new instance will be blocked by the AWS Security Group, so you might
45 45
 just get timeouts when you try to connect.
46 46
 
47
-Installing with ``get.docker.io`` (as above) will create a service
48
-named ``dockerd``. You may want to set up a :ref:`docker group
49
-<dockergroup>` and add the *ubuntu* user to it so that you don't have
50
-to use ``sudo`` for every Docker command.
47
+Installing with ``get.docker.io`` (as above) will create a service named
48
+``lxc-docker``. It will also set up a :ref:`docker group <dockergroup>` and you
49
+may want to add the *ubuntu* user to it so that you don't have to use ``sudo``
50
+for every Docker command.
51 51
 
52 52
 Once you've got Docker installed, you're ready to try it out -- head
53 53
 on over to the :doc:`../use/basics` or :doc:`../examples/index` section.
54 54
new file mode 100755
... ...
@@ -0,0 +1,136 @@
0
+#!/bin/sh
1
+set -e
2
+#
3
+# This script is meant for quick & easy install via:
4
+#   'curl -sL https://get.docker.io/ | sh'
5
+# or:
6
+#   'wget -qO- https://get.docker.io/ | sh'
7
+#
8
+#
9
+# Docker Maintainers:
10
+#   To update this script on https://get.docker.io,
11
+#   use hack/release.sh during a normal release,
12
+#   or the following one-liner for script hotfixes:
13
+#     s3cmd put --acl-public -P hack/install.sh s3://get.docker.io/index
14
+#
15
+
16
+url='https://get.docker.io/'
17
+
18
+command_exists() {
19
+	command -v "$@" > /dev/null 2>&1
20
+}
21
+
22
+case "$(uname -m)" in
23
+	*64)
24
+		;;
25
+	*)
26
+		echo >&2 'Error: you are not using a 64bit platform.'
27
+		echo >&2 'Docker currently only supports 64bit platforms.'
28
+		exit 1
29
+		;;
30
+esac
31
+
32
+if command_exists docker || command_exists lxc-docker; then
33
+	echo >&2 'Warning: "docker" or "lxc-docker" command appears to already exist.'
34
+	echo >&2 'Please ensure that you do not already have docker installed.'
35
+	echo >&2 'You may press Ctrl+C now to abort this process and rectify this situation.'
36
+	( set -x; sleep 20 )
37
+fi
38
+
39
+sh_c='sh -c'
40
+if [ "$(whoami 2>/dev/null || true)" != 'root' ]; then
41
+	if command_exists sudo; then
42
+		sh_c='sudo sh -c'
43
+	elif command_exists su; then
44
+		sh_c='su -c'
45
+	else
46
+		echo >&2 'Error: this installer needs the ability to run commands as root.'
47
+		echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
48
+		exit 1
49
+	fi
50
+fi
51
+
52
+curl=''
53
+if command_exists curl; then
54
+	curl='curl -sL'
55
+elif command_exists wget; then
56
+	curl='wget -qO-'
57
+elif command_exists busybox && busybox --list-modules | grep -q wget; then
58
+	curl='busybox wget -qO-'
59
+fi
60
+
61
+# perform some very rudimentary platform detection
62
+lsb_dist=''
63
+if command_exists lsb_release; then
64
+	lsb_dist="$(lsb_release -si)"
65
+fi
66
+if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
67
+	lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
68
+fi
69
+if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
70
+	lsb_dist='Debian'
71
+fi
72
+
73
+case "$lsb_dist" in
74
+	Ubuntu|Debian)
75
+		export DEBIAN_FRONTEND=noninteractive
76
+		
77
+		# TODO remove this comment/section once device-mapper lands
78
+		echo 'Warning: Docker currently requires AUFS support in the kernel.'
79
+		echo 'Please ensure that your kernel includes such support.'
80
+		( set -x; sleep 10 )
81
+		
82
+		if [ ! -e /usr/lib/apt/methods/https ]; then
83
+			( set -x; $sh_c 'sleep 3; apt-get update; apt-get install -y -q apt-transport-https' )
84
+		fi
85
+		if [ -z "$curl" ]; then
86
+			( set -x; $sh_c 'sleep 3; apt-get update; apt-get install -y -q curl' )
87
+			curl='curl -sL'
88
+		fi
89
+		(
90
+			set -x
91
+			$sh_c "$curl ${url}gpg | apt-key add -"
92
+			$sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list"
93
+			$sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker'
94
+		)
95
+		if command_exists docker && [ -e /var/run/docker.sock ]; then
96
+			(
97
+				set -x
98
+				$sh_c 'docker run busybox echo "Docker has been successfully installed!"'
99
+			)
100
+		fi
101
+		exit 0
102
+		;;
103
+		
104
+	Gentoo)
105
+		if [ "$url" = "https://test.docker.io/" ]; then
106
+			echo >&2
107
+			echo >&2 '  You appear to be trying to install the latest nightly build in Gentoo.'
108
+			echo >&2 '  The portage tree should contain the latest stable release of Docker, but'
109
+			echo >&2 '  if you want something more recent, you can always use the live ebuild'
110
+			echo >&2 '  provided in the "docker" overlay available via layman.  For more'
111
+			echo >&2 '  instructions, please see the following URL:'
112
+			echo >&2 '    https://github.com/tianon/docker-overlay#using-this-overlay'
113
+			echo >&2 '  After adding the "docker" overlay, you should be able to:'
114
+			echo >&2 '    emerge -av =app-emulation/docker-9999'
115
+			echo >&2
116
+			exit 1
117
+		fi
118
+		
119
+		(
120
+			set -x
121
+			$sh_c 'sleep 3; emerge app-emulation/docker'
122
+		)
123
+		exit 0
124
+		;;
125
+esac
126
+
127
+echo >&2
128
+echo >&2 '  Either your platform is not easily detectable, is not supported by this'
129
+echo >&2 '  installer script (yet - PRs welcome!), or does not yet have a package for'
130
+echo >&2 '  Docker.  Please visit the following URL for more detailed installation'
131
+echo >&2 '  instructions:'
132
+echo >&2
133
+echo >&2 '    http://docs.docker.io/en/latest/installation/'
134
+echo >&2
135
+exit 1
... ...
@@ -67,7 +67,14 @@ write_to_s3() {
67 67
 }
68 68
 
69 69
 s3_url() {
70
-	echo "http://$BUCKET.s3.amazonaws.com"
70
+	case "$BUCKET" in
71
+		get.docker.io|test.docker.io)
72
+			echo "https://$BUCKET"
73
+			;;
74
+		*)
75
+			echo "http://$BUCKET.s3.amazonaws.com"
76
+			;;
77
+	esac
71 78
 }
72 79
 
73 80
 # Upload the 'ubuntu' bundle to S3:
... ...
@@ -125,13 +132,13 @@ EOF
125 125
 	s3cmd --acl-public sync $APTDIR/ s3://$BUCKET/ubuntu/
126 126
 	cat <<EOF | write_to_s3 s3://$BUCKET/ubuntu/info
127 127
 # Add the repository to your APT sources
128
-echo deb $(s3_url $BUCKET)/ubuntu docker main > /etc/apt/sources.list.d/docker.list
128
+echo deb $(s3_url)/ubuntu docker main > /etc/apt/sources.list.d/docker.list
129 129
 # Then import the repository key
130
-curl $(s3_url $BUCKET)/gpg | apt-key add -
130
+curl $(s3_url)/gpg | apt-key add -
131 131
 # Install docker
132 132
 apt-get update ; apt-get install -y lxc-docker
133 133
 EOF
134
-	echo "APT repository uploaded. Instructions available at $(s3_url $BUCKET)/ubuntu/info"
134
+	echo "APT repository uploaded. Instructions available at $(s3_url)/ubuntu/info"
135 135
 }
136 136
 
137 137
 # Upload a static binary to S3
... ...
@@ -141,7 +148,7 @@ release_binary() {
141 141
 	s3cmd --acl-public put bundles/$VERSION/binary/docker-$VERSION $S3DIR/docker-$VERSION
142 142
 	cat <<EOF | write_to_s3 s3://$BUCKET/builds/info
143 143
 # To install, run the following command as root:
144
-curl -O http://$BUCKET.s3.amazonaws.com/builds/Linux/x86_64/docker-$VERSION && chmod +x docker-$VERSION && sudo mv docker-$VERSION /usr/local/bin/docker
144
+curl -O $(s3_url)/builds/Linux/x86_64/docker-$VERSION && chmod +x docker-$VERSION && sudo mv docker-$VERSION /usr/local/bin/docker
145 145
 # Then start docker in daemon mode:
146 146
 sudo /usr/local/bin/docker -d
147 147
 EOF
... ...
@@ -155,14 +162,7 @@ EOF
155 155
 
156 156
 # Upload the index script
157 157
 release_index() {
158
-	(
159
-	if [ "$BUCKET" != "get.docker.io" ]
160
-	then
161
-		sed s,https://get.docker.io/,http://$BUCKET.s3.amazonaws.com/, contrib/install.sh
162
-	else
163
-		cat contrib/install.sh
164
-	fi
165
-	) | write_to_s3 s3://$BUCKET/index
158
+	sed "s,https://get.docker.io/,$(s3_url)/," hack/install.sh | write_to_s3 s3://$BUCKET/index
166 159
 }
167 160
 
168 161
 release_test() {