Skip to content

Commit 611715e

Browse files
committed
Add ShellCheck CI and fix reported issues
Add a GitHub Actions workflow using differential-shellcheck to check shell scripts on pull requests. Fix the issues it found: - build.sh: replace indirect $? checks with direct `if !` form (SC2181) - src/bash_functions.sh: separate export from assignment to avoid masking return values (SC2155)
1 parent 850381a commit 611715e

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: ShellCheck
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, ready_for_review]
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
shellcheck:
11+
if: github.event.pull_request.draft == false
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
16+
17+
- name: Run ShellCheck
18+
run: find . -name "*.sh" -exec shellcheck {} +

build.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ WEB_FORK="pi-hole"
2727
PADD_FORK="pi-hole"
2828

2929
# Check if buildx is installed
30-
docker buildx version >/dev/null 2>&1
31-
if [ $? -ne 0 ]; then
30+
if ! docker buildx version >/dev/null 2>&1; then
3231
echo "Error: Docker buildx is required to build this image. For installation instructions, see:"
3332
echo " https://github.com/docker/buildx#installing"
3433
exit 1
@@ -151,10 +150,7 @@ DOCKER_BUILD_CMD+=("${BUILD_ARGS[@]}")
151150

152151
# Execute the docker build command
153152
echo "Executing command: ${DOCKER_BUILD_CMD[*]}"
154-
"${DOCKER_BUILD_CMD[@]}"
155-
156-
# Check exit code of previous command
157-
if [ $? -ne 0 ]; then
153+
if ! "${DOCKER_BUILD_CMD[@]}"; then
158154
echo ""
159155
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
160156
echo "!! ERROR: Docker build failed, please review logs above !!"

src/bash_functions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ migrate_v5_configs() {
191191
setup_web_password() {
192192
if [ -z "${FTLCONF_webserver_api_password+x}" ] && [ -n "${WEBPASSWORD_FILE}" ] && [ -r "/run/secrets/${WEBPASSWORD_FILE}" ]; then
193193
echo " [i] Setting FTLCONF_webserver_api_password from file"
194-
export FTLCONF_webserver_api_password=$(<"/run/secrets/${WEBPASSWORD_FILE}")
194+
FTLCONF_webserver_api_password=$(<"/run/secrets/${WEBPASSWORD_FILE}")
195+
export FTLCONF_webserver_api_password
195196
fi
196197

197198
# If FTLCONF_webserver_api_password is not set

0 commit comments

Comments
 (0)