Skip to content

Commit

Permalink
Fix shellcheck errors in shell scripts in this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
moskyb committed Jun 12, 2024
1 parent 8b7c8fc commit 38402f3
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 48 deletions.
15 changes: 10 additions & 5 deletions .buildkite/steps/build-github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ set -e

echo '--- Getting agent version from build meta data'

export FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export FULL_AGENT_VERSION

AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export AGENT_VERSION

BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export BUILD_VERSION

echo "Full agent version: $FULL_AGENT_VERSION"
echo "Agent version: $AGENT_VERSION"
Expand All @@ -20,7 +25,7 @@ buildkite-agent artifact download "pkg/*" .
function build() {
echo "--- Building release for: $1"

./scripts/build-github-release.sh $1 $AGENT_VERSION
./scripts/build-github-release.sh "$1" "$AGENT_VERSION"
}

# Export the function so we can use it in xargs
Expand All @@ -30,4 +35,4 @@ export -f build
rm -rf releases

# Loop over all the binaries and build them
ls pkg/* | xargs -I {} bash -c "build {}"
find pkg/* -print0 | xargs -I {} bash -c "build {}"
11 changes: 8 additions & 3 deletions .buildkite/steps/build-rpm-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ set -euo pipefail

echo "--- Getting agent version from build meta data"

export FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export FULL_AGENT_VERSION

AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export AGENT_VERSION

BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export BUILD_VERSION

echo "Full agent version: $FULL_AGENT_VERSION"
echo "Agent version: $AGENT_VERSION"
Expand Down
18 changes: 13 additions & 5 deletions .buildkite/steps/github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ dry_run() {
}

echo '--- Getting credentials from SSM'
export GITHUB_RELEASE_ACCESS_TOKEN=$(aws ssm get-parameter --name /pipelines/agent/GITHUB_RELEASE_ACCESS_TOKEN --with-decryption --output text --query Parameter.Value --region us-east-1)
GITHUB_RELEASE_ACCESS_TOKEN=$(aws ssm get-parameter --name /pipelines/agent/GITHUB_RELEASE_ACCESS_TOKEN --with-decryption --output text --query Parameter.Value --region us-east-1)
export GITHUB_RELEASE_ACCESS_TOKEN

if [[ "$GITHUB_RELEASE_ACCESS_TOKEN" == "" ]]; then
echo "Error: Missing \$GITHUB_RELEASE_ACCESS_TOKEN"
Expand All @@ -19,10 +20,17 @@ fi

echo '--- Getting agent version from build meta data'

export FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export IS_PRERELEASE=$(buildkite-agent meta-data get "agent-is-prerelease")
FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export FULL_AGENT_VERSION

AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export AGENT_VERSION

BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export BUILD_VERSION

IS_PRERELEASE=$(buildkite-agent meta-data get "agent-is-prerelease")
export IS_PRERELEASE

echo "Full agent version: $FULL_AGENT_VERSION"
echo "Agent version: $AGENT_VERSION"
Expand Down
3 changes: 2 additions & 1 deletion .buildkite/steps/publish-debian-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ if ! findmnt --source tmpfs --target /root/.gnupg; then
fi

echo "fetching signing key..."
export GPG_SIGNING_KEY=$(aws ssm get-parameter --name /pipelines/agent/GPG_SIGNING_KEY --with-decryption --output text --query Parameter.Value --region us-east-1)
GPG_SIGNING_KEY=$(aws ssm get-parameter --name /pipelines/agent/GPG_SIGNING_KEY --with-decryption --output text --query Parameter.Value --region us-east-1)
export GPG_SIGNING_KEY

echo "fetching secret key..."
aws ssm get-parameter --name /pipelines/agent/GPG_SECRET_KEY_ASCII --with-decryption --output text --query Parameter.Value --region us-east-1 > ${secret_key_path}
Expand Down
3 changes: 2 additions & 1 deletion .buildkite/steps/publish-debian-packagecloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ echo "--- Installing dependencies"
gem install package_cloud

echo "--- Requesting OIDC token"
export PACKAGECLOUD_TOKEN="$(buildkite-agent oidc request-token --audience "https://packagecloud.io/${REPOSITORY}" --lifetime 300)"
PACKAGECLOUD_TOKEN="$(buildkite-agent oidc request-token --audience "https://packagecloud.io/${REPOSITORY}" --lifetime 300)"
export PACKAGECLOUD_TOKEN

echo "--- Pushing to Packagecloud"
dry_run package_cloud push "${REPOSITORY}/${DISTRO_VERSION}" deb/*.deb
2 changes: 1 addition & 1 deletion .buildkite/steps/publish-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parse_version() {
IFS='.' read -r -a parts <<< "${v%-*}"

for idx in $(seq 1 ${#parts[*]}) ; do
sed -e 's/ /./g' <<< "${parts[@]:0:$idx}"
sed -e 's/ /./g' <<< "${parts[@]:0:$idx// /.}"
done

[[ "${v%-*}" == "$v" ]] || echo "$v"
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/steps/publish-rpm-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ for ARCH in "x86_64" "i386" "aarch64"; do
"${ARCH_PATH}/repodata"

# Copy the new RPMs in.
find "rpm/" -type f -name "*${ARCH}*" | xargs cp -t "${ARCH_PATH}"
find "rpm/" -type f -name "*${ARCH}*" -print0 | xargs cp -t "${ARCH_PATH}"

echo "--- Updating yum repository for ${CODENAME}/${ARCH}"
if updaterepo "${ARCH_PATH}"; then
Expand All @@ -99,7 +99,7 @@ for ARCH in "x86_64" "i386" "aarch64"; do
"${ARCH_PATH}"

# Copy the new RPMs in again.
find "rpm/" -type f -name "*${ARCH}*" | xargs cp -t "${ARCH_PATH}"
find "rpm/" -type f -name "*${ARCH}*" -print0 | xargs cp -t "${ARCH_PATH}"

echo "--- Recreating yum repository for ${CODENAME}/${ARCH}"
createrepo "${ARCH_PATH}"
Expand Down
3 changes: 2 additions & 1 deletion .buildkite/steps/publish-rpm-packagecloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ echo "--- Installing dependencies"
gem install package_cloud

echo "--- Requesting OIDC token"
export PACKAGECLOUD_TOKEN="$(buildkite-agent oidc request-token --audience "https://packagecloud.io/${REPOSITORY}" --lifetime 300)"
PACKAGECLOUD_TOKEN="$(buildkite-agent oidc request-token --audience "https://packagecloud.io/${REPOSITORY}" --lifetime 300)"
export PACKAGECLOUD_TOKEN

echo "--- Pushing to Packagecloud"
dry_run package_cloud push "${REPOSITORY}/${DISTRO_VERSION}" rpm/*.rpm
16 changes: 12 additions & 4 deletions .buildkite/steps/release-homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ function to_json {

echo '--- Getting agent version from build meta data'

export FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export IS_PRERELEASE=$(buildkite-agent meta-data get "agent-is-prerelease")
FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full")
export FULL_AGENT_VERSION

AGENT_VERSION=$(buildkite-agent meta-data get "agent-version")
export AGENT_VERSION

BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build")
export BUILD_VERSION

IS_PRERELEASE=$(buildkite-agent meta-data get "agent-is-prerelease")
export IS_PRERELEASE


echo "Full agent version: $FULL_AGENT_VERSION"
echo "Agent version: $AGENT_VERSION"
Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ function buildkite-download {
echo -e "\033[31mFailed to download file: $1\033[0m\n"

cat $BUILDKITE_DOWNLOAD_TMP_FILE
exit $BUILDKITE_DOWNLOAD_EXIT_STATUS
exit "$BUILDKITE_DOWNLOAD_EXIT_STATUS"
fi
}

echo -e "Installing Version: \033[35mv$VERSION\033[0m"

# Default the destination folder
: ${DESTINATION:="$HOME/.buildkite-agent"}
: "${DESTINATION:="$HOME/.buildkite-agent"}"

# If they have a $HOME/.buildkite folder, rename it to `buildkite-agent` and
# symlink back to the old one. Since we changed the name of the folder, we
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
#
#!/usr/bin/env bash
# shellcheck disable=1090

### BEGIN INIT INFO
# Provides: buildkite-agent
# Required-Start: $network $local_fs $remote_fs
Expand All @@ -20,17 +21,16 @@ pid_file="/var/run/${name}.pid"
lock_dir="/var/lock/subsys"
lock_file="${lock_dir}/${name}"
log="/var/log/${name}.log"
stderr_log="/var/log/${name}.err"

[ -r /etc/default/${name} ] && . /etc/default/${name}
[ -r /etc/sysconfig/${name} ] && . /etc/sysconfig/${name}
[ -r "/etc/default/${name}" ] && . "/etc/default/${name}"
[ -r "/etc/sysconfig/${name}" ] && . "/etc/sysconfig/${name}"

get_pid() {
cat "$pid_file"
}

is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
[ -f "$pid_file" ] && ps "$(get_pid)" > /dev/null 2>&1
}

case "$1" in
Expand All @@ -53,9 +53,8 @@ case "$1" in
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
kill "$(get_pid)"
for _ in {1..10}; do
if ! is_running; then
break
fi
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/scripts/after-install-and-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# $1 will be the version being upgraded from if this is an upgrade
if [ "$1" = "" ] ; then
OPERATION="install"
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/scripts/after-remove.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# Remove the system service we installed
if command -v systemctl > /dev/null; then
rm -f /lib/systemd/system/buildkite-agent.service
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/scripts/before-install.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/usr/bin/env bash

true
2 changes: 2 additions & 0 deletions packaging/linux/scripts/before-remove.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# Check if upstart exists
command -v initctl > /dev/null
BK_UPSTART_EXISTS=$?
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/scripts/before-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/usr/bin/env bash

true
2 changes: 1 addition & 1 deletion scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fi
export CGO_ENABLED=0

# Generated files
"$(dirname $0)"/generate-acknowledgements.sh
"$(dirname "$0")"/generate-acknowledgements.sh

mkdir -p $BUILD_PATH
go build -v -ldflags "-X github.com/buildkite/agent/v3/version.buildNumber=${BUILD_NUMBER}" -o "${BUILD_PATH}/${BINARY_FILENAME}" .
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if [[ "${BINARY_PATH}" == *"windows"* ]]; then

info "Zipping up the files"
cd "${TMP_RELEASE_DIRECTORY}"
zip -X -r "../${RELEASE_FILE_NAME}" *
zip -X -r "../${RELEASE_FILE_NAME}" -- *
else
RELEASE_FILE_NAME="${RELEASE_NAME}.tar.gz"

Expand Down
13 changes: 7 additions & 6 deletions scripts/check-upstart-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ fi
config=${1} && shift

dbus_pid_file=$(/bin/mktemp)
exec 4<> ${dbus_pid_file}
exec 4<> "${dbus_pid_file}"

dbus_add_file=$(/bin/mktemp)
exec 6<> ${dbus_add_file}
exec 6<> "${dbus_add_file}"

/bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session

function clean {
kill $(cat ${dbus_pid_file})
rm -f ${dbus_pid_file} ${dbus_add_file}
kill "$(cat "${dbus_pid_file}")"
rm -f" ${dbus_pid_file}" "${dbus_add_file}"
exit 1
}
trap "{ clean; }" EXIT

export DBUS_SESSION_BUS_ADDRESS=$(cat ${dbus_add_file})
DBUS_SESSION_BUS_ADDRESS="$(cat "${dbus_add_file}")"
export DBUS_SESSION_BUS_ADDRESS

/bin/init-checkconf ${config}
/bin/init-checkconf "${config}"
14 changes: 9 additions & 5 deletions scripts/generate-acknowledgements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo 'Generating OSS attributions'
echo "GOOS=${GOOS:-not set}"
echo "GOARCH=${GOARCH:-not set}"

cd $(git rev-parse --show-toplevel)
cd "$(git rev-parse --show-toplevel)"

if [[ ! -f "./go.mod" ]]; then
echo "Couldn't find go.mod - are you in the agent repository?"
Expand All @@ -28,9 +28,13 @@ fi

# Create temporary directory and file
# TEMPFILE is not in TEMPDIR, because this causes infinite recursion later on.
export TEMPDIR="$(mktemp -d /tmp/generate-acknowledgements.XXXXXX)"
export TEMPFILE="$(mktemp /tmp/acknowledgements.XXXXXX)"
trap "rm -fr ${TEMPDIR} ${TEMPFILE}" EXIT
TEMPDIR="$(mktemp -d /tmp/generate-acknowledgements.XXXXXX)"
export TEMPDIR

TEMPFILE="$(mktemp /tmp/acknowledgements.XXXXXX)"
export TEMPFILE

trap 'rm -fr ${TEMPDIR} ${TEMPFILE}' EXIT

"${GO_LICENSES}" save . --save_path="${TEMPDIR}" --force

Expand All @@ -43,7 +47,7 @@ Licenses for the libraries used are reproduced below.
EOF

addfile() {
printf "\n\n---\n\n## %s\n\n\`\`\`\n" "${2:-${1#${TEMPDIR}/}}" >> "${TEMPFILE}"
printf "\n\n---\n\n## %s\n\n\`\`\`\n" "${2:-${1#"${TEMPDIR}"/}}" >> "${TEMPFILE}"
cat "$1" >> "${TEMPFILE}"
printf "\n\`\`\`\n" >> "${TEMPFILE}"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-debian-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ deb_s3_args=(
# Older versions were ok with prefix and bucket in the same parameter, but we now need to split them

echo "Parsing DEB_S3_BUCKET=$DEB_S3_BUCKET"
DEB_S3_BUCKET_ARRAY=(${DEB_S3_BUCKET//\// })
DEB_S3_BUCKET_ARRAY=("${DEB_S3_BUCKET//\// }")

if [[ ${#DEB_S3_BUCKET_ARRAY[@]} -gt 2 ]] ; then
echo "Expected $DEB_S3_BUCKET to have at most 1 path component"
Expand Down

0 comments on commit 38402f3

Please sign in to comment.