Skip to content

Commit 545ed67

Browse files
committed
Format shell scripts
1 parent 70c164f commit 545ed67

28 files changed

+168
-170
lines changed

.buildkite/steps/cleanup.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# shellcheck disable=SC2016
33
set -uxo pipefail
44

5-
if [[ $OSTYPE =~ ^darwin ]] ; then
5+
if [[ $OSTYPE =~ ^darwin ]]; then
66
cutoff_date=$(gdate --date='-1 days' +%Y-%m-%d)
77
cutoff_date_milli=$(gdate --date='-1 days' +%s%3N)
88
else
@@ -15,7 +15,7 @@ echo "--- Cleaning up resources older than ${cutoff_date}"
1515
echo "--- Deleting test managed secrets buckets created"
1616
aws s3api list-buckets \
1717
--output text \
18-
--query "$(printf 'Buckets[?CreationDate<`%s`].[Name]' "$cutoff_date" )" \
18+
--query "$(printf 'Buckets[?CreationDate<`%s`].[Name]' "$cutoff_date")" \
1919
| xargs -n1 \
2020
| grep -E 'buildkite-aws-stack-test-.*-managedsecretsbucket' \
2121
| xargs -n1 -t -I% aws s3 rb s3://% --force
@@ -25,14 +25,14 @@ aws s3api list-buckets \
2525
echo "--- Deleting old lambda logs after ${cutoff_date_milli}"
2626
aws logs describe-log-groups \
2727
--log-group-name-prefix "/aws/lambda/buildkite-aws-stack-test-" \
28-
--query "$(printf 'logGroups[?creationTime<`%s`].[logGroupName]' "$cutoff_date_milli" )" \
28+
--query "$(printf 'logGroups[?creationTime<`%s`].[logGroupName]' "$cutoff_date_milli")" \
2929
--output text \
3030
| xargs -n1 -t -I% aws logs delete-log-group --log-group-name "%"
3131

3232
echo "--- Deleting old cloudformation stacks"
3333
aws cloudformation describe-stacks \
3434
--output text \
35-
--query "$(printf 'Stacks[?CreationTime<`%s`].[StackName]' "$cutoff_date" )" \
35+
--query "$(printf 'Stacks[?CreationTime<`%s`].[StackName]' "$cutoff_date")" \
3636
| xargs -n1 \
3737
| grep -E 'buildkite-aws-stack-test-(linux|windows)-(amd64|arm64)-[[:digit:]]+|buildkite-elastic-ci-stack-service-role-[[:digit:]]+' \
3838
| xargs -n1 -t -I% aws cloudformation delete-stack --stack-name "%"

.buildkite/steps/copy.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wait_for_ami_to_be_available() {
2525
local image_state
2626

2727
while true; do
28-
image_state=$(aws ec2 describe-images --region "$region" --image-ids "$image_id" --output text --query 'Images[*].State');
28+
image_state=$(aws ec2 describe-images --region "$region" --image-ids "$image_id" --output text --query 'Images[*].State')
2929
echo "$image_id ($region) is $image_state"
3030

3131
if [[ "$image_state" == "available" ]]; then
@@ -43,10 +43,10 @@ get_image_name() {
4343
local region="$2"
4444

4545
aws ec2 describe-images \
46-
--image-ids "$image_id" \
47-
--output text \
48-
--region "$region" \
49-
--query 'Images[*].Name'
46+
--image-ids "$image_id" \
47+
--output text \
48+
--region "$region" \
49+
--query 'Images[*].Name'
5050
}
5151

5252
make_ami_public() {
@@ -59,7 +59,7 @@ make_ami_public() {
5959
--launch-permission "{\"Add\": [{\"Group\":\"all\"}]}"
6060
}
6161

62-
if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]] ; then
62+
if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]]; then
6363
echo "Must set an s3 bucket in BUILDKITE_AWS_STACK_BUCKET for temporary files"
6464
exit 1
6565
fi
@@ -99,17 +99,17 @@ source_region="${AWS_REGION}"
9999
mapping_file="build/mappings.yml"
100100

101101
# Read the source images from meta-data if no arguments are provided
102-
if [ $# -eq 0 ] ; then
103-
linux_amd64_source_image_id=$(buildkite-agent meta-data get "linux_amd64_image_id")
104-
linux_arm64_source_image_id=$(buildkite-agent meta-data get "linux_arm64_image_id")
105-
windows_amd64_source_image_id=$(buildkite-agent meta-data get "windows_amd64_image_id")
102+
if [ $# -eq 0 ]; then
103+
linux_amd64_source_image_id=$(buildkite-agent meta-data get "linux_amd64_image_id")
104+
linux_arm64_source_image_id=$(buildkite-agent meta-data get "linux_arm64_image_id")
105+
windows_amd64_source_image_id=$(buildkite-agent meta-data get "windows_amd64_image_id")
106106
fi
107107

108108
# If we're not on the main branch or a tag build skip the copy
109109
if [[ $BUILDKITE_BRANCH != main ]] && [[ $BUILDKITE_TAG != "$BUILDKITE_BRANCH" ]] && [[ ${COPY_TO_ALL_REGIONS:-"false"} != "true" ]]; then
110110
echo "--- Skipping AMI copy on non-main/tag branch " >&2
111111
mkdir -p "$(dirname "$mapping_file")"
112-
cat << EOF > "$mapping_file"
112+
cat <<EOF >"$mapping_file"
113113
Mappings:
114114
AWSRegion2AMI:
115115
${AWS_REGION} : { linuxamd64: $linux_amd64_source_image_id, linuxarm64: $linux_arm64_source_image_id, windows: $windows_amd64_source_image_id }
@@ -125,7 +125,7 @@ s3_mappings_cache=$(printf "s3://%s/mappings-%s-%s-%s-%s.yml" \
125125
"${BUILDKITE_BRANCH}")
126126

127127
# Check if there is a previously copy in the cache bucket
128-
if aws s3 cp "${s3_mappings_cache}" "$mapping_file" ; then
128+
if aws s3 cp "${s3_mappings_cache}" "$mapping_file"; then
129129
echo "--- Skipping AMI copy, was previously copied"
130130
exit 0
131131
fi
@@ -138,7 +138,7 @@ windows_amd64_source_image_name=$(get_image_name "$windows_amd64_source_image_id
138138
# Copy to all other regions
139139
# shellcheck disable=SC2048
140140
for region in ${ALL_REGIONS[*]}; do
141-
if [[ $region != "$source_region" ]] ; then
141+
if [[ $region != "$source_region" ]]; then
142142
echo "--- :linux: Copying Linux AMD64 $linux_amd64_source_image_id to $region" >&2
143143
IMAGES+=("$(copy_ami_to_region "$linux_amd64_source_image_id" "$source_region" "$region" "${linux_amd64_source_image_name}-${region}")")
144144

@@ -154,12 +154,12 @@ done
154154

155155
# Write yaml preamble
156156
mkdir -p "$(dirname "$mapping_file")"
157-
cat << EOF > "$mapping_file"
157+
cat <<EOF >"$mapping_file"
158158
Mappings:
159159
AWSRegion2AMI:
160160
EOF
161161

162-
echo "--- Waiting for AMIs to become available" >&2
162+
echo "--- Waiting for AMIs to become available" >&2
163163
# shellcheck disable=SC2048
164164
for region in ${ALL_REGIONS[*]}; do
165165
linux_amd64_image_id="${IMAGES[0]}"
@@ -169,29 +169,29 @@ for region in ${ALL_REGIONS[*]}; do
169169
wait_for_ami_to_be_available "$linux_amd64_image_id" "$region" >&2
170170

171171
# Make the linux AMI public if it's not the source image
172-
if [[ $linux_amd64_image_id != "$linux_amd64_source_image_id" ]] ; then
172+
if [[ $linux_amd64_image_id != "$linux_amd64_source_image_id" ]]; then
173173
echo ":linux: Making Linux AMD64 ${linux_amd64_image_id} public" >&2
174174
make_ami_public "$linux_amd64_image_id" "$region"
175175
fi
176176

177177
wait_for_ami_to_be_available "$linux_arm64_image_id" "$region" >&2
178178

179179
# Make the linux ARM AMI public if it's not the source image
180-
if [[ $linux_arm64_image_id != "$linux_arm64_source_image_id" ]] ; then
180+
if [[ $linux_arm64_image_id != "$linux_arm64_source_image_id" ]]; then
181181
echo ":linux: Making Linux ARM64 ${linux_arm64_image_id} public" >&2
182182
make_ami_public "$linux_arm64_image_id" "$region"
183183
fi
184184

185185
wait_for_ami_to_be_available "$windows_amd64_image_id" "$region" >&2
186186

187187
# Make the windows AMI public if it's not the source image
188-
if [[ $windows_amd64_image_id != "$windows_amd64_source_image_id" ]] ; then
188+
if [[ $windows_amd64_image_id != "$windows_amd64_source_image_id" ]]; then
189189
echo ":windows: Making Windows AMD64 ${windows_amd64_image_id} public" >&2
190190
make_ami_public "$windows_amd64_image_id" "$region"
191191
fi
192192

193193
# Write yaml to file
194-
echo " $region : { linuxamd64: $linux_amd64_image_id, linuxarm64: $linux_arm64_image_id, windows: $windows_amd64_image_id }" >> "$mapping_file"
194+
echo " $region : { linuxamd64: $linux_amd64_image_id, linuxarm64: $linux_arm64_image_id, windows: $windows_amd64_image_id }" >>"$mapping_file"
195195

196196
# Shift off the processed images
197197
IMAGES=("${IMAGES[@]:3}")

.buildkite/steps/delete-service-role-stack.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
set -euo pipefail
33

44
service_role_stack="$(buildkite-agent meta-data get service-role-stack-name)"
5-
if [ -n "${service_role_stack}" ]
6-
then
7-
echo "--- Deleting service-role stack $service_role_stack"
8-
aws cloudformation delete-stack --stack-name "$service_role_stack"
9-
aws cloudformation wait stack-delete-complete --stack-name "$service_role_stack"
5+
if [ -n "${service_role_stack}" ]; then
6+
echo "--- Deleting service-role stack $service_role_stack"
7+
aws cloudformation delete-stack --stack-name "$service_role_stack"
8+
aws cloudformation wait stack-delete-complete --stack-name "$service_role_stack"
109
fi

.buildkite/steps/delete.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ arch="${2:-amd64}"
66
stack_name="buildkite-aws-stack-test-${os}-${arch}-${BUILDKITE_BUILD_NUMBER}"
77

88
secrets_bucket=$(aws cloudformation describe-stacks \
9-
--stack-name "${stack_name}" \
10-
--query "Stacks[0].Outputs[?OutputKey=='ManagedSecretsBucket'].OutputValue" \
11-
--output text)
9+
--stack-name "${stack_name}" \
10+
--query "Stacks[0].Outputs[?OutputKey=='ManagedSecretsBucket'].OutputValue" \
11+
--output text)
1212

1313
secrets_logging_bucket=$(aws cloudformation describe-stacks \
14-
--stack-name "${stack_name}" \
15-
--query "Stacks[0].Outputs[?OutputKey=='ManagedSecretsLoggingBucket'].OutputValue" \
16-
--output text)
14+
--stack-name "${stack_name}" \
15+
--query "Stacks[0].Outputs[?OutputKey=='ManagedSecretsLoggingBucket'].OutputValue" \
16+
--output text)
1717

1818
echo "--- Deleting stack $stack_name"
1919
aws cloudformation delete-stack --stack-name "$stack_name"

.buildkite/steps/deploy-service-role-stack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ buildkite-agent meta-data set service-role-stack-name "${stack_name}"
77
aws cloudformation deploy --template-file templates/service-role.yml --stack-name "${stack_name}" --region us-east-1 --capabilities CAPABILITY_IAM
88

99
role_arn="$(aws cloudformation describe-stacks --stack-name "${stack_name}" --region us-east-1 --query "Stacks[0].Outputs[?OutputKey=='RoleArn'].OutputValue" --output text)"
10-
buildkite-agent meta-data set service-role-arn "${role_arn}"
10+
buildkite-agent meta-data set service-role-arn "${role_arn}"

.buildkite/steps/launch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ chmod +x ./parfait
1313

1414
vpc_id=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query "Vpcs[0].VpcId" --output text)
1515
subnets=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$vpc_id" --query "Subnets[*].[SubnetId,AvailabilityZone]" --output text)
16-
subnet_ids=$(awk '{print $1}' <<< "$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
17-
az_ids=$(awk '{print $2}' <<< "$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
16+
subnet_ids=$(awk '{print $1}' <<<"$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
17+
az_ids=$(awk '{print $2}' <<<"$subnets" | tr ' ' ',' | tr '\n' ',' | sed 's/,$//')
1818

1919
image_id=$(buildkite-agent meta-data get "${os}_${arch}_image_id")
2020
echo "Using AMI $image_id for $os/$arch"
@@ -35,7 +35,7 @@ if [[ "$arch" == "arm64" ]]; then
3535
enable_instance_storage="true"
3636
fi
3737

38-
cat << EOF > config.json
38+
cat <<EOF >config.json
3939
[
4040
{
4141
"ParameterKey": "BuildkiteAgentToken",

.buildkite/steps/lint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
grep -rl '^#!/.*sh' . | while read -r file ; do
4+
grep -rl '^#!/.*sh' . | while read -r file; do
55
[[ $file =~ \.git ]] && continue
66
[[ $file =~ init\.d ]] && continue
77
[[ $file =~ vendor ]] && continue
@@ -11,4 +11,4 @@ grep -rl '^#!/.*sh' . | while read -r file ; do
1111
echo "Processing $file"
1212
docker run --rm -v "$PWD:/mnt" koalaman/shellcheck "$file"
1313
echo -e "Ok.\\n"
14-
done
14+
done

.buildkite/steps/packer.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]] ; then
4+
if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]]; then
55
echo "Must set an s3 bucket in BUILDKITE_AWS_STACK_BUCKET for temporary files"
66
exit 1
77
fi
@@ -10,13 +10,13 @@ os="${1:-linux}"
1010
arch="${2:-amd64}"
1111
agent_binary="buildkite-agent-${os}-${arch}"
1212

13-
if [[ "$os" == "windows" ]] ; then
13+
if [[ "$os" == "windows" ]]; then
1414
agent_binary+=".exe"
1515
fi
1616

1717
mkdir -p "build/"
1818

19-
if [[ "$os" == "linux" ]] ; then
19+
if [[ "$os" == "linux" ]]; then
2020
buildkite-agent artifact download "build/fix-perms-linux-${arch}" ./build
2121
mv "build/fix-perms-linux-${arch}" packer/linux/conf/buildkite-agent/scripts/fix-buildkite-agent-builds-permissions
2222
chmod 755 packer/linux/conf/buildkite-agent/scripts/fix-buildkite-agent-builds-permissions
@@ -32,7 +32,7 @@ echo "Packer image hash for ${os}/${arch} is ${packer_hash}"
3232
packer_file="packer-${packer_hash}-${os}-${arch}.output"
3333

3434
# Only build packer image if one with the same hash doesn't exist, and we're not being forced
35-
if [[ -n "${PACKER_REBUILD:-}" ]] || ! aws s3 cp "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}" . ; then
35+
if [[ -n "${PACKER_REBUILD:-}" ]] || ! aws s3 cp "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}" .; then
3636
make "packer-${os}-${arch}.output"
3737
aws s3 cp "packer-${os}-${arch}.output" "s3://${BUILDKITE_AWS_STACK_BUCKET}/${packer_file}"
3838
mv "packer-${os}-${arch}.output" "${packer_file}"

.buildkite/steps/publish.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ s3_upload_templates() {
88
aws s3 cp --content-type 'text/yaml' --acl public-read build/aws-stack.yml "s3://${BUILDKITE_AWS_STACK_TEMPLATE_BUCKET}/${bucket_prefix}aws-stack.yml"
99
}
1010

11-
if [[ -z "${BUILDKITE_AWS_STACK_TEMPLATE_BUCKET}" ]] ; then
11+
if [[ -z "${BUILDKITE_AWS_STACK_TEMPLATE_BUCKET}" ]]; then
1212
echo "Must set an s3 bucket in BUILDKITE_AWS_STACK_TEMPLATE_BUCKET for publishing templates to"
1313
exit 1
1414
fi
@@ -48,7 +48,7 @@ publish_for_branch() {
4848
# Publish each build to a unique URL, to let people roll back to old versions
4949
s3_upload_templates "${branch}/${BUILDKITE_COMMIT}."
5050

51-
cat << EOF | buildkite-agent annotate --style "info"
51+
cat <<EOF | buildkite-agent annotate --style "info"
5252
Published template <a href="https://s3.amazonaws.com/${BUILDKITE_AWS_STACK_TEMPLATE_BUCKET}/${branch}/aws-stack.yml">${branch}/aws-stack.yml</a>
5353
EOF
5454
}

packer/linux/conf/bin/bk-check-disk-space.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -euo pipefail
33

44
DISK_MIN_AVAILABLE=${DISK_MIN_AVAILABLE:-5242880} # 5GB
5-
DISK_MIN_INODES=${DISK_MIN_INODES:-250000} # docker needs lots
5+
DISK_MIN_INODES=${DISK_MIN_INODES:-250000} # docker needs lots
66

77
DOCKER_DIR="$(jq -r '."data-root" // "/var/lib/docker"' /etc/docker/daemon.json)"
88

0 commit comments

Comments
 (0)