Skip to content

Commit 56f791a

Browse files
committed
Fix permission trouble writing to /dev/stderr when running within docker. Exit if running in an unexpected environment. Fixed a typo in an informational message. Refined the hanling of ~/.docker-info files. Improved the permission mods on the unpacked mysql files (matching the permissions mysql prefers).
- Legacy-Id: 10484
1 parent c8b534f commit 56f791a

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

docker/run

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ EOF
5353

5454
# ----------------------------------------------------------------------
5555
function die() {
56-
echo -e "\n$program: error: $*" > /dev/stderr
56+
echo -e "\n$program: error: $*" >&2
5757
exit 1
5858
}
5959

@@ -134,18 +134,32 @@ if [ "$(uname)" != "Linux" ]; then
134134
else
135135
die "Could not find boot2docker or docker-machine -- you need to set one of those before running this script."
136136
fi
137+
else
138+
die "Didn't expect to run this script on Linux -- are you inside docker?"
137139
fi
138140

141+
139142
if [ $($machine status) != "running" ]; then
140-
echo "The docker VM doesn't seem to be running; will attempt to start it by doing '$$ $machine $up':"
143+
echo "The docker VM doesn't seem to be running; will attempt to start it by doing '\$ $machine $up':"
141144
$machine $up || die "Failed taking up the Docker VM"
142145
fi
143146

144-
145-
if [ ! -f ~/.docker-info ]; then
146-
$machine $env 2>/dev/null | grep DOCKER_ > ~/.docker-info
147+
if [ -f "$machine" ]; then
148+
if [ $($machine status | tr "A-Z" "a-z") = "running" ]; then
149+
tmpfile=$(mktemp docker.run.XXXXXXXX)
150+
if $machine $env 2>/dev/null | grep DOCKER_ > $tmpfile; then
151+
mv $tmpfile ~/.docker-info
152+
elif printenv | grep DOCKER_ > $tmpfile; then
153+
mv $tmpfile ~/.docker-info
154+
else
155+
rm $tmpfile
156+
die "Failed setting the appropriate DOCKER_* environment variables."
157+
fi
158+
. ~/.docker-info
159+
else
160+
rm -f ~/.docker-info
161+
fi
147162
fi
148-
. ~/.docker-info
149163

150164

151165
echo ""
@@ -162,7 +176,7 @@ to bail out here. Quitting."
162176
if [ -n "$DOWNLOAD" ]; then
163177
(
164178
cd $(dirname $MYSQLDIR)
165-
wget -N $URL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
179+
wget -N $URL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R g+rX mysql
166180
)
167181
[ -d "$MYSQLDIR" ] || die "The download seems to have failed; still no $MYSQLDIR. Giving up."
168182
else

0 commit comments

Comments
 (0)