Skip to content

Commit fae1826

Browse files
committed
Fix shellcheck lints of our various bash scripts
The following lints have been fixed: SC2046,SC2086,SC2068,SC2148,SC2007,SC2004,SC2006, SC2164,SC2145,SC1091,SC2034,SC2155.
1 parent 09cfec2 commit fae1826

29 files changed

+116
-94
lines changed

android/docs/diagrams/update_graphs.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
44

5-
plantuml $SCRIPT_DIR/*.puml
5+
plantuml "$SCRIPT_DIR"/*.puml

android/fdroid-build/env.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#!/usr/bin/env bash
12
# Sourcing this file prepares the environment for building inside the F-Droid build server
23

34
# Ensure Cargo tools are accessible
5+
# shellcheck source=/dev/null
46
source "$HOME/.cargo/env"
57

68
# Ensure Go compiler is accessible

android/fdroid-build/init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ set -eux
55
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

77
REPO_DIR="$SCRIPT_DIR/../../"
8-
TOOLCHAINS_DIR="$HOME/android-ndk-toolchains"
98

109
# Install Rust
1110
curl -sf -L https://sh.rustup.rs > /tmp/rustup.sh
1211
chmod +x /tmp/rustup.sh
1312
/tmp/rustup.sh -y
13+
# shellcheck source=/dev/null
1414
source "$HOME/.cargo/env"
1515
rustup set profile minimal
1616
rustup target add \

android/scripts/generate-pngs.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ function convert_image() {
4646

4747
local source_image="$1"
4848
local dpi_config="$2"
49+
local destination_image
4950

5051
if (( $# >= 3 )); then
51-
local destination_image="$3"
52+
destination_image="$3"
5253
else
53-
local destination_image="$(basename "$source_image" .svg | sed -e 's/-/_/g')"
54+
destination_image="$(basename "$source_image" .svg | sed -e 's/-/_/g')"
5455
fi
5556

5657
if (( $# >= 4 )); then
@@ -59,8 +60,10 @@ function convert_image() {
5960
local destination_dir="drawable"
6061
fi
6162

62-
local dpi="$(echo "$dpi_config" | cut -f1 -d'-')"
63-
local size="$(echo "$dpi_config" | cut -f2 -d'-')"
63+
local dpi
64+
dpi="$(echo "$dpi_config" | cut -f1 -d'-')"
65+
local size
66+
size="$(echo "$dpi_config" | cut -f2 -d'-')"
6467

6568
local dpi_dir="../lib/resource/src/main/res/${destination_dir}-${dpi}"
6669

android/scripts/run-instrumented-tests-locally.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44

55
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

7-
cd $SCRIPT_DIR/..
7+
cd "$SCRIPT_DIR"/..
88
./gradlew assembleOssProdAndroidTest
99
./gradlew app:assembleOssProdDebug
10-
$SCRIPT_DIR/run-instrumented-tests.sh app
10+
"$SCRIPT_DIR"/run-instrumented-tests.sh app

android/scripts/run-instrumented-tests.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ INVALID_TEST_ACCOUNT_TOKEN="${INVALID_TEST_ACCOUNT_TOKEN:-}"
2323
while [[ "$#" -gt 0 ]]; do
2424
case $1 in
2525
--test-type)
26-
if [[ ! -z ${2-} && "$2" =~ ^(app|mockapi|e2e)$ ]]; then
26+
if [[ -n "${2-}" && "$2" =~ ^(app|mockapi|e2e)$ ]]; then
2727
TEST_TYPE="$2"
2828
else
2929
echo "Error: Bad or missing test type. Must be one of: app, mockapi, e2e"
@@ -32,7 +32,7 @@ while [[ "$#" -gt 0 ]]; do
3232
shift 2
3333
;;
3434
--infra-flavor)
35-
if [[ ! -z ${2-} && "$2" =~ ^(prod|stagemole)$ ]]; then
35+
if [[ -n "${2-}" && "$2" =~ ^(prod|stagemole)$ ]]; then
3636
INFRA_FLAVOR="$2"
3737
else
3838
echo "Error: Bad or missing infra flavor. Must be one of: prod, stagemole"
@@ -41,7 +41,7 @@ while [[ "$#" -gt 0 ]]; do
4141
shift 2
4242
;;
4343
--billing-flavor)
44-
if [[ ! -z ${2-} && "$2" =~ ^(oss|play)$ ]]; then
44+
if [[ -n "${2-}" && "$2" =~ ^(oss|play)$ ]]; then
4545
BILLING_FLAVOR="$2"
4646
else
4747
echo "Error: Bad or missing billing flavor. Must be one of: oss, play"

build-apk.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BUILD_BUNDLE="no"
2121
CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"target"}
2222
SKIP_STRIPPING=${SKIP_STRIPPING:-"no"}
2323

24-
while [ ! -z "${1:-""}" ]; do
24+
while [ -n "${1:-""}" ]; do
2525
if [[ "${1:-""}" == "--dev-build" ]]; then
2626
BUILD_TYPE="debug"
2727
GRADLE_BUILD_TYPE="debug"
@@ -103,7 +103,7 @@ for ARCHITECTURE in ${ARCHITECTURES:-aarch64 armv7 x86_64 i686}; do
103103
esac
104104

105105
echo "Building mullvad-daemon for $TARGET"
106-
cargo build $CARGO_ARGS --target "$TARGET" --package mullvad-jni
106+
cargo build "$CARGO_ARGS" --target "$TARGET" --package mullvad-jni
107107

108108
STRIP_TOOL="${NDK_TOOLCHAIN_DIR}/llvm-strip"
109109
TARGET_LIB_PATH="$SCRIPT_DIR/android/app/build/extraJni/$ABI/libmullvad_jni.so"
@@ -117,7 +117,7 @@ for ARCHITECTURE in ${ARCHITECTURES:-aarch64 armv7 x86_64 i686}; do
117117
done
118118

119119
echo "Updating relays.json..."
120-
cargo run --bin relay_list $CARGO_ARGS > build/relays.json
120+
cargo run --bin relay_list "$CARGO_ARGS" > build/relays.json
121121

122122
cd "$SCRIPT_DIR/android"
123123
$GRADLE_CMD --console plain "${GRADLE_TASKS[@]}"

building/build-and-publish-container-image.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trap 'delete_tmp_signature_dir' EXIT
5353

5454
log_header "Pushing $full_container_name:latest"
5555
podman push "$full_container_name:latest" \
56-
--sign-by $CONTAINER_SIGNING_KEY_FINGERPRINT \
56+
--sign-by "$CONTAINER_SIGNING_KEY_FINGERPRINT" \
5757
--digestfile "$tmp_signature_dir/digest_latest"
5858

5959
digest=$(cat "$tmp_signature_dir/digest_latest")
@@ -68,7 +68,7 @@ cp "$signature_dir/signature-1" "$tmp_signature_dir/signature-2"
6868

6969
log_header "Pushing $full_container_name:$tag"
7070
podman push "$full_container_name:$tag" \
71-
--sign-by $CONTAINER_SIGNING_KEY_FINGERPRINT \
71+
--sign-by "$CONTAINER_SIGNING_KEY_FINGERPRINT" \
7272
--digestfile "$tmp_signature_dir/digest_$tag"
7373

7474
if ! cmp -s "$tmp_signature_dir/digest_latest" "$tmp_signature_dir/digest_$tag"; then

ci/buildserver-build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ LAST_BUILT_DIR="$SCRIPT_DIR/last-built"
2020

2121
BRANCHES_TO_BUILD=("origin/main")
2222

23+
# shellcheck source=ci/buildserver-config.sh
2324
source "$SCRIPT_DIR/buildserver-config.sh"
2425

2526
# Ask for the passphrase to the signing keys

ci/buildserver-upload.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CODE_SIGNING_KEY_FINGERPRINT="A1198702FC3E0A09A9AE5B75D5A1D4F266DE8DDF"
77

88
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
99

10+
# shellcheck source=ci/buildserver-config.sh
1011
source "$SCRIPT_DIR/buildserver-config.sh"
1112

1213
cd "$UPLOAD_DIR"

ci/ios/build-app.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cd ~/build/ios
1717
rm -r Build
1818

1919
# Instantiate Xcconfig templates.
20-
for file in ./Configurations/*.template ; do cp $file ${file//.template/} ; done
20+
for file in ./Configurations/*.template ; do cp "$file" "${file//.template/}" ; done
2121

2222
IOS_PROVISIONING_PROFILES_DIR=~/provisioning-profiles \
2323
PATH=/usr/local/go/bin:$PATH \

ci/ios/buildserver-build-ios.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export GIT_DIR="$GIT_WORK_TREE/.git"
1414
function run_git {
1515
# `git submodule` needs more info than just $GIT_DIR and $GIT_WORK_TREE.
1616
# But -C makes it work.
17-
git -C $GIT_WORK_TREE $@
17+
git -C "$GIT_WORK_TREE" "$@"
1818
}
1919

2020

@@ -43,7 +43,7 @@ function build_ref() {
4343
fi
4444

4545
run_git reset --hard
46-
run_git checkout $tag
46+
run_git checkout "$tag"
4747
run_git submodule update
4848
run_git clean -df
4949

@@ -92,7 +92,8 @@ function run_build_loop() {
9292
run_git tag | xargs git tag -d > /dev/null
9393

9494
run_git fetch --prune --tags 2> /dev/null || continue
95-
local tags=( $(run_git tag | grep "$TAG_PATTERN_TO_BUILD") )
95+
local tags
96+
tags=( $(run_git tag | grep "$TAG_PATTERN_TO_BUILD") )
9697

9798
for tag in "${tags[@]}"; do
9899
build_ref "refs/tags/$tag"

ci/ios/run-build-and-upload.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
set -eu -o pipefail
1111

1212
# Add SSH key for iOS build VMs to be able to SSH into them without user interaction
13-
eval $(ssh-agent)
13+
eval "$(ssh-agent)"
1414
ssh-add ~/.ssh/ios-vm-key
1515

1616
# This single path really screws with XCode and wireguard-go's makefiles, which

ci/ios/run-in-vm.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env bash
12
# This takes the following positional arguments 
23
# 1. tart VM name
34
# 2. Script to execute in the VM
@@ -23,7 +24,7 @@ sleep 10
2324

2425
# apparently, there's a difference between piping into zsh like this and doing
2526
# a <(echo $SCRIPT).
26-
cat "$SCRIPT" | ssh admin@$(tart ip "$VM_NAME") bash /dev/stdin
27+
cat "$SCRIPT" | ssh admin@"$(tart ip "$VM_NAME")" bash /dev/stdin
2728
script_status=$?
2829

2930
kill $vm_pid

ci/ios/upload-app.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env bash
2+
set -eu
23
# Upload script to run in `ios-upload` VM to upload a newly built IPA to TestFlight
34

45
VM_UPLOAD_IPA_PATH="/Volumes/My Shared Files/build-output/MullvadVPN.ipa"
56
API_KEY_PATH="$HOME/ci/app-store-connect-key.json"
67
cd ci/
8+
# shellcheck source=/dev/null
79
source ~/.bash_profile
810
bundle exec fastlane pilot upload --api-key-path "${API_KEY_PATH}" --ipa "${VM_UPLOAD_IPA_PATH}"

ci/prepare-apt-repository.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set -eu
99

1010
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1111

12+
# shellcheck source=ci/buildserver-config.sh
1213
source "$SCRIPT_DIR/buildserver-config.sh"
1314

1415
artifact_dir=$1

ci/prepare-rpm-repository.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set -eu
99

1010
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1111

12+
# shellcheck source=ci/buildserver-config.sh
1213
source "$SCRIPT_DIR/buildserver-config.sh"
1314

1415
artifact_dir=$1

ci/publish-linux-repositories.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set -eu
99

1010
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1111

12+
# shellcheck source=ci/buildserver-config.sh
1213
source "$SCRIPT_DIR/buildserver-config.sh"
1314

1415
while [ "$#" -gt 0 ]; do

ci/verify-locked-down-signatures.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
set -eu
33
shopt -s nullglob
44

5-
readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
readonly SCRIPT_DIR
67
readonly REPO_DIR="$SCRIPT_DIR/.."
78

89
# In the CI environment we would like to import trusted public keys from a file,
@@ -76,7 +77,7 @@ for locked_path in $locked_down_paths; do
7677

7778
# Check if important file has been removed.
7879
if [[ ! -e "$REPO_DIR/$locked_path" ]]; then
79-
echo "$locked_path was removed. If this was intentional, remove it from `verify-locked-down-signatures.yml`."
80+
echo "$locked_path was removed. If this was intentional, remove it from 'verify-locked-down-signatures.yml'"
8081
important_file_was_removed=1
8182
fi
8283
done

gui/scripts/build-logo-icons.sh

+14-14
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ TMP_DIR=$(mktemp -d)
4646
TMP_ICO_DIR="$TMP_DIR/ico"
4747
TMP_ICONSET_DIR="$TMP_DIR/icon.iconset"
4848

49-
mkdir $TMP_ICONSET_DIR
50-
mkdir $TMP_ICO_DIR
49+
mkdir "$TMP_ICONSET_DIR"
50+
mkdir "$TMP_ICO_DIR"
5151

5252
COMPRESSION_OPTIONS="-define png:compression-filter=5 -define png:compression-level=9 \
5353
-define png:compression-strategy=1 -define png:exclude-chunk=all -strip"
@@ -62,36 +62,36 @@ rm "$TMP_ICONSET_DIR"/*
6262

6363
# Linux .icns icon
6464
for size in 16 32 128 256 512; do
65-
double_size=$[$size * 2]
66-
rsvg-convert -o $TMP_ICONSET_DIR/icon-$size.png -w $size -h $size $SVG_SOURCE_PATH
67-
rsvg-convert -o $TMP_ICONSET_DIR/icon-$size@2x.png -w $double_size -h $double_size \
65+
double_size="$((size * 2))"
66+
rsvg-convert -o "$TMP_ICONSET_DIR"/icon-$size.png -w $size -h $size $SVG_SOURCE_PATH
67+
rsvg-convert -o "$TMP_ICONSET_DIR"/icon-$size@2x.png -w "$double_size" -h "$double_size" \
6868
$SVG_SOURCE_PATH
6969
done
70-
iconutil --convert icns --output $DIST_ASSETS_DIR/icon.icns $TMP_ICONSET_DIR
71-
rm -rf $TMP_ICONSET_DIR
70+
iconutil --convert icns --output $DIST_ASSETS_DIR/icon.icns "$TMP_ICONSET_DIR"
71+
rm -rf "$TMP_ICONSET_DIR"
7272

7373
# Windows .ico icon
7474
for size in 16 20 24 30 32 36 40 48 60 64 72 80 96 256 512; do
75-
rsvg-convert -o $TMP_ICO_DIR/$size.png -w $size -h $size $SVG_SOURCE_PATH
75+
rsvg-convert -o "$TMP_ICO_DIR"/$size.png -w $size -h $size $SVG_SOURCE_PATH
7676
done
77-
convert $TMP_ICO_DIR/* $COMPRESSION_OPTIONS $DIST_ASSETS_DIR/icon.ico
78-
rm -rf $TMP_ICO_DIR
77+
convert "$TMP_ICO_DIR"/* "$COMPRESSION_OPTIONS" $DIST_ASSETS_DIR/icon.ico
78+
rm -rf "$TMP_ICO_DIR"
7979

8080
# Windows installer sidebar
8181
# "bmp3" specifies the Windows 3.x format which is required for the image to be displayed
8282
sidebar_path="$TMP_DIR/sidebar.png"
8383
sidebar_logo_size=234
84-
rsvg-convert -o $sidebar_path -w $sidebar_logo_size -h $sidebar_logo_size $SVG_SOURCE_PATH
85-
convert -background "#294D73" $sidebar_path \
84+
rsvg-convert -o "$sidebar_path" -w $sidebar_logo_size -h $sidebar_logo_size $SVG_SOURCE_PATH
85+
convert -background "#294D73" "$sidebar_path" \
8686
-gravity center -extent ${sidebar_logo_size}x314 \
8787
-gravity west -crop 164x314+10+0 bmp3:$DIST_ASSETS_DIR/windows/installersidebar.bmp
88-
rm $sidebar_path
88+
rm "$sidebar_path"
8989

9090
# GUI notification icon
9191
rsvg-convert -o ../assets/images/icon-notification.png -w 128 -h 128 $SVG_SOURCE_PATH
9292

9393
# GUI in app icon
9494
cp "$SVG_SOURCE_PATH" ../assets/images/logo-icon.svg
9595

96-
rmdir $TMP_DIR
96+
rmdir "$TMP_DIR"
9797

gui/scripts/build-proto.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ mkdir -p $TYPES_DESTINATION_DIR
2424

2525
if [[ "$PLATFORM" == "Linux" && ("${ARCH,,}" == "arm64" || "${ARCH,,}" == "aarch64") ]]; then
2626
if [[ -n "${MANAGEMENT_INTERFACE_PROTO_BUILD_DIR}" ]]; then
27-
cp $MANAGEMENT_INTERFACE_PROTO_BUILD_DIR/*.js $DESTINATION_DIR
28-
cp $MANAGEMENT_INTERFACE_PROTO_BUILD_DIR/*.ts $TYPES_DESTINATION_DIR
27+
cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.js $DESTINATION_DIR
28+
cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.ts $TYPES_DESTINATION_DIR
2929
else
3030
>&2 echo "Building management interface proto files on aarch64 is not supported"
3131
>&2 echo "(see https://github.com/grpc/grpc-node/issues/1497)."
@@ -41,7 +41,7 @@ else
4141
$PROTO_DIR/$PROTO_FILENAME
4242

4343
"$NODE_MODULES_DIR/grpc_tools_node_protoc" \
44-
--plugin=protoc-gen-ts=$TS_PROTOC_PLUGIN \
44+
--plugin=protoc-gen-ts="$TS_PROTOC_PLUGIN" \
4545
--ts_out=grpc_js:$TYPES_DESTINATION_DIR \
4646
--proto_path=$PROTO_DIR \
4747
$PROTO_DIR/$PROTO_FILENAME

gui/scripts/crowdin.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
BASE_URL=https://api.crowdin.com/api/project/mullvad-app
55
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6-
ROOT_DIR=$( dirname $SCRIPT_DIR )
6+
ROOT_DIR=$( dirname "$SCRIPT_DIR" )
77
LOCALE_DIR="$ROOT_DIR/locales"
88

99
if [ $# -ne 1 ]; then
@@ -32,9 +32,9 @@ function download_translations {
3232
wget \
3333
--content-disposition \
3434
$BASE_URL/download/all.zip?key="$CROWDIN_API_KEY"
35-
unzip -o all.zip -d $LOCALE_DIR
36-
find $LOCALE_DIR -type d -exec chmod 755 {} \;
37-
find $LOCALE_DIR -type f -exec chmod 644 {} \;
35+
unzip -o all.zip -d "$LOCALE_DIR"
36+
find "$LOCALE_DIR" -type d -exec chmod 755 {} \;
37+
find "$LOCALE_DIR" -type f -exec chmod 644 {} \;
3838
rm all.zip
3939
}
4040

ios/build-rust-library.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ for arch in $ARCHS; do
4343

4444
# Intel iOS simulator
4545
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
46-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target x86_64-apple-ios
47-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib --target x86_64-apple-ios
46+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib "$RELFLAG" --target x86_64-apple-ios
47+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target x86_64-apple-ios
4848
;;
4949

5050
arm64)
5151
if [ $IS_SIMULATOR -eq 0 ]; then
5252
# Hardware iOS targets
53-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios
54-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib --target aarch64-apple-ios
53+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib "$RELFLAG" --target aarch64-apple-ios
54+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios
5555
else
56-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios-sim
57-
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib --target aarch64-apple-ios-sim
56+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib "$RELFLAG" --target aarch64-apple-ios-sim
57+
"$HOME"/.cargo/bin/cargo build -p "$FFI_TARGET" --lib --target aarch64-apple-ios-sim
5858
fi
5959
esac
6060
done

0 commit comments

Comments
 (0)