Skip to content

Commit

Permalink
Fix various linter issues
Browse files Browse the repository at this point in the history
Found via shellcheck.
  • Loading branch information
iaguis committed Jan 18, 2017
1 parent ec0b6dd commit 43d9f38
Show file tree
Hide file tree
Showing 34 changed files with 268 additions and 227 deletions.
4 changes: 2 additions & 2 deletions backend/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ SCOPE_SRC=$GOPATH/src/github.com/weaveworks/scope
# will have awkward ownership. So we switch to a user with the
# same user and group IDs as source directory. We have to set a
# few things up so that sudo works without complaining later on.
uid=$(stat --format="%u" $SCOPE_SRC)
gid=$(stat --format="%g" $SCOPE_SRC)
uid=$(stat --format="%u" "$SCOPE_SRC")
gid=$(stat --format="%g" "$SCOPE_SRC")
echo "weave:x:$uid:$gid::$SCOPE_SRC:/bin/sh" >>/etc/passwd
echo "weave:*:::::::" >>/etc/shadow
echo "weave ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
Expand Down
88 changes: 41 additions & 47 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
RELEASE_NAME=${RELEASE_NAME:-"Weave Scope"}
RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"}

PWD=`pwd`
WC="wc"
# Use GNU wc on Darwin
case $OSTYPE in darwin*) WC="gwc" ;; esac
PWD=$(pwd)

infer_release_type() {
if echo $1 | grep -qE '^v[0-9]+\.[0-9]+\.0+$' ; then
if echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.0+$' ; then
echo MAINLINE
elif echo $1 | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$' ; then
elif echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$' ; then
echo BRANCH
else
echo PRERELEASE
Expand All @@ -26,10 +23,12 @@ infer_release_type() {
setup() {
# Ensure we have exactly one annotated tag pointing at HEAD
HEAD_TAGS=$(git tag --points-at HEAD)
TAG_COUNT=$(echo $(echo $HEAD_TAGS | wc -w)) # mac hack
# shellcheck disable=SC2116
# shellcheck disable=SC2005
TAG_COUNT=$(echo "$(echo "$HEAD_TAGS" | wc -w)") # mac hack
case $TAG_COUNT in
1)
if [ $HEAD_TAGS != "latest_release" ] ; then
if [ "$HEAD_TAGS" != "latest_release" ] ; then
LATEST_TAG=$HEAD_TAGS
else
echo "Cannot determine version - latest_release points at HEAD" >&2
Expand All @@ -49,11 +48,11 @@ setup() {
;;
esac

RELEASE_TYPE=$(infer_release_type $LATEST_TAG)
RELEASE_TYPE=$(infer_release_type "$LATEST_TAG")
echo "== Inferred release type $RELEASE_TYPE from tag $LATEST_TAG"

LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG)
LATEST_TAG_COMMIT_SHA=$(git rev-list -1 $LATEST_TAG)
LATEST_TAG_SHA=$(git rev-parse "$LATEST_TAG")
LATEST_TAG_COMMIT_SHA=$(git rev-list -1 "$LATEST_TAG")
LATEST_RELEASE_SHA=$(git rev-parse latest_release)
LATEST_RELEASE_COMMIT_SHA=$(git rev-list -1 latest_release)
if [ "$RELEASE_TYPE" != 'PRERELEASE' ] ; then
Expand All @@ -69,20 +68,20 @@ build() {
setup

echo "== Clone repo at $LATEST_TAG for version $VERSION"
if [ -d $RELEASE_DIR ]; then
if [ -d "$RELEASE_DIR" ]; then
echo -e "\u2757 Release directory $RELEASE_DIR already exists, you may want to" >&2
echo -e "\trm -rf $RELEASE_DIR" >&2
exit 1
fi

## Clone the repo at the tag and go there
mkdir -p releases
git clone -q -b $LATEST_TAG . $RELEASE_DIR 2>/dev/null
cd $RELEASE_DIR
git clone -q -b "$LATEST_TAG" . "$RELEASE_DIR" 2>/dev/null
cd "$RELEASE_DIR"

## Check that the top changelog entry is this version
if ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) || \
! [ `echo "$latest_changelog" = "$VERSION"` ]; then
! [ "$latest_changelog" = "$VERSION" ]; then
echo -e "\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2
exit 1
fi
Expand All @@ -93,9 +92,9 @@ build() {
## Inject the version numbers and build the distributables
## (library versions?)
sed -i.tmp "s/SCRIPT_VERSION=\"[^\"]*\"/SCRIPT_VERSION=\"$VERSION\"/" ./scope
make SUDO=$SUDO SCOPE_VERSION=$VERSION DOCKERHUB_USER=$DOCKERHUB_USER
make SUDO="$SUDO" SCOPE_VERSION="$VERSION" DOCKERHUB_USER="$DOCKERHUB_USER"

if make tests SUDO=$SUDO; then
if make tests SUDO="$SUDO"; then
echo -e '\u2713 Tests pass'
else
echo -e "\u2757 Tests failed, probably best not publish this one" >&2
Expand All @@ -110,18 +109,18 @@ build() {
#fi

echo -e '\u2713 Build OK'
echo '** Release artefacts in' $RELEASE_DIR
echo '** Release artefacts in' "$RELEASE_DIR"
}

draft() {
setup

cd $PWD/$RELEASE_DIR
cd "$PWD"/"$RELEASE_DIR"

echo "== Sanity checks"

## Check that the tag exists by looking at github
if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_TAG_SHA >/dev/null 2>&1; then
if ! curl -sSf "https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_TAG_SHA" >/dev/null 2>&1; then
echo -e "\u2757 Tag $LATEST_TAG is not on GitHub, or is not the same as the local tag" >&2
echo -e "\thttps://github.com/$GITHUB_USER/scope/tags" >&2
echo "You may need to" >&2
Expand All @@ -133,31 +132,31 @@ draft() {

## Check that the version does not already exist by looking at github
## releases
if github-release info --user $GITHUB_USER --repo scope --tag $LATEST_TAG >/dev/null 2>&1; then
if github-release info --user "$GITHUB_USER" --repo scope --tag "$LATEST_TAG" >/dev/null 2>&1; then
echo -e "\u2757 Release $LATEST_TAG already exists on GitHub" >&2
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG" >&2
exit 1
fi

echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/scope:$VERSION
echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"

RELEASE_ARGS="--draft"
if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
RELEASE_ARGS="$RELEASE_ARGS --pre-release"
fi

echo "== Creating GitHub release $RELEASE_ARGS $RELEASE_NAME $VERSION"
github-release release $RELEASE_ARGS \
--user $GITHUB_USER \
github-release release "$RELEASE_ARGS" \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG \
--tag "$LATEST_TAG" \
--name "$RELEASE_NAME $VERSION" \
--description "$RELEASE_DESCRIPTION"

github-release upload \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG \
--tag "$LATEST_TAG" \
--name "scope" \
--file "./scope"

Expand All @@ -167,25 +166,20 @@ draft() {

publish() {
setup
cd $PWD/$RELEASE_DIR

UPDATE_LATEST=false
if [ "$RELEASE_TYPE" = 'MAINLINE' ] ; then
UPDATE_LATEST=true
fi
cd "$PWD"/"$RELEASE_DIR"

if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f $DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION
$SUDO docker push $DOCKERHUB_USER/scope:$VERSION
$SUDO docker tag -f "$DOCKERHUB_USER"/scope "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER/scope:$VERSION"
echo "** Docker images tagged and pushed"

echo "== Publishing pre-release on GitHub"

github-release publish \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG
--tag "$LATEST_TAG"

echo "** Pre-release $RELEASE_NAME $VERSION published at"
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"
Expand All @@ -199,44 +193,44 @@ publish() {
fi

## Check that the 'latest_release' tag exists by looking at github
if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_RELEASE_SHA >/dev/null 2>&1; then
if ! curl -sSf "https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_RELEASE_SHA" >/dev/null 2>&1; then
echo -e "\u2757 Tag latest_release is not on GitHub, or is not the same as the local tag" >&2
echo -e "\thttps://github.com/$GITHUB_USER/scope/tags" >&2
echo "You may need to" >&2
echo -e "\tgit push -f [email protected]:$GITHUB_USER/scope latest_release" >&2
exit 1
fi
echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/scope:$VERSION
echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"

echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f $DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION
$SUDO docker push $DOCKERHUB_USER/scope:$VERSION
$SUDO docker tag -f "$DOCKERHUB_USER"/scope "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER"/scope:$"VERSION"
echo "** Docker images tagged and pushed"

echo "== Publishing release on GitHub"

github-release publish \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG
--tag "$LATEST_TAG"

if github-release info --user $GITHUB_USER --repo scope \
if github-release info --user "$GITHUB_USER" --repo scope \
--tag latest_release >/dev/null 2>&1; then
github-release delete \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release
fi

github-release release \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release \
--name "$RELEASE_NAME latest ($VERSION)" \
--description "[Release Notes](https://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG)"

github-release upload \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release \
--name "scope" \
Expand Down
2 changes: 1 addition & 1 deletion bin/setup-circleci-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -eu
openssl base64 -d << EOF \
| openssl enc \
-out bin/do-setup-circleci-secrets \
-d -aes256 -pass pass:$1
-d -aes256 -pass pass:"$1"
U2FsdGVkX193YHZJXNzxU9GqigQaXWrA0AKd+BIjRcx7bmmKn/zSgOv+FfApRRjn
KGBd2ulZw9CwsftX0HWHzVdtpgqbJUW+FEma8eNldau4/f+T+yWTVpCNQXGc3DvB
cWYhmkoTfGWmI2v/0/Bv2TYkw7MAfjCocdluFAv7sSvYnSgIjoYxD4XXkTjLWy1P
Expand Down
2 changes: 1 addition & 1 deletion client/test/run-jankie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ echo "Testing $COMMIT on $DATE"
# ../../scope launch
# sleep 5

COMMIT="$COMMIT" DATE=$DATE HOST=$HOST DEBUG=scope* node ./perfjankie/main.js
COMMIT="$COMMIT" DATE=$DATE HOST=$HOST DEBUG="scope*" node ./perfjankie/main.js
4 changes: 3 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mkdir -p /var/run/weave

for arg in $@; do
for arg in "$@"; do
case "$arg" in
--no-app|--probe-only|--service-token*|--probe.token*)
touch /etc/service/app/down
Expand All @@ -13,9 +13,11 @@ for arg in $@; do
esac
done

# shellcheck disable=SC2034
ARGS=("$@")

typeset -p ARGS >/var/run/weave/scope-app.args
# shellcheck disable=SC2034
typeset -p ARGS >/var/run/weave/scope-probe.args

exec /home/weave/runsvinit
1 change: 1 addition & 0 deletions docker/run-app
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source /var/run/weave/scope-app.args

exec -a scope-app /home/weave/scope --mode app "${ARGS[@]}"
1 change: 1 addition & 0 deletions docker/run-probe
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source /var/run/weave/scope-probe.args

exec -a scope-probe /home/weave/scope --mode probe "${ARGS[@]}"
2 changes: 1 addition & 1 deletion extras/build_on_circle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

./in_parallel.sh "make RM=" $(find . -maxdepth 2 -name *.go -printf "%h\n" | sort -u | sed -n 's/\.\/\(.*\)/\1\/\1/p')
./in_parallel.sh "make RM=" "$(find . -maxdepth 2 -name "./*.go" -printf "%h\n" | sort -u | sed -n 's/\.\/\(.*\)/\1\/\1/p')"
1 change: 1 addition & 0 deletions extras/dialer/dialer
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readonly addr=$1
readonly max_dialer=${2:-50}

dialer=()
# shellcheck disable=SC2154
trap 'echo -n "stopping ... "; for c in "${dialer[@]}"; do docker rm -f "$c" >/dev/null; done; echo "done"' EXIT

while true; do
Expand Down
14 changes: 7 additions & 7 deletions extras/example/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set -ex

readonly ARG="$1"

if ! $(weave status 1>/dev/null 2>&1); then
if ! weave status 1>/dev/null 2>&1; then
WEAVE_NO_PLUGIN=y weave launch
fi

eval $(weave env)
eval "$(weave env)"

start_container() {
local IMAGE=$2
Expand All @@ -17,12 +17,12 @@ start_container() {
shift 3
local HOSTNAME=$BASENAME.weave.local

for i in $(seq $REPLICAS); do
if docker inspect $BASENAME$i >/dev/null 2>&1; then
docker rm -f $BASENAME$i
for i in $(seq "$REPLICAS"); do
if docker inspect "$BASENAME""$i" >/dev/null 2>&1; then
docker rm -f "$BASENAME""$i"
fi
if [ "$ARG" != "-rm" ]; then
docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE
docker run -d --name="$BASENAME""$i" --hostname="$HOSTNAME" "$@" "$IMAGE"
fi
done
}
Expand All @@ -33,6 +33,6 @@ start_container 1 redis redis
start_container 1 tomwilkie/qotd qotd
start_container 1 tomwilkie/echo echo
start_container 2 tomwilkie/app app
start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:$(weave docker-bridge-ip)
start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:"$(weave docker-bridge-ip)"
start_container 1 tomwilkie/client client

16 changes: 8 additions & 8 deletions extras/example/run_tracer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set -ex

readonly ARG="$1"

if ! $(weave status 1>/dev/null 2>&1); then
if ! weave status 1>/dev/null 2>&1; then
WEAVE_NO_PLUGIN=y weave launch
fi

eval $(weave env)
eval "$(weave env)"

start_container() {
local replicas=$1
Expand All @@ -30,14 +30,14 @@ start_container() {
;;
esac
done
local container_args="$@"
local container_args="$*"

for i in $(seq ${replicas}); do
if docker inspect ${basename}${i} >/dev/null 2>&1; then
docker rm -f ${basename}${i}
for i in $(seq "${replicas}"); do
if docker inspect "${basename}""${i}" >/dev/null 2>&1; then
docker rm -f "${basename}""${i}"
fi
docker run -d -e CHECKPOINT_DISABLE --name=${basename}${i} --hostname=${hostname} \
${docker_args} ${image} ${container_args}
docker run -d -e CHECKPOINT_DISABLE --name="${basename}""${i}" --hostname="${hostname}" \
"${docker_args}" "${image}" "${container_args}"
done
}

Expand Down
Loading

0 comments on commit 43d9f38

Please sign in to comment.