From c7c270cc03f98f32707f8a24d3292af5cb4aecef Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Tue, 9 Dec 2025 18:51:56 +0000 Subject: [PATCH] style: Use shfmt for shell scripts (#2841) --- .github/scripts/conan/init.sh | 4 +- .../scripts/execute-tests-under-sanitizer.sh | 18 +++---- .github/scripts/prepare-release-artifacts.sh | 2 +- .pre-commit-config.yaml | 6 +++ cmake/pkg/postinst | 51 +++++++++---------- docker/develop/run | 31 ++++++----- pre-commit-hooks/check-doxygen-docs.sh | 34 ++++++------- pre-commit-hooks/fix-local-includes.sh | 4 +- pre-commit-hooks/run-go-fmt.sh | 2 +- pre-commit-hooks/verify-commits.sh | 13 +++-- 10 files changed, 87 insertions(+), 78 deletions(-) diff --git a/.github/scripts/conan/init.sh b/.github/scripts/conan/init.sh index 5875d57b0..dba73a6ec 100755 --- a/.github/scripts/conan/init.sh +++ b/.github/scripts/conan/init.sh @@ -40,9 +40,9 @@ mkdir -p "$PROFILES_DIR" if [[ "$(uname)" == "Darwin" ]]; then create_profile_with_sanitizers "apple-clang" "$APPLE_CLANG_PROFILE" - echo "include(apple-clang)" > "$PROFILES_DIR/default" + echo "include(apple-clang)" >"$PROFILES_DIR/default" else create_profile_with_sanitizers "clang" "$CLANG_PROFILE" create_profile_with_sanitizers "gcc" "$GCC_PROFILE" - echo "include(gcc)" > "$PROFILES_DIR/default" + echo "include(gcc)" >"$PROFILES_DIR/default" fi diff --git a/.github/scripts/execute-tests-under-sanitizer.sh b/.github/scripts/execute-tests-under-sanitizer.sh index 18e609c78..9646994bb 100755 --- a/.github/scripts/execute-tests-under-sanitizer.sh +++ b/.github/scripts/execute-tests-under-sanitizer.sh @@ -22,8 +22,8 @@ fi TEST_BINARY=$1 if [[ ! -f "$TEST_BINARY" ]]; then - echo "Test binary not found: $TEST_BINARY" - exit 1 + echo "Test binary not found: $TEST_BINARY" + exit 1 fi TESTS=$($TEST_BINARY --gtest_list_tests | awk '/^ / {print suite $1} !/^ / {suite=$1}') @@ -35,12 +35,12 @@ export TSAN_OPTIONS="die_after_fork=0" export MallocNanoZone='0' # for MacOSX for TEST in $TESTS; do - OUTPUT_FILE="$OUTPUT_DIR/${TEST//\//_}.log" - $TEST_BINARY --gtest_filter="$TEST" > "$OUTPUT_FILE" 2>&1 + OUTPUT_FILE="$OUTPUT_DIR/${TEST//\//_}.log" + $TEST_BINARY --gtest_filter="$TEST" >"$OUTPUT_FILE" 2>&1 - if [ $? -ne 0 ]; then - echo "'$TEST' failed a sanitizer check." - else - rm "$OUTPUT_FILE" - fi + if [ $? -ne 0 ]; then + echo "'$TEST' failed a sanitizer check." + else + rm "$OUTPUT_FILE" + fi done diff --git a/.github/scripts/prepare-release-artifacts.sh b/.github/scripts/prepare-release-artifacts.sh index 2267d8f99..0461170af 100755 --- a/.github/scripts/prepare-release-artifacts.sh +++ b/.github/scripts/prepare-release-artifacts.sh @@ -20,5 +20,5 @@ for artifact_name in $(ls); do rm "${artifact_name}/${BINARY_NAME}" rm -r "${artifact_name}" - sha256sum "./${artifact_name}.zip" > "./${artifact_name}.zip.sha256sum" + sha256sum "./${artifact_name}.zip" >"./${artifact_name}.zip.sha256sum" done diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50c7fc888..91fe5bf7e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,6 +63,12 @@ repos: hooks: - id: black + - repo: https://github.com/scop/pre-commit-shfmt + rev: 2a30809d16bc7a60d9b97353c797f42b510d3368 # frozen: v3.12.0-2 + hooks: + - id: shfmt + args: ["-i", "4", "--write"] + # Running some C++ hooks before clang-format # to ensure that the style is consistent. - repo: local diff --git a/cmake/pkg/postinst b/cmake/pkg/postinst index 19780b21c..d10353d9b 100755 --- a/cmake/pkg/postinst +++ b/cmake/pkg/postinst @@ -10,37 +10,36 @@ CLIO_BIN="$CLIO_PREFIX/bin/${CLIO_EXECUTABLE}" CLIO_CONFIG="$CLIO_PREFIX/etc/config.json" case "$1" in - configure) - if ! id -u "$USER_NAME" >/dev/null 2>&1; then - # Users who should not have a home directory should have their home directory set to /nonexistent - # https://www.debian.org/doc/debian-policy/ch-opersys.html#non-existent-home-directories - useradd \ - --system \ - --home-dir /nonexistent \ - --no-create-home \ - --shell /usr/sbin/nologin \ - --comment "system user for ${CLIO_EXECUTABLE}" \ - --user-group \ - ${USER_NAME} - fi +configure) + if ! id -u "$USER_NAME" >/dev/null 2>&1; then + # Users who should not have a home directory should have their home directory set to /nonexistent + # https://www.debian.org/doc/debian-policy/ch-opersys.html#non-existent-home-directories + useradd \ + --system \ + --home-dir /nonexistent \ + --no-create-home \ + --shell /usr/sbin/nologin \ + --comment "system user for ${CLIO_EXECUTABLE}" \ + --user-group \ + ${USER_NAME} + fi - install -d -o "$USER_NAME" -g "$GROUP_NAME" /var/log/clio + install -d -o "$USER_NAME" -g "$GROUP_NAME" /var/log/clio - if [ -f "$CLIO_CONFIG" ]; then - chown "$USER_NAME:$GROUP_NAME" "$CLIO_CONFIG" - fi + if [ -f "$CLIO_CONFIG" ]; then + chown "$USER_NAME:$GROUP_NAME" "$CLIO_CONFIG" + fi - chown -R "$USER_NAME:$GROUP_NAME" "$CLIO_PREFIX" + chown -R "$USER_NAME:$GROUP_NAME" "$CLIO_PREFIX" - ln -sf "$CLIO_BIN" "/usr/bin/${CLIO_EXECUTABLE}" + ln -sf "$CLIO_BIN" "/usr/bin/${CLIO_EXECUTABLE}" - ;; - abort-upgrade|abort-remove|abort-deconfigure) - ;; - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 1 - ;; + ;; +abort-upgrade | abort-remove | abort-deconfigure) ;; +*) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; esac exit 0 diff --git a/docker/develop/run b/docker/develop/run index 6874831e2..88518f14e 100755 --- a/docker/develop/run +++ b/docker/develop/run @@ -2,7 +2,7 @@ script_dir=$(dirname $0) -pushd $script_dir > /dev/null +pushd $script_dir >/dev/null function start_container { if [ -z "$(docker ps -q -f name=clio_develop)" ]; then @@ -41,21 +41,26 @@ EOF } case $1 in - -h|--help) - print_help ;; +-h | --help) + print_help + ;; - -t|--terminal) - open_terminal ;; +-t | --terminal) + open_terminal + ;; - -s|--stop) - stop_container ;; +-s | --stop) + stop_container + ;; - -*) - echo "Unknown option: $1" - print_help ;; +-*) + echo "Unknown option: $1" + print_help + ;; - *) - run "$@" ;; +*) + run "$@" + ;; esac -popd > /dev/null +popd >/dev/null diff --git a/pre-commit-hooks/check-doxygen-docs.sh b/pre-commit-hooks/check-doxygen-docs.sh index cc5487925..76a27f2cb 100755 --- a/pre-commit-hooks/check-doxygen-docs.sh +++ b/pre-commit-hooks/check-doxygen-docs.sh @@ -45,7 +45,7 @@ if [[ "1.14.0" > "$version" ]]; then ERROR ----------------------------------------------------------------------------- - A minimum of version 1.14 of `which doxygen` is required. + A minimum of version 1.14 of $(which doxygen) is required. Your version is $version. Please upgrade it. Your changes may fail CI checks. @@ -55,26 +55,26 @@ EOF exit 0 fi -mkdir -p ${DOCDIR} > /dev/null 2>&1 -pushd ${DOCDIR} > /dev/null 2>&1 +mkdir -p ${DOCDIR} >/dev/null 2>&1 +pushd ${DOCDIR} >/dev/null 2>&1 -cat ${ROOT}/docs/Doxyfile | \ -sed \ - -e "s/\${LINT}/YES/" \ - -e "s/\${WARN_AS_ERROR}/NO/" \ - -e "s!\${SOURCE}!${ROOT}!" \ - -e "s/\${USE_DOT}/NO/" \ - -e "s/\${EXCLUDES}/impl/" \ -| ${DOXYGEN} - 2> ${TMPFILE} 1> /dev/null +cat ${ROOT}/docs/Doxyfile | + sed \ + -e "s/\${LINT}/YES/" \ + -e "s/\${WARN_AS_ERROR}/NO/" \ + -e "s!\${SOURCE}!${ROOT}!" \ + -e "s/\${USE_DOT}/NO/" \ + -e "s/\${EXCLUDES}/impl/" | + ${DOXYGEN} - 2>${TMPFILE} 1>/dev/null # We don't want to check for default values and typedefs as well as for member variables -OUT=$(cat ${TMPFILE} \ - | grep -v "=default" \ - | grep -v "\(variable\)" \ - | grep -v "\(typedef\)") +OUT=$(cat ${TMPFILE} | + grep -v "=default" | + grep -v "\(variable\)" | + grep -v "\(typedef\)") -rm -rf ${TMPFILE} > /dev/null 2>&1 -popd > /dev/null 2>&1 +rm -rf ${TMPFILE} >/dev/null 2>&1 +popd >/dev/null 2>&1 if [[ ! -z "$OUT" ]]; then cat < style - sed -E 's|#include "(.*)"|#include <\1>|g' "$file_path" > "$file_path_all_global" + sed -E 's|#include "(.*)"|#include <\1>|g' "$file_path" >"$file_path_all_global" # Make local includes to be "..." style - sed -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path_all_global" > "$file_path_fixed" + sed -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g" "$file_path_all_global" >"$file_path_fixed" rm "$file_path_all_global" # Check if the temporary file is different from the original file diff --git a/pre-commit-hooks/run-go-fmt.sh b/pre-commit-hooks/run-go-fmt.sh index 6f73c8944..c13312ea1 100755 --- a/pre-commit-hooks/run-go-fmt.sh +++ b/pre-commit-hooks/run-go-fmt.sh @@ -4,7 +4,7 @@ # set -e -o pipefail -if ! command -v gofmt &> /dev/null ; then +if ! command -v gofmt &>/dev/null; then echo "gofmt not installed or available in the PATH" >&2 exit 1 fi diff --git a/pre-commit-hooks/verify-commits.sh b/pre-commit-hooks/verify-commits.sh index 2ebf170f4..70ddb4d24 100755 --- a/pre-commit-hooks/verify-commits.sh +++ b/pre-commit-hooks/verify-commits.sh @@ -1,5 +1,4 @@ -#!/bin/sh - +#!/bin/bash # git for-each-ref refs/tags # see which tags are annotated and which are lightweight. Annotated tags are "tag" objects. # # Set these so your commits and tags are always signed @@ -7,7 +6,7 @@ # git config tag.gpgsign true verify_commit_signed() { - if git verify-commit HEAD &> /dev/null; then + if git verify-commit HEAD &>/dev/null; then : # echo "HEAD commit seems signed..." else @@ -17,7 +16,7 @@ verify_commit_signed() { } verify_tag() { - if git describe --exact-match --tags HEAD &> /dev/null; then + if git describe --exact-match --tags HEAD &>/dev/null; then : # You might be ok to push # echo "Tag is annotated." return 0 @@ -28,7 +27,7 @@ verify_tag() { } verify_tag_signed() { - if git verify-tag "$version" &> /dev/null ; then + if git verify-tag "$version" &>/dev/null; then : # ok, I guess we'll let you push # echo "Tag appears signed" return 0 @@ -40,11 +39,11 @@ verify_tag_signed() { } # Check some things if we're pushing a branch called "release/" -if echo "$PRE_COMMIT_REMOTE_BRANCH" | grep ^refs\/heads\/release\/ &> /dev/null ; then +if echo "$PRE_COMMIT_REMOTE_BRANCH" | grep ^refs\/heads\/release\/ &>/dev/null; then version=$(git tag --points-at HEAD) echo "Looks like you're trying to push a $version release..." echo "Making sure you've signed and tagged it." - if verify_commit_signed && verify_tag && verify_tag_signed ; then + if verify_commit_signed && verify_tag && verify_tag_signed; then : # Ok, I guess you can push else exit 1