diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 310900e..ed72123 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,9 @@ jobs: - name: Check formatting run: ./scripts/lint/02-clang-format.sh + - name: Check shell scripts + run: ./scripts/lint/03-shellcheck.sh + tool: strategy: matrix: diff --git a/scripts/clang-format.sh b/scripts/clang-format.sh index a4d7e0c..1289406 100755 --- a/scripts/clang-format.sh +++ b/scripts/clang-format.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # SPDX-License-Identifier: GPL-3.0-only -FILES=($(git ls-files '*.[ch]')) +readarray -t FILES < <(git ls-files '*.c' '*.h') FMT_OPTS=( "-style=file" diff --git a/scripts/deps.sh b/scripts/deps.sh index 0900796..43cba75 100755 --- a/scripts/deps.sh +++ b/scripts/deps.sh @@ -29,6 +29,7 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then make \ pkgconf \ sdcc \ + shellcheck \ xxd elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then sudo dnf install \ @@ -41,6 +42,7 @@ elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then gcc \ make \ sdcc \ + ShellCheck \ systemd-devel \ vim-common elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then @@ -55,6 +57,7 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then make \ pkgconf \ sdcc \ + shellcheck \ systemd-libs \ vim else diff --git a/scripts/lint/03-shellcheck.sh b/scripts/lint/03-shellcheck.sh new file mode 100755 index 0000000..d9ebe43 --- /dev/null +++ b/scripts/lint/03-shellcheck.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-only + +# Check if any shell scripts have issues. + +LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) +. "$LINT_DIR/util.sh" + +echo -n "Checking shell scripts..." + +if ! command -v shellcheck > /dev/null; then + skipped "shellcheck not found" + exit 0 +fi + +readarray -t FILES < <(git ls-files '*.sh') +needs_formatting=() + +for file in "${FILES[@]}"; do + # SC1091: Ignore external scripts + if ! shellcheck -f quiet --exclude=SC1091 "$file"; then + needs_formatting+=("$file") + fi +done + +if [[ "${#needs_formatting[@]}" != "0" ]]; then + failed + + for file in "${needs_formatting[@]}"; do + echo "- $file" + done + + exit 1 +fi + +passed diff --git a/scripts/power.sh b/scripts/power.sh index a2d15e9..9a8cdd3 100755 --- a/scripts/power.sh +++ b/scripts/power.sh @@ -60,7 +60,7 @@ do else F="$(date "+%T")" - last_E="$(sudo cat /sys/class/powercap/intel-rapl\:0/energy_uj)" + last_E="$(sudo cat '/sys/class/powercap/intel-rapl:0/energy_uj')" sleep 1 if [ "${has_bat}" == "1" ] @@ -73,15 +73,15 @@ do F="${F}\t$(printf "%.2f" "${bat_W}")" fi - E="$(sudo cat /sys/class/powercap/intel-rapl\:0/energy_uj)" + E="$(sudo cat '/sys/class/powercap/intel-rapl:0/energy_uj')" W="$(echo "(${E} - ${last_E})/1000000" | bc -lq)" F="${F}\t$(printf "%.1f" "${W}")" - PL1_uW="$(sudo cat /sys/class/powercap/intel-rapl\:0/constraint_0_power_limit_uw)" + PL1_uW="$(sudo cat '/sys/class/powercap/intel-rapl:0/constraint_0_power_limit_uw')" PL1_W="$(echo "${PL1_uW}/1000000" | bc -lq)" F="${F}\t$(printf "%.1f" "${PL1_W}")" - PL2_uW="$(sudo cat /sys/class/powercap/intel-rapl\:0/constraint_1_power_limit_uw)" + PL2_uW="$(sudo cat '/sys/class/powercap/intel-rapl:0/constraint_1_power_limit_uw')" PL2_W="$(echo "${PL2_uW}/1000000" | bc -lq)" F="${F}\t$(printf "%.1f" "${PL2_W}")"