Browse code

Merge pull request #12376 from Mic92/refactor-hack

Refactor shellscripts

Jessie Frazelle authored on 2015/04/23 04:12:44
Showing 21 changed files
... ...
@@ -60,7 +60,7 @@ for HIER in $(cut -d: -f2 /proc/1/cgroup); do
60 60
 
61 61
 	mkdir -p "$CGROUP/$HIER"
62 62
 
63
-	if ! mountpoint -q $CGROUP/$HIER; then
63
+	if ! mountpoint -q "$CGROUP/$HIER"; then
64 64
 		mount -n -t cgroup -o "$OHIER" cgroup "$CGROUP/$HIER"
65 65
 	fi
66 66
 
... ...
@@ -24,10 +24,12 @@ set -e
24 24
 set -o pipefail
25 25
 
26 26
 export DOCKER_PKG='github.com/docker/docker'
27
+export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
28
+export MAKEDIR="$SCRIPTDIR/make"
27 29
 
28 30
 # We're a nice, sexy, little shell script, and people might try to run us;
29 31
 # but really, they shouldn't. We want to be in a container!
30
-if [ "$(pwd)" != "/go/src/$DOCKER_PKG" ] || [ -z "$DOCKER_CROSSPLATFORMS" ]; then
32
+if [ "$PWD" != "/go/src/$DOCKER_PKG" ] || [ -z "$DOCKER_CROSSPLATFORMS" ]; then
31 33
 	{
32 34
 		echo "# WARNING! I don't seem to be running in the Docker container."
33 35
 		echo "# The result of this command might be an incorrect build, and will not be"
... ...
@@ -62,7 +64,7 @@ DEFAULT_BUNDLES=(
62 62
 	ubuntu
63 63
 )
64 64
 
65
-VERSION=$(cat ./VERSION)
65
+VERSION=$(< ./VERSION)
66 66
 if command -v git &> /dev/null && git rev-parse &> /dev/null; then
67 67
 	GITCOMMIT=$(git rev-parse --short HEAD)
68 68
 	if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
... ...
@@ -82,7 +84,7 @@ if [ "$AUTO_GOPATH" ]; then
82 82
 	rm -rf .gopath
83 83
 	mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
84 84
 	ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
85
-	export GOPATH="$(pwd)/.gopath:$(pwd)/vendor"
85
+	export GOPATH="${PWD}/.gopath:${PWD}/vendor"
86 86
 fi
87 87
 
88 88
 if [ ! "$GOPATH" ]; then
... ...
@@ -110,7 +112,7 @@ fi
110 110
 # Use these flags when compiling the tests and final binary
111 111
 
112 112
 IAMSTATIC='true'
113
-source "$(dirname "$BASH_SOURCE")/make/.go-autogen"
113
+source "$SCRIPTDIR/make/.go-autogen"
114 114
 LDFLAGS='-w'
115 115
 
116 116
 LDFLAGS_STATIC='-linkmode external'
... ...
@@ -251,7 +253,7 @@ bundle() {
251 251
 	bundlescript=$1
252 252
 	bundle=$(basename $bundlescript)
253 253
 	echo "---> Making bundle: $bundle (in bundles/$VERSION/$bundle)"
254
-	mkdir -p bundles/$VERSION/$bundle
254
+	mkdir -p "bundles/$VERSION/$bundle"
255 255
 	source "$bundlescript" "$(pwd)/bundles/$VERSION/$bundle"
256 256
 }
257 257
 
... ...
@@ -261,23 +263,22 @@ main() {
261 261
 	mkdir -p bundles
262 262
 	if [ -e "bundles/$VERSION" ]; then
263 263
 		echo "bundles/$VERSION already exists. Removing."
264
-		rm -fr bundles/$VERSION && mkdir bundles/$VERSION || exit 1
264
+		rm -fr "bundles/$VERSION" && mkdir "bundles/$VERSION" || exit 1
265 265
 		echo
266 266
 	fi
267 267
 
268 268
 	if [ "$(go env GOHOSTOS)" != 'windows' ]; then
269 269
 		# Windows and symlinks don't get along well
270
-		ln -sfT $VERSION bundles/latest
270
+		ln -sfT "$VERSION" bundles/latest
271 271
 	fi
272 272
 
273
-	SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
274 273
 	if [ $# -lt 1 ]; then
275 274
 		bundles=(${DEFAULT_BUNDLES[@]})
276 275
 	else
277 276
 		bundles=($@)
278 277
 	fi
279 278
 	for bundle in ${bundles[@]}; do
280
-		bundle $SCRIPTDIR/make/$bundle
279
+		bundle "$SCRIPTDIR/make/$bundle"
281 280
 		echo
282 281
 	done
283 282
 }
... ...
@@ -2,7 +2,7 @@
2 2
 set -e
3 3
 
4 4
 IAMSTATIC="true"
5
-source "$(dirname "$BASH_SOURCE")/.go-autogen"
5
+source "${MAKEDIR}/.go-autogen"
6 6
 
7 7
 # dockerinit still needs to be a static binary, even if docker is dynamic
8 8
 go build \
... ...
@@ -30,4 +30,4 @@ else
30 30
 fi
31 31
 
32 32
 # sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
33
-export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
33
+export DOCKER_INITSHA1=$($sha1sum "$DEST/dockerinit-$VERSION" | cut -d' ' -f1)
... ...
@@ -2,7 +2,7 @@
2 2
 set -e
3 3
 
4 4
 IAMSTATIC="true"
5
-source "$(dirname "$BASH_SOURCE")/.go-autogen"
5
+source "${MAKEDIR}/.go-autogen"
6 6
 
7 7
 # dockerinit still needs to be a static binary, even if docker is dynamic
8 8
 go build --compiler=gccgo \
... ...
@@ -28,4 +28,4 @@ else
28 28
 fi
29 29
 
30 30
 # sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
31
-export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
31
+export DOCKER_INITSHA1=$($sha1sum "$DEST/dockerinit-$VERSION" | cut -d' ' -f1)
... ...
@@ -2,8 +2,8 @@
2 2
 
3 3
 for pidFile in $(find "$DEST" -name docker.pid); do
4 4
 	pid=$(set -x; cat "$pidFile")
5
-	( set -x; kill $pid )
6
-	if ! wait $pid; then
5
+	( set -x; kill "$pid" )
6
+	if ! wait "$pid"; then
7 7
 		echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code"
8 8
 	fi
9 9
 done
... ...
@@ -11,7 +11,7 @@ if [[ "$(uname -s)" == CYGWIN* ]]; then
11 11
 	DEST=$(cygpath -mw $DEST)
12 12
 fi
13 13
 
14
-source "$(dirname "$BASH_SOURCE")/.go-autogen"
14
+source "${MAKEDIR}/.go-autogen"
15 15
 
16 16
 go build \
17 17
 	-o "$DEST/$BINARY_FULLNAME" \
... ...
@@ -5,7 +5,7 @@ DEST=$1
5 5
 
6 6
 # subshell so that we can export PATH without breaking other things
7 7
 (
8
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
8
+	source "${MAKEDIR}/.integration-daemon-start"
9 9
 
10 10
 	# we need to wrap up everything in between integration-daemon-start and
11 11
 	# integration-daemon-stop to make sure we kill the daemon and don't hang,
... ...
@@ -76,7 +76,7 @@ DEST=$1
76 76
 	# clean up after ourselves
77 77
 	rm -f Dockerfile.build
78 78
 
79
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
79
+	source "${MAKEDIR}/.integration-daemon-stop"
80 80
 
81 81
 	[ -z "$didFail" ] # "set -e" ftw
82 82
 ) 2>&1 | tee -a $DEST/test.log
... ...
@@ -28,6 +28,6 @@ for platform in $DOCKER_CROSSPLATFORMS; do
28 28
 			export LDFLAGS_STATIC_DOCKER="" # we just need a simple client for these platforms
29 29
 			export BUILDFLAGS=( "${ORIG_BUILDFLAGS[@]/ daemon/}" ) # remove the "daemon" build tag from platforms that aren't supported
30 30
 		fi
31
-		source "$(dirname "$BASH_SOURCE")/binary" "$DEST/$platform"
31
+		source "${MAKEDIR}/binary" "$DEST/$platform"
32 32
 	)
33 33
 done
... ...
@@ -4,7 +4,7 @@ set -e
4 4
 DEST=$1
5 5
 
6 6
 if [ -z "$DOCKER_CLIENTONLY" ]; then
7
-	source "$(dirname "$BASH_SOURCE")/.dockerinit"
7
+	source "${MAKEDIR}/.dockerinit"
8 8
 
9 9
 	hash_files "$DEST/dockerinit-$VERSION"
10 10
 else
... ...
@@ -18,5 +18,5 @@ fi
18 18
 	export LDFLAGS_STATIC_DOCKER=''
19 19
 	export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
20 20
 	export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here
21
-	source "$(dirname "$BASH_SOURCE")/binary"
21
+	source "${MAKEDIR}/binary"
22 22
 )
... ...
@@ -4,7 +4,7 @@ set -e
4 4
 DEST=$1
5 5
 
6 6
 if [ -z "$DOCKER_CLIENTONLY" ]; then
7
-	source "$(dirname "$BASH_SOURCE")/.dockerinit-gccgo"
7
+	source "${MAKEDIR}/.dockerinit-gccgo"
8 8
 
9 9
 	hash_files "$DEST/dockerinit-$VERSION"
10 10
 else
... ...
@@ -19,5 +19,5 @@ fi
19 19
 	export LDFLAGS_STATIC_DOCKER=''
20 20
 	export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
21 21
 	export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here
22
-	source "$(dirname "$BASH_SOURCE")/gccgo"
22
+	source "${MAKEDIR}/gccgo"
23 23
 )
... ...
@@ -6,7 +6,7 @@ BINARY_NAME="docker-$VERSION"
6 6
 BINARY_EXTENSION="$(binary_extension)"
7 7
 BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
8 8
 
9
-source "$(dirname "$BASH_SOURCE")/.go-autogen"
9
+source "${MAKEDIR}/.go-autogen"
10 10
 
11 11
 if [[ "${BUILDFLAGS[@]}" =~ 'netgo ' ]]; then
12 12
 	EXTLDFLAGS_STATIC_DOCKER+=' -lnetgo'
... ...
@@ -5,7 +5,7 @@ DEST=$1
5 5
 
6 6
 # subshell so that we can export PATH without breaking other things
7 7
 (
8
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
8
+	source "${MAKEDIR}/.integration-daemon-start"
9 9
 
10 10
 	# we need to wrap up everything in between integration-daemon-start and
11 11
 	# integration-daemon-stop to make sure we kill the daemon and don't hang,
... ...
@@ -24,7 +24,7 @@ DEST=$1
24 24
 		didFail=1
25 25
 	fi
26 26
 
27
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
27
+	source "${MAKEDIR}/.integration-daemon-stop"
28 28
 
29 29
 	[ -z "$didFail" ] # "set -e" ftw
30 30
 ) 2>&1 | tee -a $DEST/test.log
... ...
@@ -5,7 +5,7 @@ DEST=$1
5 5
 
6 6
 INIT=$DEST/../dynbinary/dockerinit-$VERSION
7 7
 [ -x "$INIT" ] || {
8
-	source "$(dirname "$BASH_SOURCE")/.dockerinit"
8
+	source "${MAKEDIR}/.dockerinit"
9 9
 	INIT="$DEST/dockerinit"
10 10
 }
11 11
 export TEST_DOCKERINIT_PATH="$INIT"
... ...
@@ -22,4 +22,4 @@ bundle_test_integration() {
22 22
 # spews when it is given packages that aren't used
23 23
 bundle_test_integration 2>&1 \
24 24
 	| grep --line-buffered -v '^warning: no packages being tested depend on ' \
25
-	| tee -a $DEST/test.log
25
+	| tee -a "$DEST/test.log"
... ...
@@ -9,23 +9,23 @@ bundle_test_integration_cli() {
9 9
 
10 10
 # subshell so that we can export PATH without breaking other things
11 11
 (
12
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
12
+	source "${MAKEDIR}/.integration-daemon-start"
13 13
 
14 14
 	# we need to wrap up everything in between integration-daemon-start and
15 15
 	# integration-daemon-stop to make sure we kill the daemon and don't hang,
16 16
 	# even and especially on test failures
17 17
 	didFail=
18 18
 	if ! {
19
-		source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images"
20
-		source "$(dirname "$BASH_SOURCE")/.ensure-httpserver"
21
-		source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs"
19
+		source "${MAKEDIR}/.ensure-frozen-images"
20
+		source "${MAKEDIR}/.ensure-httpserver"
21
+		source "${MAKEDIR}/.ensure-emptyfs"
22 22
 
23 23
 		bundle_test_integration_cli
24 24
 	}; then
25 25
 		didFail=1
26 26
 	fi
27 27
 
28
-	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
28
+	source "${MAKEDIR}/.integration-daemon-stop"
29 29
 
30 30
 	[ -z "$didFail" ] # "set -e" ftw
31
-) 2>&1 | tee -a $DEST/test.log
31
+) 2>&1 | tee -a "$DEST/test.log"
... ...
@@ -39,12 +39,12 @@ bundle_test_unit() {
39 39
 				mkdir -p "$HOME/.parallel"
40 40
 				touch "$HOME/.parallel/ignored_vars"
41 41
 
42
-				echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
42
+				echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ "${MAKEDIR}/.go-compile-test-dir"
43 43
 				rm -rf "$HOME"
44 44
 			else
45 45
 				# aww, no "parallel" available - fall back to boring
46 46
 				for test_dir in $TESTDIRS; do
47
-					"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir" || true
47
+					"${MAKEDIR}/.go-compile-test-dir" "$test_dir" || true
48 48
 					# don't let one directory that fails to build tank _all_ our tests!
49 49
 				done
50 50
 			fi
... ...
@@ -85,4 +85,4 @@ go_run_test_dir() {
85 85
 	fi
86 86
 }
87 87
 
88
-bundle_test_unit 2>&1 | tee -a $DEST/test.log
88
+bundle_test_unit 2>&1 | tee -a "$DEST/test.log"
... ...
@@ -40,26 +40,26 @@ bundle_ubuntu() {
40 40
 	DIR=$DEST/build
41 41
 
42 42
 	# Include our udev rules
43
-	mkdir -p $DIR/etc/udev/rules.d
44
-	cp contrib/udev/80-docker.rules $DIR/etc/udev/rules.d/
43
+	mkdir -p "$DIR/etc/udev/rules.d"
44
+	cp contrib/udev/80-docker.rules "$DIR/etc/udev/rules.d/"
45 45
 
46 46
 	# Include our init scripts
47
-	mkdir -p $DIR/etc/init
48
-	cp contrib/init/upstart/docker.conf $DIR/etc/init/
49
-	mkdir -p $DIR/etc/init.d
50
-	cp contrib/init/sysvinit-debian/docker $DIR/etc/init.d/
51
-	mkdir -p $DIR/etc/default
52
-	cp contrib/init/sysvinit-debian/docker.default $DIR/etc/default/docker
53
-	mkdir -p $DIR/lib/systemd/system
54
-	cp contrib/init/systemd/docker.{service,socket} $DIR/lib/systemd/system/
47
+	mkdir -p "$DIR/etc/init"
48
+	cp contrib/init/upstart/docker.conf "$DIR/etc/init/"
49
+	mkdir -p "$DIR/etc/init.d"
50
+	cp contrib/init/sysvinit-debian/docker "$DIR/etc/init.d/"
51
+	mkdir -p "$DIR/etc/default"
52
+	cp contrib/init/sysvinit-debian/docker.default "$DIR/etc/default/docker"
53
+	mkdir -p "$DIR/lib/systemd/system"
54
+	cp contrib/init/systemd/docker.{service,socket} "$DIR/lib/systemd/system/"
55 55
 
56 56
 	# Include contributed completions
57
-	mkdir -p $DIR/etc/bash_completion.d
58
-	cp contrib/completion/bash/docker $DIR/etc/bash_completion.d/
59
-	mkdir -p $DIR/usr/share/zsh/vendor-completions
60
-	cp contrib/completion/zsh/_docker $DIR/usr/share/zsh/vendor-completions/
61
-	mkdir -p $DIR/etc/fish/completions
62
-	cp contrib/completion/fish/docker.fish $DIR/etc/fish/completions/
57
+	mkdir -p "$DIR/etc/bash_completion.d"
58
+	cp contrib/completion/bash/docker "$DIR/etc/bash_completion.d/"
59
+	mkdir -p "$DIR/usr/share/zsh/vendor-completions"
60
+	cp contrib/completion/zsh/_docker "$DIR/usr/share/zsh/vendor-completions/"
61
+	mkdir -p "$DIR/etc/fish/completions"
62
+	cp contrib/completion/fish/docker.fish "$DIR/etc/fish/completions/"
63 63
 
64 64
 	# Include contributed man pages
65 65
 	docs/man/md2man-all.sh -q
... ...
@@ -76,11 +76,11 @@ bundle_ubuntu() {
76 76
 
77 77
 	# Copy the binary
78 78
 	# This will fail if the binary bundle hasn't been built
79
-	mkdir -p $DIR/usr/bin
80
-	cp $DEST/../binary/docker-$VERSION $DIR/usr/bin/docker
79
+	mkdir -p "$DIR/usr/bin"
80
+	cp "$DEST/../binary/docker-$VERSION" "$DIR/usr/bin/docker"
81 81
 
82 82
 	# Generate postinst/prerm/postrm scripts
83
-	cat > $DEST/postinst <<'EOF'
83
+	cat > "$DEST/postinst" <<'EOF'
84 84
 #!/bin/sh
85 85
 set -e
86 86
 set -u
... ...
@@ -104,7 +104,7 @@ service docker $_dh_action 2>/dev/null || true
104 104
 
105 105
 #DEBHELPER#
106 106
 EOF
107
-	cat > $DEST/prerm <<'EOF'
107
+	cat > "$DEST/prerm" <<'EOF'
108 108
 #!/bin/sh
109 109
 set -e
110 110
 set -u
... ...
@@ -113,7 +113,7 @@ service docker stop 2>/dev/null || true
113 113
 
114 114
 #DEBHELPER#
115 115
 EOF
116
-	cat > $DEST/postrm <<'EOF'
116
+	cat > "$DEST/postrm" <<'EOF'
117 117
 #!/bin/sh
118 118
 set -e
119 119
 set -u
... ...
@@ -131,18 +131,18 @@ fi
131 131
 #DEBHELPER#
132 132
 EOF
133 133
 	# TODO swaths of these were borrowed from debhelper's auto-inserted stuff, because we're still using fpm - we need to use debhelper instead, and somehow reconcile Ubuntu that way
134
-	chmod +x $DEST/postinst $DEST/prerm $DEST/postrm
134
+	chmod +x "$DEST/postinst" "$DEST/prerm" "$DEST/postrm"
135 135
 
136 136
 	(
137 137
 		# switch directories so we create *.deb in the right folder
138
-		cd $DEST
138
+		cd "$DEST"
139 139
 
140 140
 		# create lxc-docker-VERSION package
141
-		fpm -s dir -C $DIR \
142
-			--name lxc-docker-$VERSION --version "$PKGVERSION" \
143
-			--after-install $DEST/postinst \
144
-			--before-remove $DEST/prerm \
145
-			--after-remove $DEST/postrm \
141
+		fpm -s dir -C "$DIR" \
142
+			--name "lxc-docker-$VERSION" --version "$PKGVERSION" \
143
+			--after-install "$DEST/postinst" \
144
+			--before-remove "$DEST/prerm" \
145
+			--after-remove "$DEST/postrm" \
146 146
 			--architecture "$PACKAGE_ARCHITECTURE" \
147 147
 			--prefix / \
148 148
 			--depends iptables \
... ...
@@ -184,8 +184,8 @@ EOF
184 184
 	)
185 185
 
186 186
 	# clean up after ourselves so we have a clean output directory
187
-	rm $DEST/postinst $DEST/prerm $DEST/postrm
188
-	rm -r $DIR
187
+	rm "$DEST/postinst" "$DEST/prerm" "$DEST/postrm"
188
+	rm -r "$DIR"
189 189
 }
190 190
 
191 191
 bundle_ubuntu
... ...
@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-source "$(dirname "$BASH_SOURCE")/.validate"
3
+source "${MAKEDIR}/.validate"
4 4
 
5 5
 adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
6 6
 dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
... ...
@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-source "$(dirname "$BASH_SOURCE")/.validate"
3
+source "${MAKEDIR}/.validate"
4 4
 
5 5
 IFS=$'\n'
6 6
 files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
... ...
@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-source "$(dirname "$BASH_SOURCE")/.validate"
3
+source "${MAKEDIR}/.validate"
4 4
 
5 5
 IFS=$'\n'
6 6
 files=( $(validate_diff --diff-filter=ACMR --name-only -- 'MAINTAINERS' || true) )
... ...
@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-source "$(dirname "$BASH_SOURCE")/.validate"
3
+source "${MAKEDIR}/.validate"
4 4
 
5 5
 IFS=$'\n'
6 6
 files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
... ...
@@ -60,7 +60,7 @@ if [ "$1" != '--release-regardless-of-test-failure' ]; then
60 60
 	)
61 61
 fi
62 62
 
63
-VERSION=$(cat VERSION)
63
+VERSION=$(< VERSION)
64 64
 BUCKET=$AWS_S3_BUCKET
65 65
 
66 66
 # These are the 2 keys we've used to sign the deb's
... ...
@@ -71,23 +71,23 @@ BUCKET=$AWS_S3_BUCKET
71 71
 
72 72
 setup_s3() {
73 73
 	# Try creating the bucket. Ignore errors (it might already exist).
74
-	s3cmd mb s3://$BUCKET 2>/dev/null || true
74
+	s3cmd mb "s3://$BUCKET" 2>/dev/null || true
75 75
 	# Check access to the bucket.
76 76
 	# s3cmd has no useful exit status, so we cannot check that.
77 77
 	# Instead, we check if it outputs anything on standard output.
78 78
 	# (When there are problems, it uses standard error instead.)
79
-	s3cmd info s3://$BUCKET | grep -q .
79
+	s3cmd info "s3://$BUCKET" | grep -q .
80 80
 	# Make the bucket accessible through website endpoints.
81
-	s3cmd ws-create --ws-index index --ws-error error s3://$BUCKET
81
+	s3cmd ws-create --ws-index index --ws-error error "s3://$BUCKET"
82 82
 }
83 83
 
84 84
 # write_to_s3 uploads the contents of standard input to the specified S3 url.
85 85
 write_to_s3() {
86 86
 	DEST=$1
87 87
 	F=`mktemp`
88
-	cat > $F
89
-	s3cmd --acl-public --mime-type='text/plain' put $F $DEST
90
-	rm -f $F
88
+	cat > "$F"
89
+	s3cmd --acl-public --mime-type='text/plain' put "$F" "$DEST"
90
+	rm -f "$F"
91 91
 }
92 92
 
93 93
 s3_url() {
... ...
@@ -246,20 +246,20 @@ release_build() {
246 246
 # 1. A full APT repository is published at $BUCKET/ubuntu/
247 247
 # 2. Instructions for using the APT repository are uploaded at $BUCKET/ubuntu/index
248 248
 release_ubuntu() {
249
-	[ -e bundles/$VERSION/ubuntu ] || {
249
+	[ -e "bundles/$VERSION/ubuntu" ] || {
250 250
 		echo >&2 './hack/make.sh must be run before release_ubuntu'
251 251
 		exit 1
252 252
 	}
253 253
 
254 254
 	# Sign our packages
255 255
 	dpkg-sig -g "--passphrase $GPG_PASSPHRASE" -k releasedocker \
256
-		--sign builder bundles/$VERSION/ubuntu/*.deb
256
+		--sign builder "bundles/$VERSION/ubuntu/"*.deb
257 257
 
258 258
 	# Setup the APT repo
259 259
 	APTDIR=bundles/$VERSION/ubuntu/apt
260
-	mkdir -p $APTDIR/conf $APTDIR/db
261
-	s3cmd sync s3://$BUCKET/ubuntu/db/ $APTDIR/db/ || true
262
-	cat > $APTDIR/conf/distributions <<EOF
260
+	mkdir -p "$APTDIR/conf" "$APTDIR/db"
261
+	s3cmd sync "s3://$BUCKET/ubuntu/db/" "$APTDIR/db/" || true
262
+	cat > "$APTDIR/conf/distributions" <<EOF
263 263
 Codename: docker
264 264
 Components: main
265 265
 Architectures: amd64 i386
... ...
@@ -267,19 +267,19 @@ EOF
267 267
 
268 268
 	# Add the DEB package to the APT repo
269 269
 	DEBFILE=bundles/$VERSION/ubuntu/lxc-docker*.deb
270
-	reprepro -b $APTDIR includedeb docker $DEBFILE
270
+	reprepro -b "$APTDIR" includedeb docker "$DEBFILE"
271 271
 
272 272
 	# Sign
273 273
 	for F in $(find $APTDIR -name Release); do
274
-		gpg -u releasedocker --passphrase $GPG_PASSPHRASE \
274
+		gpg -u releasedocker --passphrase "$GPG_PASSPHRASE" \
275 275
 			--armor --sign --detach-sign \
276
-			--output $F.gpg $F
276
+			--output "$F.gpg" "$F"
277 277
 	done
278 278
 
279 279
 	# Upload keys
280
-	s3cmd sync $HOME/.gnupg/ s3://$BUCKET/ubuntu/.gnupg/
281
-	gpg --armor --export releasedocker > bundles/$VERSION/ubuntu/gpg
282
-	s3cmd --acl-public put bundles/$VERSION/ubuntu/gpg s3://$BUCKET/gpg
280
+	s3cmd sync "$HOME/.gnupg/" "s3://$BUCKET/ubuntu/.gnupg/"
281
+	gpg --armor --export releasedocker > "bundles/$VERSION/ubuntu/gpg"
282
+	s3cmd --acl-public put "bundles/$VERSION/ubuntu/gpg" "s3://$BUCKET/gpg"
283 283
 
284 284
 	local gpgFingerprint=36A1D7869245C8950F966E92D8576A8BA88D21E9
285 285
 	if [[ $BUCKET == test* ]]; then
... ...
@@ -287,7 +287,7 @@ EOF
287 287
 	fi
288 288
 
289 289
 	# Upload repo
290
-	s3cmd --acl-public sync $APTDIR/ s3://$BUCKET/ubuntu/
290
+	s3cmd --acl-public sync "$APTDIR/" "s3://$BUCKET/ubuntu/"
291 291
 	cat <<EOF | write_to_s3 s3://$BUCKET/ubuntu/index
292 292
 # Check that HTTPS transport is available to APT
293 293
 if [ ! -e /usr/lib/apt/methods/https ]; then
... ...
@@ -312,14 +312,14 @@ EOF
312 312
 
313 313
 	# Add redirect at /ubuntu/info for URL-backwards-compatibility
314 314
 	rm -rf /tmp/emptyfile && touch /tmp/emptyfile
315
-	s3cmd --acl-public --add-header='x-amz-website-redirect-location:/ubuntu/' --mime-type='text/plain' put /tmp/emptyfile s3://$BUCKET/ubuntu/info
315
+	s3cmd --acl-public --add-header='x-amz-website-redirect-location:/ubuntu/' --mime-type='text/plain' put /tmp/emptyfile "s3://$BUCKET/ubuntu/info"
316 316
 
317 317
 	echo "APT repository uploaded. Instructions available at $(s3_url)/ubuntu"
318 318
 }
319 319
 
320 320
 # Upload binaries and tgz files to S3
321 321
 release_binaries() {
322
-	[ -e bundles/$VERSION/cross/linux/amd64/docker-$VERSION ] || {
322
+	[ -e "bundles/$VERSION/cross/linux/amd64/docker-$VERSION" ] || {
323 323
 		echo >&2 './hack/make.sh must be run before release_binaries'
324 324
 		exit 1
325 325
 	}
... ...
@@ -341,29 +341,29 @@ EOF
341 341
 
342 342
 	# Add redirect at /builds/info for URL-backwards-compatibility
343 343
 	rm -rf /tmp/emptyfile && touch /tmp/emptyfile
344
-	s3cmd --acl-public --add-header='x-amz-website-redirect-location:/builds/' --mime-type='text/plain' put /tmp/emptyfile s3://$BUCKET/builds/info
344
+	s3cmd --acl-public --add-header='x-amz-website-redirect-location:/builds/' --mime-type='text/plain' put /tmp/emptyfile "s3://$BUCKET/builds/info"
345 345
 
346 346
 	if [ -z "$NOLATEST" ]; then
347 347
 		echo "Advertising $VERSION on $BUCKET as most recent version"
348
-		echo $VERSION | write_to_s3 s3://$BUCKET/latest
348
+		echo "$VERSION" | write_to_s3 "s3://$BUCKET/latest"
349 349
 	fi
350 350
 }
351 351
 
352 352
 # Upload the index script
353 353
 release_index() {
354
-	sed "s,url='https://get.docker.com/',url='$(s3_url)/'," hack/install.sh | write_to_s3 s3://$BUCKET/index
354
+	sed "s,url='https://get.docker.com/',url='$(s3_url)/'," hack/install.sh | write_to_s3 "s3://$BUCKET/index"
355 355
 }
356 356
 
357 357
 release_test() {
358 358
 	if [ -e "bundles/$VERSION/test" ]; then
359
-		s3cmd --acl-public sync bundles/$VERSION/test/ s3://$BUCKET/test/
359
+		s3cmd --acl-public sync "bundles/$VERSION/test/" "s3://$BUCKET/test/"
360 360
 	fi
361 361
 }
362 362
 
363 363
 setup_gpg() {
364 364
 	# Make sure that we have our keys
365
-	mkdir -p $HOME/.gnupg/
366
-	s3cmd sync s3://$BUCKET/ubuntu/.gnupg/ $HOME/.gnupg/ || true
365
+	mkdir -p "$HOME/.gnupg/"
366
+	s3cmd sync "s3://$BUCKET/ubuntu/.gnupg/" "$HOME/.gnupg/" || true
367 367
 	gpg --list-keys releasedocker >/dev/null || {
368 368
 		gpg --gen-key --batch <<EOF
369 369
 Key-Type: RSA