mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-19 13:29:35 +00:00
WIP -- fixing some shellcheck issues in scope
This commit is contained in:
74
scope
74
scope
@@ -15,7 +15,7 @@ usage() {
|
||||
}
|
||||
|
||||
SCRIPT_VERSION="(unreleased version)"
|
||||
if [ "$SCRIPT_VERSION" = "(unreleased version)" ] ; then
|
||||
if [ "$SCRIPT_VERSION" = "(unreleased version)" ]; then
|
||||
IMAGE_VERSION=latest
|
||||
else
|
||||
IMAGE_VERSION=$SCRIPT_VERSION
|
||||
@@ -60,8 +60,8 @@ check_docker_access() {
|
||||
MIN_DOCKER_VERSION=1.6.0
|
||||
|
||||
check_docker_version() {
|
||||
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') ||
|
||||
[ -z "$DOCKER_VERSION" ] ; then
|
||||
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') \
|
||||
|| [ -z "$DOCKER_VERSION" ]; then
|
||||
echo "ERROR: Unable to parse docker version" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -78,22 +78,22 @@ check_docker_version() {
|
||||
\( "$DOCKER_VERSION_MAJOR" -eq "$MIN_DOCKER_VERSION_MAJOR" -a \
|
||||
\( "$DOCKER_VERSION_MINOR" -lt "$MIN_DOCKER_VERSION_MINOR" -o \
|
||||
\( "$DOCKER_VERSION_MINOR" -eq "$MIN_DOCKER_VERSION_MINOR" -a \
|
||||
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ] ; then
|
||||
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ]; then
|
||||
echo "ERROR: scope requires Docker version $MIN_DOCKER_VERSION or later; you are running $DOCKER_VERSION" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_probe_only() {
|
||||
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
|
||||
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
|
||||
}
|
||||
|
||||
check_docker_for_mac() {
|
||||
[ "$(uname)" = "Darwin" ] \
|
||||
&& [ -S /var/run/docker.sock ] \
|
||||
&& [ ! "${DOCKER_HOST+x}" = x ] \
|
||||
&& [ "${HOME+x}" = x ] \
|
||||
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
|
||||
[ "$(uname)" = "Darwin" ] \
|
||||
&& [ -S /var/run/docker.sock ] \
|
||||
&& [ ! "${DOCKER_HOST+x}" = x ] \
|
||||
&& [ "${HOME+x}" = x ] \
|
||||
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
|
||||
}
|
||||
|
||||
# Check that a container named $1 with image $2 is not running
|
||||
@@ -125,32 +125,32 @@ check_not_running() {
|
||||
}
|
||||
|
||||
create_plugins_dir() {
|
||||
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
|
||||
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
|
||||
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
|
||||
# secondly Docker for Mac would have to be configured to share this path. The result
|
||||
# of this "feature" is an error message: "The path /var/run/scope/plugins
|
||||
# is not shared from OS X and does not belong to the system."
|
||||
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
|
||||
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
|
||||
docker run --rm --entrypoint=/bin/sh \
|
||||
-v /var/run:/var/run \
|
||||
$SCOPE_IMAGE -c "mkdir -p /var/run/scope/plugins"
|
||||
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
|
||||
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
|
||||
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
|
||||
# secondly Docker for Mac would have to be configured to share this path. The result
|
||||
# of this "feature" is an error message: "The path /var/run/scope/plugins
|
||||
# is not shared from OS X and does not belong to the system."
|
||||
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
|
||||
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
|
||||
docker run --rm --entrypoint=/bin/sh \
|
||||
-v /var/run:/var/run \
|
||||
$SCOPE_IMAGE -c "mkdir -p /var/run/scope/plugins"
|
||||
}
|
||||
|
||||
launch_command() {
|
||||
echo docker run --privileged -d --name=$SCOPE_CONTAINER_NAME --net=host --pid=host \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /var/run/scope/plugins:/var/run/scope/plugins \
|
||||
-e CHECKPOINT_DISABLE \
|
||||
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker=true
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /var/run/scope/plugins:/var/run/scope/plugins \
|
||||
-e CHECKPOINT_DISABLE \
|
||||
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker=true
|
||||
}
|
||||
|
||||
launch_docker4mac_app_command() {
|
||||
echo docker run -d --name=$SCOPE_APP_CONTAINER_NAME \
|
||||
-e CHECKPOINT_DISABLE \
|
||||
-p 0.0.0.0:4040:4040 \
|
||||
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe
|
||||
-e CHECKPOINT_DISABLE \
|
||||
-p 0.0.0.0:4040:4040 \
|
||||
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe
|
||||
}
|
||||
|
||||
launch() {
|
||||
@@ -172,7 +172,7 @@ check_docker_version
|
||||
|
||||
case "$COMMAND" in
|
||||
command)
|
||||
# TODO: properly escape/quote the output of "$@"
|
||||
# TODO: properly escape/quote the output of "$@"
|
||||
echo $(launch_command) "$@"
|
||||
;;
|
||||
|
||||
@@ -207,9 +207,9 @@ EOF
|
||||
docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope \
|
||||
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --dry-run $@
|
||||
|
||||
if check_docker_for_mac ; then
|
||||
if check_docker_for_mac; then
|
||||
create_plugins_dir
|
||||
if check_probe_only ; then
|
||||
if check_probe_only; then
|
||||
launch "$@"
|
||||
exit
|
||||
fi
|
||||
@@ -231,7 +231,7 @@ EOF
|
||||
fi
|
||||
|
||||
launch "$@"
|
||||
if ! check_probe_only ; then
|
||||
if ! check_probe_only; then
|
||||
IP_ADDRS=$(docker run --rm --net=host --entrypoint /bin/sh $SCOPE_IMAGE -c "$IP_ADDR_CMD")
|
||||
print_app_endpoints $IP_ADDRS
|
||||
fi
|
||||
@@ -240,12 +240,12 @@ EOF
|
||||
|
||||
stop)
|
||||
[ $# -eq 0 ] || usage
|
||||
if docker inspect $SCOPE_CONTAINER_NAME >/dev/null 2>&1 ; then
|
||||
docker stop $SCOPE_CONTAINER_NAME >/dev/null
|
||||
if docker inspect $SCOPE_CONTAINER_NAME >/dev/null 2>&1; then
|
||||
docker stop $SCOPE_CONTAINER_NAME >/dev/null
|
||||
fi
|
||||
if check_docker_for_mac ; then
|
||||
if docker inspect $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1 ; then
|
||||
docker stop $SCOPE_APP_CONTAINER_NAME >/dev/null
|
||||
if check_docker_for_mac; then
|
||||
if docker inspect $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1; then
|
||||
docker stop $SCOPE_APP_CONTAINER_NAME >/dev/null
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user