Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run shellcheck against scripts #4280

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ scripts:
srcs:
- components/**/*
script: |
GO_COMPONENTS=( content-service-api image-builder-api registry-facade-api supervisor-api ws-daemon-api ws-manager-api ws-manager-bridge-api )
GO_COMPONENTS=( local-app-api content-service-api image-builder-api registry-facade-api supervisor-api ws-daemon-api ws-manager-api ws-manager-bridge-api )

for COMPONENT in "${GO_COMPONENTS[@]}";do
echo "Generating code for component $COMPONENT..."
Expand All @@ -108,7 +108,7 @@ scripts:
popd > /dev/null
done

WEB_COMPONENTS=( supervisor-api/typescript-grpc supervisor-api/typescript-rest supervisor-api/typescript-grpcweb )
WEB_COMPONENTS=( local-app-api/typescript-grpcweb supervisor-api/typescript-grpc supervisor-api/typescript-grpcweb )
for COMPONENT in "${WEB_COMPONENTS[@]}";do
echo "Generating code for component $COMPONENT..."
pushd $COMPONENT > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion components/blobserve/telepresence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ if [ "$1" == "intp" ]; then
exit $?
fi

telepresence --mount /tmp/c --swap-deployment registry-facade --method vpn-tcp --run $0 dbg-intp
telepresence --mount /tmp/c --swap-deployment registry-facade --method vpn-tcp --run "$0" dbg-intp
8 changes: 5 additions & 3 deletions components/common-go/go-get-kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ fi
set -euo pipefail

echo "Retrieving kubernetes module file"
GM=$(go mod download -json k8s.io/kubernetes@v1.$VERSION | jq -r .GoMod)
MODS=($(cat $GM | egrep "^\s+k8s.io/.*v0.0.0$" | tr -d '\t' | cut -d ' ' -f 1))
GM=$(go mod download -json k8s.io/kubernetes@v1."$VERSION" | jq -r .GoMod)
# shellcheck disable=SC2002,SC2207
MODS=($(cat "$GM" | grep -E "^\s+k8s.io/.*v0.0.0$" | tr -d '\t' | cut -d ' ' -f 1))

useSemver=$(echo "console.log(\"1.${VERSION}\" >= \"1.17\")" | node -)
if [ "$useSemver" = "true" ]; then
echo "Version is newer than 1.17 - using semver"
fi

echo "Adding ${MODS[@]}"
echo Adding "${MODS[@]}"
for MOD in "${MODS[@]}"; do
if [ "$useSemver" = "true" ]; then
V="v0.${VERSION}"
Expand All @@ -35,4 +36,5 @@ for MOD in "${MODS[@]}"; do
fi
go mod edit "-replace=${MOD}=${MOD}@${V}"
done

go get -v ./...
11 changes: 6 additions & 5 deletions components/content-service-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)/../../
COMPONENTS_DIR=$ROOT_DIR/components
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/../../
COMPONENTS_DIR="$ROOT_DIR"/components

# include protoc bash functions
source $ROOT_DIR/scripts/protoc-generator.sh
# shellcheck disable=SC1090,SC1091
source "$ROOT_DIR"/scripts/protoc-generator.sh

install_dependencies
go_protoc $COMPONENTS_DIR
typescript_protoc $COMPONENTS_DIR
go_protoc "$COMPONENTS_DIR"
typescript_protoc "$COMPONENTS_DIR"

go generate typescript/util/generate-ws-ready.go

Expand Down
10 changes: 6 additions & 4 deletions components/dashboard/remove-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
rm -rvf dist/*.map;

# ensure all files using Google Analytics have the proper format
# shellcheck disable=SC2044
for i in $(find public/ -name "*.html"); do
if grep -q "Global site tag" $i; then
if ! grep -q -- "-- gtag end --" $i; then
if grep -q "Global site tag" "$i"; then
if ! grep -q -- "-- gtag end --" "$i"; then
echo "$i does not have a gtag end marker. This would break the remove-sources.sh script."
echo 'Please add <!-- gtag end --> after the Google Analytics block'
exit -1
exit 1
fi
fi
done

# remove Google Analytics
echo "BEWARE: This script actually modifies files in the source tree"
rm public/google2db8c31aefd7ebbd.html
# shellcheck disable=SC2044
for i in $(find public/ -name "*.html"); do
sed -i '/<!-- Global site tag/,/gtag end/d' $i;
sed -i '/<!-- Global site tag/,/gtag end/d' "$i";
done
10 changes: 6 additions & 4 deletions components/ide/code/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# the bash history.
set +o history
history -c
truncate -s 0 $HISTFILE
truncate -s 0 "$HISTFILE"

# This is the main entrypoint to workspace container in Gitpod. It is called (and controlled) by the supervisor
# container root process.
Expand All @@ -27,8 +27,10 @@ export USER=gitpod
# (+ compatibility period)
# Also to mitigate compatibility issues let's try to source recently added configuration explicitly
[ -d "/home/gitpod/.sdkman" ] && [ -z "$SDKMAN_DIR" ] && export SDKMAN_DIR="/home/gitpod/.sdkman"
# shellcheck disable=SC1090,SC1091
[ -s /home/gitpod/.sdkman/bin/sdkman-init.sh ] && [ -z "$SDKMAN_VERSION" ] && source "/home/gitpod/.sdkman/bin/sdkman-init.sh"
[ -s ~/.nvm/nvm-lazy.sh ] && source ~/.nvm/nvm-lazy.sh
# shellcheck disable=SC1090,SC1091
[ -s ~/.nvm/nvm-lazy.sh ] && source /home/gitpod/.nvm/nvm-lazy.sh

cd /ide
exec /ide/node/bin/gitpod-node ./out/gitpod.js $*
cd /ide || exit
exec /ide/node/bin/gitpod-node ./out/gitpod.js "$@"
14 changes: 7 additions & 7 deletions components/ide/theia/package-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ echo "$BINARY: Starting rewiring libs to $DST"

[ -d "$DST" ] || mkdir -p "$DST"

INTERPRETER_ORIG=$(patchelf --print-interpreter $BINARY 2>/dev/null)
if [ ! -z "$INTERPRETER_ORIG" ]; then
INTERPRETER_DST="${DST}$(basename $INTERPRETER_ORIG)"
INTERPRETER_ORIG=$(patchelf --print-interpreter "$BINARY" 2>/dev/null)
if [ -n "$INTERPRETER_ORIG" ]; then
INTERPRETER_DST="${DST}$(basename "$INTERPRETER_ORIG")"
[ -f "${INTERPRETER_DST}" ] || cp "${INTERPRETER_ORIG}" "${INTERPRETER_DST}"
patchelf --set-interpreter "${INTERPRETER_DST}" "${BINARY}"
echo "${BINARY}: changed ELF interpreter from ${INTERPRETER_ORIG} to ${INTERPRETER_DST}"
Expand All @@ -39,8 +39,8 @@ do
continue
fi
if [ -f "${LIB_ORIG}" ]; then
LIB_DST="${DST}$(basename $LIB_ORIG)"
if [ ! -f $LIB_DST ]; then
LIB_DST="${DST}$(basename "$LIB_ORIG")"
if [ ! -f "$LIB_DST" ]; then
cp "${LIB_ORIG}" "${LIB_DST}"
"$0" "${LIB_DST}"
fi
Expand All @@ -49,6 +49,6 @@ do
else
echo "${BINARY}: library $LIB_ORIG not found."
fi
done < <(ldd $BINARY 2>/dev/null)
done < <(ldd "$BINARY" 2>/dev/null)

echo "$BINARY: Finished rewiring libs to $DST"
echo "$BINARY: Finished rewiring libs to $DST"
10 changes: 6 additions & 4 deletions components/ide/theia/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# the bash history.
set +o history
history -c
truncate -s 0 $HISTFILE
truncate -s 0 "$HISTFILE"

# This is the main entrypoint to workspace container in Gitpod. It is called (and controlled) by the supervisor
# container root process.
Expand All @@ -27,8 +27,10 @@ export USER=gitpod
# (+ compatibility period)
# Also to mitigate compatibility issues let's try to source recently added configuration explicitly
[ -d "/home/gitpod/.sdkman" ] && [ -z "$SDKMAN_DIR" ] && export SDKMAN_DIR="/home/gitpod/.sdkman"
# shellcheck disable=SC1090,SC1091
[ -s /home/gitpod/.sdkman/bin/sdkman-init.sh ] && [ -z "$SDKMAN_VERSION" ] && source "/home/gitpod/.sdkman/bin/sdkman-init.sh"
[ -s ~/.nvm/nvm-lazy.sh ] && source ~/.nvm/nvm-lazy.sh
# shellcheck disable=SC1090,SC1091
[ -s ~/.nvm/nvm-lazy.sh ] && source /home/gitpod/.nvm/nvm-lazy.sh

cd /theia/theia-app/app
exec /theia/node/bin/gitpod-node ./src-gen/backend/main.js --vscode-api-version=1.53.2 $*
cd /theia/theia-app/app || exit
exec /theia/node/bin/gitpod-node ./src-gen/backend/main.js --vscode-api-version=1.53.2 "$@"
11 changes: 6 additions & 5 deletions components/image-builder-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)/../../
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/../../
COMPONENTS_DIR=$ROOT_DIR/components

# include protoc bash functions
source $ROOT_DIR/scripts/protoc-generator.sh
# shellcheck disable=SC1090,SC1091
source "$ROOT_DIR"/scripts/protoc-generator.sh

install_dependencies
go_protoc $COMPONENTS_DIR
typescript_protoc $COMPONENTS_DIR
go_protoc "$COMPONENTS_DIR"
typescript_protoc "$COMPONENTS_DIR"

go generate typescript/util/generate-ws-ready.go

Expand All @@ -31,7 +32,7 @@ mockgen \
popd

pushd typescript/src
node $COMPONENTS_DIR/content-service-api/typescript/patch-grpc-js.ts
node "$COMPONENTS_DIR"/content-service-api/typescript/patch-grpc-js.ts
popd

update_license
4 changes: 2 additions & 2 deletions components/image-builder/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# This script builds the image builder and replaces the current deployment with it.

docker ps &> /dev/null || (echo "You need a working Docker daemon. Maybe set DOCKER_HOST?"; exit -1)
docker ps &> /dev/null || (echo "You need a working Docker daemon. Maybe set DOCKER_HOST?"; exit 1)
gcloud auth list | grep typefox &>/dev/null || (echo "Login using 'gcloud auth login' for the docker push to work"; exit 1)

leeway build .:docker -Dversion=dev
devImage=eu.gcr.io/gitpod-dev/image-builder:dev

kubectl patch deployment image-builder --patch '{"spec": {"template": {"spec": {"containers": [{"name": "service","image": "'$devImage'"}]}}}}'
kubectl get pods --no-headers -o=custom-columns=:metadata.name | grep image-builder | xargs kubectl delete pod
kubectl get pods --no-headers -o=custom-columns=:metadata.name | grep image-builder | xargs kubectl delete pod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -e;

# Install necessary tools only if they are not yet installed
INSTALLED_PACKAGES=$(apk list -I git bash | wc -l)
if [ $INSTALLED_PACKAGES != 2 ]; then
if [ "$INSTALLED_PACKAGES" != 2 ]; then
# Install
apk add --no-cache --update \
git \
Expand Down Expand Up @@ -44,13 +44,13 @@ if ! id -u gitpod; then
chown -R gitpod:gitpod /home/gitpod/;
else
USER_ID=$(id -u gitpod)
if [ $USER_ID -eq 33333 ]; then
if [ "$USER_ID" -eq 33333 ]; then
# users exists and has user id 33333. We hope that the user does not have ID 0, because that grants root privileges
echo "Found user 'gitpod'. Reusing it.";
echo "gitpod:gitpod" | chpasswd;
else
# error
echo "Error: User 'gitpod' exists but does not have user-id 33333. The user-id is $UID";
echo "Error: User 'gitpod' exists but does not have user-id 33333. The user-id is $(id -u)";
exit 1;
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -e;

# Install necessary tools only if they are not yet installed
INSTALLED_PACKAGES=$(dpkg-query -f '${Package} ${Status}\n' -W bash-completion git | wc -l)
if [ $INSTALLED_PACKAGES != 2 ]; then
if [ "$INSTALLED_PACKAGES" != 2 ]; then
# The first 'clean' is needed to avoid apt-get detecting package meta data changes
# (like changed labels) which result in errors and broken builds/workspaces!
apt-get clean && rm -rf /var/lib/apt/lists/*;
Expand Down Expand Up @@ -52,13 +52,13 @@ if ! id -u gitpod; then
chown -R gitpod:gitpod /home/gitpod/;
else
USER_ID=$(id -u gitpod)
if [ $USER_ID -eq 33333 ]; then
if [ "$USER_ID" -eq 33333 ]; then
# users exists and has user id 33333. We hope that the user does not have ID 0, because that grants root privileges
echo "Found user 'gitpod'. Reusing it.";
echo "gitpod:gitpod" | chpasswd;
else
# error
echo "Error: User 'gitpod' exists but does not have user-id 33333. The user-id is $UID";
echo "Error: User 'gitpod' exists but does not have user-id 33333. The user-id is $(id -u)";
exit 1;
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Parameters:
# $1: BASE_IMAGE
BASE_DIR="$( cd "$( dirname $0 )/.." >/dev/null 2>&1 && pwd )"
BASE_DIR="$( cd "$( dirname "$0" )/.." >/dev/null 2>&1 && pwd )"
BASE_IMAGE=$1

# 1. Read distro value
Expand All @@ -24,10 +24,10 @@ rm -f $DISTRO_IN_FILE

# 2. Copy distro-specific files into workspace (default path in Google Cloud Container builder: /workspace)
DISTRO_PATH="$BASE_DIR/gitpod-layer/$DISTRO"
cp -R $DISTRO_PATH/. ./
cp -R "$DISTRO_PATH"/. ./

# 3. Copy the gitpod-cli into the workspaace
cp $BASE_DIR/gitpod-cli gitpod-cli
cp "$BASE_DIR"/gitpod-cli gitpod-cli

# 4. Create Dockerfile in /workspace starting from BASE_IMAGE and append the distro-specific part
echo "FROM $BASE_IMAGE" > Dockerfile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

USER_ID=$(id -u gitpod)
if [ $USER_ID -ne 33333 ]; then
if [ "$USER_ID" -ne 33333 ]; then
echo "user 'gitpod' not present or wrong user-id."
exit 1
fi
Expand Down
20 changes: 10 additions & 10 deletions components/image-builder/workspace-image-layer/tests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ BASE=$(pwd)

cd positive

for DOCKERFILE in $(ls *.dockerfile); do
for DOCKERFILE in ls *.dockerfile; do
echo "********* BEGIN TEST $DOCKERFILE ************"
BASE_IMG="$DOCKERFILE:test"
WORKSPACE_IMG="$DOCKERFILE:layered"
WORKSPACE="$(sudo rm -rf .tmp; mkdir .tmp; cd .tmp; pwd)"

cp "$BASE/"../scripts/* $WORKSPACE
cp "$BASE/positive/verify.sh" $WORKSPACE
docker build -f $DOCKERFILE -t $BASE_IMG .
docker run -v $WORKSPACE:/workspace $BASE_IMG /workspace/detect-distro.sh
cp "$BASE/"../scripts/* "$WORKSPACE"
cp "$BASE/positive/verify.sh" "$WORKSPACE"
docker build -f "$DOCKERFILE" -t "$BASE_IMG" .
docker run -v "$WORKSPACE":/workspace "$BASE_IMG" /workspace/detect-distro.sh
# Fake-satisfy generate-dockerfile.sh dependency
touch "$BASE/../gitpod-cli"
docker run -v $WORKSPACE:/workspace -v "$BASE/..":/base $BASE_IMG sh -c "cd /workspace && /base/scripts/generate-dockerfile.sh $BASE_IMG"
docker run -v "$WORKSPACE":/workspace -v "$BASE/..":/base "$BASE_IMG" sh -c "cd /workspace && /base/scripts/generate-dockerfile.sh $BASE_IMG"

docker build -f "$WORKSPACE/Dockerfile" -t $WORKSPACE_IMG $WORKSPACE
docker build -f "$WORKSPACE/Dockerfile" -t "$WORKSPACE_IMG" "$WORKSPACE"

echo "docker run -v $WORKSPACE:/workspace $WORKSPACE_IMG /workspace/verify.sh"
if ! docker run -v $WORKSPACE:/workspace --entrypoint="" $WORKSPACE_IMG /workspace/verify.sh; then
if ! docker run -v "$WORKSPACE:/workspace" --entrypoint="" "$WORKSPACE_IMG" /workspace/verify.sh; then
echo "verify.sh failed."
exit 1
fi
sudo rm -rf $WORKSPACE
sudo rm -rf "$WORKSPACE"
rm -f "$BASE/../gitpod-cli"
echo "********* END TEST $DOCKERFILE ************"
done
done
19 changes: 10 additions & 9 deletions components/local-app-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)/../../
COMPONENTS_DIR=$ROOT_DIR/components
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/../../
COMPONENTS_DIR="$ROOT_DIR"/components

# include protoc bash functions
source $ROOT_DIR/scripts/protoc-generator.sh
# shellcheck disable=SC1090,SC1091
source "$ROOT_DIR"/scripts/protoc-generator.sh

THIRD_PARTY_INCLUDES=${PROTOLOC:-$COMPONENTS_DIR/supervisor-api/third_party}
if [ ! -d $THIRD_PARTY_INCLUDES/google/api ]; then
if [ ! -d "$THIRD_PARTY_INCLUDES"/google/api ]; then
echo "missing $THIRD_PARTY_INCLUDES/google/api"
exit -1
exit 1
fi

# TODO (aledbf): refactor to avoid duplication
local_go_protoc() {
local ROOT_DIR=$1

protoc \
-I /usr/lib/protoc/include -I$COMPONENTS_DIR -I. -I$THIRD_PARTY_INCLUDES \
-I /usr/lib/protoc/include -I"$COMPONENTS_DIR" -I. -I"$THIRD_PARTY_INCLUDES" \
--go_out=go \
--go_opt=paths=source_relative \
--go-grpc_out=go \
--go-grpc_opt=paths=source_relative \
*.proto
./*.proto
}

install_dependencies
local_go_protoc $COMPONENTS_DIR
update_license
local_go_protoc "$COMPONENTS_DIR"
update_license
Loading