Browse code

Wrap installer in a function

This will assure that the install script will not
begin executing until after it has been downloaded should
it be utilized in a 'curl | bash' workflow.

Signed-off-by: Eric Windisch <eric@windisch.us>
(cherry picked from commit fa961ce0463ebd738da875c3a6da8171373d7723)

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