Skip to content

Commit 6f70775

Browse files
chore: update scripts to satisfy validation
Fix ShellCheck warnings across all shell scripts: - SC2155: Separate variable declaration and assignment to avoid masking return values - SC2068: Quote array expansions to prevent word splitting - SC2164: Add error handling to cd commands with || exit - SC2088: Replace tilde with $HOME for proper expansion in quotes - SC2206: Use robust array assignment with IFS read instead of word splitting - SC1090: Add disable directive for non-constant source paths All changes preserve or improve functionality while following shell scripting best practices.
1 parent b77df50 commit 6f70775

File tree

19 files changed

+56
-25
lines changed

19 files changed

+56
-25
lines changed

.github/scripts/check_registry_site_health.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ create_incident() {
8282
# Function to check for existing unresolved incidents
8383
check_existing_incident() {
8484
# Fetch the latest incidents with status not equal to "RESOLVED"
85-
local unresolved_incidents=$(curl -s -X GET "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
85+
local unresolved_incidents
86+
unresolved_incidents=$(curl -s -X GET "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
8687
-H "Authorization: Bearer $INSTATUS_API_KEY" \
8788
-H "Content-Type: application/json" | jq -r '.incidents[] | select(.status != "RESOLVED") | .id')
8889

registry/anomaly/modules/tmux/scripts/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ main() {
144144
printf "$${BOLD}✅ tmux setup complete! \n\n"
145145

146146
printf "$${BOLD} Attempting to restore sessions\n"
147-
tmux new-session -d \; source-file ~/.tmux.conf \; run-shell '~/.tmux/plugins/tmux-resurrect/scripts/restore.sh'
147+
tmux new-session -d \; source-file ~/.tmux.conf \; run-shell "$HOME/.tmux/plugins/tmux-resurrect/scripts/restore.sh"
148148
printf "$${BOLD} Sessions restored: -> %s\n" "$(tmux ls)"
149149

150150
}

registry/coder-labs/modules/archive/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ EXTRACT_ON_START="${TF_EXTRACT_ON_START}"
66
EXTRACT_WAIT_TIMEOUT="${TF_EXTRACT_WAIT_TIMEOUT}"
77

88
# Set script defaults from Terraform.
9-
DEFAULT_PATHS=(${TF_PATHS})
10-
DEFAULT_EXCLUDE_PATTERNS=(${TF_EXCLUDE_PATTERNS})
9+
IFS=' ' read -r -a DEFAULT_PATHS <<< "${TF_PATHS}"
10+
IFS=' ' read -r -a DEFAULT_EXCLUDE_PATTERNS <<< "${TF_EXCLUDE_PATTERNS}"
1111
DEFAULT_COMPRESSION="${TF_COMPRESSION}"
1212
DEFAULT_ARCHIVE_PATH="${TF_ARCHIVE_PATH}"
1313
DEFAULT_DIRECTORY="${TF_DIRECTORY}"
@@ -62,6 +62,7 @@ echo "Installed extract script to: $EXTRACT_WRAPPER_PATH"
6262

6363
# 3) Optionally wait for and extract an archive on start.
6464
if [[ $EXTRACT_ON_START = true ]]; then
65+
# shellcheck disable=SC1090
6566
. "$LIB_PATH"
6667

6768
archive_wait_and_extract "$EXTRACT_WAIT_TIMEOUT" quiet || {

registry/coder/modules/code-server/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function extension_installed() {
8888
if [ "${USE_CACHED_EXTENSIONS}" != true ]; then
8989
return 1
9090
fi
91+
# shellcheck disable=SC2066
9192
for _extension in "$${EXTENSIONS_ARRAY[@]}"; do
9293
if [ "$_extension" == "$1" ]; then
9394
echo "Extension $1 was already installed."
@@ -99,6 +100,7 @@ function extension_installed() {
99100

100101
# Install each extension...
101102
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
103+
# shellcheck disable=SC2066
102104
for extension in "$${EXTENSIONLIST[@]}"; do
103105
if [ -z "$extension" ]; then
104106
continue

registry/coder/modules/devcontainers-cli/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# might contain a `package.json` with `packageManager` set to something
55
# other than the detected package manager. When this happens, it can
66
# cause the installation to fail.
7-
cd "$CODER_SCRIPT_DATA_DIR"
7+
cd "$CODER_SCRIPT_DATA_DIR" || exit
88

99
# If @devcontainers/cli is already installed, we can skip
1010
if command -v devcontainer > /dev/null 2>&1; then

registry/coder/modules/dotfiles/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -euo pipefail
55
DOTFILES_URI="${DOTFILES_URI}"
66
DOTFILES_USER="${DOTFILES_USER}"
77

8+
# shellcheck disable=SC2157
89
if [ -n "$${DOTFILES_URI// }" ]; then
910
if [ -z "$DOTFILES_USER" ]; then
1011
DOTFILES_USER="$USER"

registry/coder/modules/git-clone/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if [ -n "$POST_CLONE_SCRIPT" ]; then
6060
echo "Running post-clone script..."
6161
echo "$POST_CLONE_SCRIPT" | base64 -d > /tmp/post_clone.sh
6262
chmod +x /tmp/post_clone.sh
63-
cd "$CLONE_PATH"
63+
cd "$CLONE_PATH" || exit
6464
/tmp/post_clone.sh
6565
rm /tmp/post_clone.sh
6666
fi

registry/coder/modules/slackme/slackme.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ fi
7373

7474
START=$(date +%s%N)
7575
# Run all arguments as a command
76-
$@
76+
"$@"
7777
END=$(date +%s%N)
7878
DURATION_MS=$${DURATION_MS:-$(((END - START) / 1000000))}
7979
PRETTY_DURATION=$(pretty_duration $DURATION_MS)
8080

8181
set -e
82-
COMMAND=$(echo $@)
82+
COMMAND=$(echo "$@")
8383
SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$COMMAND|$COMMAND|g")
8484
SLACK_MESSAGE=$(echo "$SLACK_MESSAGE" | sed "s|\\$DURATION|$PRETTY_DURATION|g")
8585

registry/coder/modules/vault-github/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ install() {
4646
if [ "$${INSTALL_VERSION}" = "latest" ]; then
4747
LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -v 'rc' | grep -oE 'vault/[0-9]+\.[0-9]+\.[0-9]+' | sed 's/vault\///' | sort -V | tail -n 1)
4848
printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}"
49+
# shellcheck disable=SC2157
4950
if [ -z "$${LATEST_VERSION}" ]; then
5051
printf "Failed to determine the latest Vault version.\n"
5152
return 1
@@ -63,8 +64,10 @@ install() {
6364
fi
6465
fi
6566

67+
# shellcheck disable=SC2170
6668
if [ $${installation_needed} -eq 1 ]; then
6769
# Download and install Vault
70+
# shellcheck disable=SC2157
6871
if [ -z "$${CURRENT_VERSION}" ]; then
6972
printf "Installing Vault CLI ...\n\n"
7073
else

registry/coder/modules/vault-jwt/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ install() {
4747
if [ "$${VAULT_CLI_VERSION}" = "latest" ]; then
4848
LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -v 'rc' | grep -oE 'vault/[0-9]+\.[0-9]+\.[0-9]+' | sed 's/vault\///' | sort -V | tail -n 1)
4949
printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}"
50+
# shellcheck disable=SC2157
5051
if [ -z "$${LATEST_VERSION}" ]; then
5152
printf "Failed to determine the latest Vault version.\n"
5253
return 1
@@ -64,8 +65,10 @@ install() {
6465
fi
6566
fi
6667

68+
# shellcheck disable=SC2170
6769
if [ $${installation_needed} -eq 1 ]; then
6870
# Download and install Vault
71+
# shellcheck disable=SC2157
6972
if [ -z "$${CURRENT_VERSION}" ]; then
7073
printf "Installing Vault CLI ...\n\n"
7174
else

0 commit comments

Comments
 (0)