Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint bash scripts with custom shebangs #3824

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ jobs:

- name: Run linter
uses: ludeeus/[email protected]
with:
# Names of scripts with custom shebangs that the action would not
# discover on its own:
additional_files: >-
check_certificate_renewal
cpcd-config-up
discovery
finish
lock-tables-for-backup
matter-server-discovery
reboot
run
shutdown
universal-silabs-flasher-up
unlock-tables-for-backup
vlc-discovery
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter much, but for clarity, should we maybe use the full path for the add-on specific scripts, e.g. vlc/rootfs/etc/s6-overlay/scripts/vlc-discovery? 🤔

I'd still use just file name for the generic s6-init scripts (like run and friends).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have loved to use full paths, but the additional_files input to the action only supports file names and not paths: https://github.com/ludeeus/action-shellcheck/blob/00b27aa7cb85167568cb48a3838b75f4265f2bca/action.yaml#L141-L143

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Take down the S6 supervision tree when service fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -14,7 +15,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
1 change: 1 addition & 0 deletions cec_scan/rootfs/etc/services.d/cec-scan/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start CEC scan service
# ==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Take down the S6 supervision tree when service fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
Expand All @@ -14,7 +15,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start Configurator service
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/cont-init.d/firmware.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Manage deCONZ firmware
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/cont-init.d/nginx.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Configure NGINX for use with deCONZ
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/cont-init.d/novnc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Setup noVNC
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/deconz/discovery
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Send deCONZ discovery information to Home Assistant
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/deconz/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start deCONZ service
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/nginx/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start NGINX service
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/otau-ikea/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Download available firmware update for IKEA
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/otau-ledvance/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Download available firmware update for OSRAM Ledvance
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions deconz/rootfs/etc/services.d/websockify/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start ozw-admin
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions dhcp_server/data/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved

CONFIG="/etc/dhcpd.conf"
Expand Down
1 change: 1 addition & 0 deletions dnsmasq/rootfs/etc/cont-init.d/config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# DNSMASQ config
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions dnsmasq/rootfs/etc/services.d/dnsmasq/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
CONFIG="/etc/dnsmasq.conf"

# Run dnsmasq
Expand Down
3 changes: 2 additions & 1 deletion duckdns/rootfs/etc/s6-overlay/s6-rc.d/duckdns/finish
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Home Assistant Community Add-on: chrony
# Take down the S6 supervision tree when chrony fails
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
Expand All @@ -15,7 +16,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
1 change: 1 addition & 0 deletions duckdns/rootfs/etc/s6-overlay/s6-rc.d/duckdns/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash

CERT_DIR=/data/letsencrypt
WORK_DIR=/data/workdir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start Google Assistant service
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions letsencrypt/rootfs/etc/cont-init.d/file-structure.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Init folder & structures
# ==============================================================================
Expand Down
2 changes: 2 additions & 0 deletions letsencrypt/rootfs/etc/services.d/lets-encrypt/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start sshd service if enabled
# ==============================================================================
Expand Down Expand Up @@ -294,6 +295,7 @@ else
bashio::log.info "Detecting existing certificate type for ${DOMAIN_ARR[1]}"
readarray -t CBCERTS < <(certbot certificates --non-interactive --cert-name "${DOMAIN_ARR[1]}" --config-dir "$CERT_DIR" --work-dir "$WORK_DIR")
for output in "${CBCERTS[@]}"; do
# shellcheck disable=SC2076
if [[ $output =~ "No certificates found." ]]; then
bashio::log.info "No certificate found - using 'ecdsa' key type."
KEY_ARGUMENTS+=("--key-type" "ecdsa")
Expand Down
3 changes: 2 additions & 1 deletion mariadb/rootfs/etc/s6-overlay/s6-rc.d/mariadb-core/finish
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ==============================================================================
# Take down the S6 supervision tree when daemon fails
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
Expand All @@ -14,7 +15,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

declare MARIADB_LOCK_CORE_PID
MARIADB_LOCK_CORE_PID=$(s6-svstat -o pid "/run/service/mariadb-lock-core")
# shellcheck disable=SC2086
if bashio::var.equals ${MARIADB_LOCK_CORE_PID} -1; then
bashio::log.error "Invalid mariadb-lock-core process id ${MARIADB_LOCK_CORE_PID}"
bashio::exit.nok
fi

# File descriptor &4 is used as stdin for mysql, because &0 is closed after the mariadb-lock-core service is started
# shellcheck disable=SC2086
echo "UNLOCK TABLES;" > /proc/${MARIADB_LOCK_CORE_PID}/fd/4

bashio::log.info "MariaDB tables unlocked"
2 changes: 2 additions & 0 deletions mariadb/rootfs/etc/s6-overlay/s6-rc.d/mariadb-lock-post/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

declare MARIADB_LOCK_CORE_PID
MARIADB_LOCK_CORE_PID=$(s6-svstat -o pid "/run/service/mariadb-lock-core")
# shellcheck disable=SC2086
if bashio::var.equals ${MARIADB_LOCK_CORE_PID} -1; then
bashio::log.error "Invalid mariadb-lock-core process id ${MARIADB_LOCK_CORE_PID}"
bashio::exit.nok
fi

# File descriptor &4 is used as stdin for mysql, because &0 is closed after the mariadb-lock-core service is started
# shellcheck disable=SC2086
echo "FLUSH TABLES WITH READ LOCK;" > /proc/${MARIADB_LOCK_CORE_PID}/fd/4
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved

bashio::log.info "MariaDB tables locked"
2 changes: 2 additions & 0 deletions mariadb/rootfs/etc/s6-overlay/s6-rc.d/mariadb-post/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function execute_without_error_messages() {
local current_log_level="${__BASHIO_LOG_LEVELS[${__BASHIO_LOG_LEVEL}]}"
bashio::log.level fatal
local exit_code=0
# shellcheck disable=SC2068
$@ || exit_code=$?
# shellcheck disable=SC2086
bashio::log.level ${current_log_level}
return ${exit_code}
}
Expand Down
4 changes: 2 additions & 2 deletions mariadb/rootfs/etc/s6-overlay/s6-rc.d/mariadb-pre/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ if ! bashio::fs.directory_exists "${MARIADB_DATA}"; then
fi

# Save variables
printf "${MARIADB_DATA}" > /var/run/s6/container_environment/MARIADB_DATA
printf "${NEW_INSTALL}" > /var/run/s6/container_environment/NEW_INSTALL
cat <<<"${MARIADB_DATA}" > /var/run/s6/container_environment/MARIADB_DATA
cat <<<"${NEW_INSTALL}" > /var/run/s6/container_environment/NEW_INSTALL

# Redirect log output
mkdir -p "${MARIADB_DATA}"
Expand Down
9 changes: 9 additions & 0 deletions matter_server/rootfs/etc/s6-overlay/s6-rc.d/matter-server/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Start matter-server service
# ==============================================================================
Expand All @@ -24,9 +25,11 @@ log_level_sdk=$(bashio::string.lower "$(bashio::config log_level_sdk error)")
if bashio::config.has_value "matter_server_version"; then
matter_server_version=$(bashio::config 'matter_server_version')
bashio::log.info "Installing Python Matter Server ${matter_server_version}"
# shellcheck disable=SC2102
pip3 install --pre python-matter-server[server]=="${matter_server_version}"
elif bashio::config.true "beta"; then
bashio::log.info 'Upgrading Python Matter Server to latest pre-release'
# shellcheck disable=SC2102
pip3 install --upgrade --pre python-matter-server[server]
fi

Expand All @@ -52,20 +55,24 @@ fi
primary_interface="$(bashio::api.supervisor 'GET' '/network/info' '' 'first(.interfaces[] | select (.primary == true)) .interface')"

# Try fallback method (e.g. in case NetworkManager is not available)
# shellcheck disable=SC2086
if [ -z ${primary_interface} ]; then
bashio::log.warning 'Trying fallback method to determine primary interface'
primary_interface="$(ip --json route show default | jq --raw-output '.[0].dev')"
fi

# shellcheck disable=SC2086
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
if [ -z ${primary_interface} ] || [ ${primary_interface} == "null" ]; then
bashio::exit.nok "No primary network interface found!"
fi

if bashio::config.has_value "bluetooth_adapter_id"; then
# shellcheck disable=SC2207
extra_args+=('--bluetooth-adapter' $(bashio::config 'bluetooth_adapter_id'))
fi

if bashio::config.has_value "matter_server_args"; then
# shellcheck disable=SC2207
extra_args+=($(bashio::config 'matter_server_args'))
fi

Expand All @@ -74,8 +81,10 @@ bashio::log.info "Using '${primary_interface}' as primary network interface."
# Send out discovery information to Home Assistant
/etc/s6-overlay/scripts/matter-server-discovery &

# shellcheck disable=SC2164
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
cd /root

# shellcheck disable=SC2206
matter_server_args+=(
'--storage-path' "/data"
'--port' "${server_port}"
Expand Down
1 change: 1 addition & 0 deletions matter_server/rootfs/etc/s6-overlay/scripts/banner.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Displays a simple add-on banner on startup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Send matter discovery information to Home Assistant
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions mosquitto/rootfs/etc/cont-init.d/mosquitto.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Configures mosquitto
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions mosquitto/rootfs/etc/cont-init.d/nginx.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Configures NGINX
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions mosquitto/rootfs/etc/services.d/mosquitto/discovery
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Send MQTT discovery information to Home Assistant and service information
# to the Supervisor (for other add-ons).
Expand Down
1 change: 1 addition & 0 deletions mosquitto/rootfs/etc/services.d/mosquitto/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Runs mosquitto
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions mosquitto/rootfs/etc/services.d/nginx/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Runs the NGINX daemon
# ==============================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Check certificate renewal
# ==============================================================================
Expand Down
3 changes: 2 additions & 1 deletion nginx_proxy/rootfs/etc/s6-overlay/s6-rc.d/crond/finish
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ==============================================================================
# Take down the S6 supervision tree when daemon fails
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
Expand All @@ -14,7 +15,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
3 changes: 2 additions & 1 deletion nginx_proxy/rootfs/etc/s6-overlay/s6-rc.d/nginx/finish
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ==============================================================================
# Take down the S6 supervision tree when daemon fails
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
Expand All @@ -14,7 +15,7 @@ bashio::log.info \

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
Expand Down
Loading
Loading