From 2886b34e97265a1b43185e4d0d9e3b489804f867 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 25 May 2026 22:13:18 -0700 Subject: [PATCH 1/3] .editorconfig: add [[shell]] section, space_redirects 1. Add [[shell]] section, which is for shfmt only to apply formatting to shell files that does not end with .sh or bash, but with a shebang line present. 2. Add space_redirects = true setting for shfmt. Note the [[language]] syntax is not officially supported by editorconfig standard (the discussion since at least 2019 is still ongoing, see [1]) but is supported by shfmt since v3.8.0 (February 2024). [1]: https://github.com/editorconfig/editorconfig/issues/404 Signed-off-by: Kir Kolyshkin --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.editorconfig b/.editorconfig index 5e4fc7919c3..7d716a6808b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,12 @@ ignore = true [*.{bash,bats,sh}] indent_style = space indent_size = 4 +space_redirects = true + +# This is for shell scripts with shebang but no extensions. +# Not yes supported by editorconfig[1], only by shfmt. +# https://github.com/editorconfig/editorconfig/issues/404 +[[shell]] +indent_style = space +indent_size = 4 +space_redirects = true From 9a3427dfefb47c3d4595ec71132f858a38c6cc34 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 25 May 2026 22:45:25 -0700 Subject: [PATCH 2/3] hack: format with shfmt -w Using shfmt v3.13.1 Signed-off-by: Kir Kolyshkin --- hack/apparmor_tag.sh | 4 +- hack/bats | 67 +++++++++++++------------ hack/btrfs_installed_tag.sh | 4 +- hack/check_root.sh | 4 +- hack/commit-subject-check.sh | 20 ++++---- hack/get_ci_vm.sh | 24 ++++----- hack/golangci-lint.sh | 19 +++---- hack/install_golangci.sh | 5 +- hack/libsubid_tag.sh | 8 +-- hack/make-and-check-size | 14 +++--- hack/man-page-checker | 40 +++++++-------- hack/perf/bz-2162111.sh | 38 +++++++------- hack/perf/create.sh | 4 +- hack/perf/helpers.bash | 30 +++++------ hack/perf/ps.sh | 4 +- hack/perf/rm.sh | 8 +-- hack/perf/run.sh | 16 +++--- hack/perf/start.sh | 8 +-- hack/perf/stop.sh | 8 +-- hack/perf/system-df.sh | 4 +- hack/podman-commands.sh | 12 ++--- hack/podman-registry | 97 +++++++++++++++++++----------------- hack/podman-socat | 12 ++--- hack/podmanv2-retry | 3 +- hack/sqlite_tag.sh | 4 +- hack/systemd_tag.sh | 4 +- hack/tree_status.sh | 21 ++++---- hack/xref-docker-options | 36 ++++++------- 28 files changed, 262 insertions(+), 256 deletions(-) diff --git a/hack/apparmor_tag.sh b/hack/apparmor_tag.sh index 794370e79d7..5c6b38c1472 100755 --- a/hack/apparmor_tag.sh +++ b/hack/apparmor_tag.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -if pkg-config libapparmor 2> /dev/null ; then - echo apparmor +if pkg-config libapparmor 2> /dev/null; then + echo apparmor fi diff --git a/hack/bats b/hack/bats index 505b8904400..53cce319dee 100755 --- a/hack/bats +++ b/hack/bats @@ -67,35 +67,40 @@ declare -a bats_filter=() declare -a TESTS -for i;do - value=`expr "$i" : '[^=]*=\(.*\)'` +for i; do + value=$(expr "$i" : '[^=]*=\(.*\)') case "$i" in - -h|--help) echo "$usage"; exit 0;; - --root) TEST_ROOTLESS= ;; - --rootless) TEST_ROOT= ;; - --remote) REMOTE=remote ;; - --tap|-t) bats_opts+=("-t") ;; - --ts|-T) bats_opts+=("-T") ;; - --tag=*) bats_filter=("--filter-tags" "$value") - if [[ "$value" = "ci:parallel" ]]; then - bats_opts+=("--jobs" $(nproc)) - fi;; - */*.bats) TESTS+=("$i") ;; - *) - if [[ $i =~ : ]]; then - tname=${i%:*} # network:localhost -> network - filt=${i#*:} # network:localhost -> localhost - TESTS+=($(echo $TESTS_DIR/*$tname*.bats)) - bats_filter=("--filter" "$filt") - else - TESTS+=($(echo $TESTS_DIR/*$i*.bats)) - fi - ;; + -h | --help) + echo "$usage" + exit 0 + ;; + --root) TEST_ROOTLESS= ;; + --rootless) TEST_ROOT= ;; + --remote) REMOTE=remote ;; + --tap | -t) bats_opts+=("-t") ;; + --ts | -T) bats_opts+=("-T") ;; + --tag=*) + bats_filter=("--filter-tags" "$value") + if [[ "$value" = "ci:parallel" ]]; then + bats_opts+=("--jobs" $(nproc)) + fi + ;; + */*.bats) TESTS+=("$i") ;; + *) + if [[ $i =~ : ]]; then + tname=${i%:*} # network:localhost -> network + filt=${i#*:} # network:localhost -> localhost + TESTS+=($(echo $TESTS_DIR/*$tname*.bats)) + bats_filter=("--filter" "$filt") + else + TESTS+=($(echo $TESTS_DIR/*$i*.bats)) + fi + ;; esac done -if [ ${#TESTS[@]} -eq 0 ] ; then - TESTS=("$TESTS_DIR") +if [ ${#TESTS[@]} -eq 0 ]; then + TESTS=("$TESTS_DIR") fi # With --remote, use correct binary and make sure daem--I mean server--is live @@ -125,12 +130,12 @@ export PODMAN_BATS_LEAK_CHECK=1 # Root if [[ "$TEST_ROOT" ]]; then echo "# bats ${bats_opts[*]} ${bats_filter[*]} ${TESTS[*]}" - sudo --preserve-env=PODMAN \ - --preserve-env=QUADLET \ - --preserve-env=PODMAN_TEST_DEBUG \ - --preserve-env=CONTAINERS_HELPER_BINARY_DIR \ - --preserve-env=PODMAN_ROOTLESS_USER \ - bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}" + sudo --preserve-env=PODMAN \ + --preserve-env=QUADLET \ + --preserve-env=PODMAN_TEST_DEBUG \ + --preserve-env=CONTAINERS_HELPER_BINARY_DIR \ + --preserve-env=PODMAN_ROOTLESS_USER \ + bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}" rc=$? fi diff --git a/hack/btrfs_installed_tag.sh b/hack/btrfs_installed_tag.sh index f2f2b33c83a..5cc687b9e30 100755 --- a/hack/btrfs_installed_tag.sh +++ b/hack/btrfs_installed_tag.sh @@ -2,6 +2,6 @@ ${CPP:-${CC:-cc} -E} ${CPPFLAGS} - > /dev/null 2> /dev/null << EOF #include EOF -if test $? -ne 0 ; then - echo exclude_graphdriver_btrfs +if test $? -ne 0; then + echo exclude_graphdriver_btrfs fi diff --git a/hack/check_root.sh b/hack/check_root.sh index 2489a4eddee..fac236aad3e 100755 --- a/hack/check_root.sh +++ b/hack/check_root.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash if ! [ $(id -u) = 0 ]; then - echo "Please run as root! '$*' requires root privileges." - exit 1 + echo "Please run as root! '$*' requires root privileges." + exit 1 fi diff --git a/hack/commit-subject-check.sh b/hack/commit-subject-check.sh index 1f03f65fe4c..bdfb4acdf5e 100755 --- a/hack/commit-subject-check.sh +++ b/hack/commit-subject-check.sh @@ -12,22 +12,22 @@ set -euo pipefail MAX=90 if [[ $# -ne 1 ]]; then - echo "Usage: $0 " >&2 - exit 2 + echo "Usage: $0 " >&2 + exit 2 fi range=$1 rc=0 while IFS=$'\t' read -r sha subject; do - len=${#subject} - if [[ $len -eq 0 ]]; then - echo "$sha: empty commit subject" >&2 - rc=1 - elif [[ $len -ge $MAX ]]; then - echo "$sha: subject is $len chars (must be < $MAX): $subject" >&2 - rc=1 - fi + len=${#subject} + if [[ $len -eq 0 ]]; then + echo "$sha: empty commit subject" >&2 + rc=1 + elif [[ $len -ge $MAX ]]; then + echo "$sha: subject is $len chars (must be < $MAX): $subject" >&2 + rc=1 + fi done < <(git log --no-merges --format='%H%x09%s' "$range") exit $rc diff --git a/hack/get_ci_vm.sh b/hack/get_ci_vm.sh index bdd947bba86..d4f044d9710 100755 --- a/hack/get_ci_vm.sh +++ b/hack/get_ci_vm.sh @@ -18,7 +18,7 @@ REPO_DIRPATH=$(realpath "$SCRIPT_DIRPATH/../") # Help detect what get_ci_vm container called this script GET_CI_VM="${GET_CI_VM:-0}" in_get_ci_vm() { - if ((GET_CI_VM==0)); then + if ((GET_CI_VM == 0)); then echo "Error: $1 is not intended for use in this context" exit 2 fi @@ -27,10 +27,10 @@ in_get_ci_vm() { # get_ci_vm APIv1 container entrypoint calls into this script # to obtain required repo. specific configuration options. if [[ "$1" == "--config" ]]; then - in_get_ci_vm "$1" # handles GET_CI_VM==0 case + in_get_ci_vm "$1" # handles GET_CI_VM==0 case case "$GET_CI_VM" in - 1) - cat <$saved_size_file + echo $size > $saved_size_file printf "%-20s size=%9d\n" $bin $size fi done diff --git a/hack/man-page-checker b/hack/man-page-checker index 04c41139e94..045e3a3286f 100755 --- a/hack/man-page-checker +++ b/hack/man-page-checker @@ -6,11 +6,10 @@ verbose= for i; do case "$i" in - -v|--verbose) verbose=verbose ;; + -v | --verbose) verbose=verbose ;; esac done - die() { echo "$(basename $0): $*" >&2 exit 1 @@ -20,13 +19,13 @@ cd $(dirname $0)/../docs/source/markdown || die "Please run me from top-level li rc=0 -for md in *.1.md;do +for md in *.1.md; do # Read the first line after '# NAME' (or '## NAME'). (FIXME: # and ## # are not the same; should we stick to one convention?) # There may be more than one name, e.g. podman-info.1.md has # podman-system-info then another line with podman-info. We # care only about the first. - name=$(grep -E -A1 '^#* NAME' $md|tail -1|awk '{print $1}' | tr -d \\\\) + name=$(grep -E -A1 '^#* NAME' $md | tail -1 | awk '{print $1}' | tr -d \\\\) expect=$(basename $md .1.md) if [ "$name" != "$expect" ]; then @@ -42,8 +41,8 @@ done # Make sure the descriptive text in podman-foo.1.md matches the one # in the table in podman.1.md. podman-remote is not a podman subcommand, # so it is excluded here. -for md in $(ls -1 *-*.1.md | grep -v remote);do - desc=$(grep -E -A1 '^#* NAME' $md|tail -1|sed -e 's/^podman[^ ]\+ - //') +for md in $(ls -1 *-*.1.md | grep -v remote); do + desc=$(grep -E -A1 '^#* NAME' $md | tail -1 | sed -e 's/^podman[^ ]\+ - //') # podman.1.md has a two-column table; podman-*.1.md all have three. parent=$(echo $md | sed -e 's/^\(.*\)-.*$/\1.1.md/') @@ -59,7 +58,7 @@ for md in $(ls -1 *-*.1.md | grep -v remote);do parent="podman-system.1.md" fi x=3 - if expr -- "$parent" : ".*-" >/dev/null; then + if expr -- "$parent" : ".*-" > /dev/null; then x=4 fi @@ -97,36 +96,36 @@ function compare_usage() { local from_help=$(echo "$help_output" | grep -A1 '^Usage:' | tail -1) # strip off command name from both - from_man=$(sed -e "s/\*\*$cmd\*\*[[:space:]]*//" <<<"$from_man") - from_help=$(sed -e "s/^[[:space:]]*${cmd}[[:space:]]*//" <<<"$from_help") + from_man=$(sed -e "s/\*\*$cmd\*\*[[:space:]]*//" <<< "$from_man") + from_help=$(sed -e "s/^[[:space:]]*${cmd}[[:space:]]*//" <<< "$from_help") # man page lists 'foo [*options*]', help msg shows 'foo [flags]'. # Make sure if one has it, the other does too. - if expr "$from_man" : "\[\*options\*\]" >/dev/null; then - if expr "$from_help" : "\[options\]" >/dev/null; then + if expr "$from_man" : "\[\*options\*\]" > /dev/null; then + if expr "$from_help" : "\[options\]" > /dev/null; then : else echo "WARNING: $cmd: man page shows '[*options*]', help does not show [options]" rc=1 - fi - elif expr "$from_help" : "\[flags\]" >/dev/null; then + fi + elif expr "$from_help" : "\[flags\]" > /dev/null; then echo "WARNING: $cmd: --help shows [flags], man page does not show [*options*]" rc=1 fi # Strip off options and flags; start comparing arguments - from_man=$(sed -e 's/^\[\*options\*\][[:space:]]*//' <<<"$from_man") - from_help=$(sed -e 's/^\[flags\][[:space:]]*//' <<<"$from_help") + from_man=$(sed -e 's/^\[\*options\*\][[:space:]]*//' <<< "$from_man") + from_help=$(sed -e 's/^\[flags\][[:space:]]*//' <<< "$from_help") # Args in man page are '*foo*', in --help are 'FOO'. Convert all to # UPCASE simply because it stands out better to the eye. - from_man=$(sed -e 's/\*\([a-z-]\+\)\*/\U\1/g' <<<"$from_man") + from_man=$(sed -e 's/\*\([a-z-]\+\)\*/\U\1/g' <<< "$from_man") # FIXME: one of the common patterns is for --help to show 'POD [POD...]' # but man page show 'pod ...'. This conversion may help one day, but # not yet: there are too many inconsistencies such as '[pod ...]' # (brackets) and 'pod...' (no space between). -# from_help=$(sed -e 's/\([A-Z]\+\)[[:space:]]\+\[\1[[:space:]]*\.\.\.\]/\1 .../' <<<"$from_help") + # from_help=$(sed -e 's/\([A-Z]\+\)[[:space:]]\+\[\1[[:space:]]*\.\.\.\]/\1 .../' <<<"$from_help") # Compare man-page and --help usage strings. For now, do so only # when run with --verbose. @@ -142,7 +141,7 @@ function compare_usage() { # Pass 3: compare synopses. # # Make sure the SYNOPSIS line in podman-foo.1.md reads '**podman foo** ...' -for md in *.1.md;do +for md in *.1.md; do # FIXME: several pages have a multi-line form of SYNOPSIS in which # many or all flags are enumerated. Some of these are trivial # and really should be made into one line (podman-container-exists, @@ -152,7 +151,7 @@ for md in *.1.md;do # To view those: # $ less $(for i in docs/*.1.md;do x=$(grep -A2 '^#* SYNOPSIS' $i|tail -1); if [ -n "$x" ]; then echo $i;fi;done) # - synopsis=$(grep -E -A1 '^#* SYNOPSIS' $md|tail -1) + synopsis=$(grep -E -A1 '^#* SYNOPSIS' $md | tail -1) # Command name must be bracketed by double asterisks; options and # arguments are bracketed by single ones. @@ -177,7 +176,7 @@ for md in *.1.md;do # The convention is to use UPPER CASE in 'podman foo --help', # but *lower case bracketed by asterisks* in the man page - if expr "$synopsis" : ".*[A-Z]" >/dev/null; then + if expr "$synopsis" : ".*[A-Z]" > /dev/null; then echo printf "Inconsistent capitalization in SYNOPSIS in %s\n" $md printf " '%s' should not contain upper-case characters\n" "$synopsis" @@ -192,5 +191,4 @@ for md in *.1.md;do compare_usage "$md_nodash" "$synopsis" done - exit $rc diff --git a/hack/perf/bz-2162111.sh b/hack/perf/bz-2162111.sh index 4e802e119d6..eaed045aec3 100755 --- a/hack/perf/bz-2162111.sh +++ b/hack/perf/bz-2162111.sh @@ -32,7 +32,7 @@ container_cmd="--name $container_name \ # Script to clean up before each benchmark below prepare_sh=$(mktemp -p $tmp --suffix '.prepare.sh') -cat >$prepare_sh < $prepare_sh << EOF \$ENGINE rm -f \$(\$ENGINE ps -aq) \$ENGINE volume prune -f \$ENGINE volume create $volume_name @@ -41,14 +41,14 @@ echo_bold "Prepare script: $prepare_sh" # Script to create container below create_sh=$(mktemp -p $tmp --suffix '.create.sh') -cat >$create_sh < $create_sh << EOF \$ENGINE create $container_cmd true EOF echo_bold "Create script: $create_sh" # Script to run container below run_sh=$(mktemp -p $tmp --suffix '.run.sh') -cat >$run_sh < $run_sh << EOF # Make sure to remove the container from a previous run \$ENGINE rm -f $container_name || true # Run the container @@ -61,40 +61,40 @@ echo "----------------------------------------------------" echo echo_bold "Create $NUM_CONTAINERS containers" hyperfine --warmup 10 --runs $RUNS \ - --prepare "ENGINE=$ENGINE_A sh $prepare_sh" \ - --prepare "ENGINE=$ENGINE_B sh $prepare_sh" \ - "$ENGINE_A create $container_cmd true" \ - "$ENGINE_B create $container_cmd true" + --prepare "ENGINE=$ENGINE_A sh $prepare_sh" \ + --prepare "ENGINE=$ENGINE_B sh $prepare_sh" \ + "$ENGINE_A create $container_cmd true" \ + "$ENGINE_B create $container_cmd true" echo "" echo "----------------------------------------------------" echo echo_bold "Start $NUM_CONTAINERS containers" hyperfine --warmup 10 --runs $RUNS \ - --prepare "ENGINE=$ENGINE_A sh $prepare_sh; ENGINE=$ENGINE_A sh $create_sh" \ - --prepare "ENGINE=$ENGINE_B sh $prepare_sh; ENGINE=$ENGINE_B sh $create_sh" \ - "$ENGINE_A start $container_name" \ - "$ENGINE_B start $container_name" + --prepare "ENGINE=$ENGINE_A sh $prepare_sh; ENGINE=$ENGINE_A sh $create_sh" \ + --prepare "ENGINE=$ENGINE_B sh $prepare_sh; ENGINE=$ENGINE_B sh $create_sh" \ + "$ENGINE_A start $container_name" \ + "$ENGINE_B start $container_name" echo "" echo "----------------------------------------------------" echo echo_bold "Stop $NUM_CONTAINERS containers" hyperfine --warmup 10 --runs $RUNS \ - --prepare "ENGINE=$ENGINE_A sh $run_sh" \ - --prepare "ENGINE=$ENGINE_B sh $run_sh" \ - "$ENGINE_A stop $container_name" \ - "$ENGINE_B stop $container_name" + --prepare "ENGINE=$ENGINE_A sh $run_sh" \ + --prepare "ENGINE=$ENGINE_B sh $run_sh" \ + "$ENGINE_A stop $container_name" \ + "$ENGINE_B stop $container_name" echo "" echo "----------------------------------------------------" echo echo_bold "Remove $NUM_CONTAINERS containers" hyperfine --warmup 10 --runs $RUNS \ - --prepare "ENGINE=$ENGINE_A sh $prepare_sh; ENGINE=$ENGINE_A sh $create_sh" \ - --prepare "ENGINE=$ENGINE_B sh $prepare_sh; ENGINE=$ENGINE_B sh $create_sh" \ - "$ENGINE_A rm -f $container_name" \ - "$ENGINE_B rm -f $container_name" + --prepare "ENGINE=$ENGINE_A sh $prepare_sh; ENGINE=$ENGINE_A sh $create_sh" \ + --prepare "ENGINE=$ENGINE_B sh $prepare_sh; ENGINE=$ENGINE_B sh $create_sh" \ + "$ENGINE_A rm -f $container_name" \ + "$ENGINE_B rm -f $container_name" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/create.sh b/hack/perf/create.sh index a6af109b739..80797c75ab9 100755 --- a/hack/perf/create.sh +++ b/hack/perf/create.sh @@ -4,8 +4,8 @@ source ./helpers.bash setup echo_bold "Create $RUNS containers" hyperfine --warmup 10 --runs $RUNS \ - "$ENGINE_A create $IMAGE" \ - "$ENGINE_B create $IMAGE" + "$ENGINE_A create $IMAGE" \ + "$ENGINE_B create $IMAGE" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/helpers.bash b/hack/perf/helpers.bash index bfb576ffd43..c41b8b87584 100644 --- a/hack/perf/helpers.bash +++ b/hack/perf/helpers.bash @@ -12,25 +12,25 @@ function echo_bold() { } function pull_image() { - echo_bold "... pulling $IMAGE" - $ENGINE_A pull $IMAGE -q > /dev/null - $ENGINE_B pull $IMAGE -q > /dev/null + echo_bold "... pulling $IMAGE" + $ENGINE_A pull $IMAGE -q > /dev/null + $ENGINE_B pull $IMAGE -q > /dev/null } function setup() { - echo_bold "---------------------------------------------------" - echo_bold "... comparing $ENGINE_A with $ENGINE_B" - echo_bold "... cleaning up previous containers and images" - $ENGINE_A system prune -f > /dev/null - $ENGINE_B system prune -f > /dev/null - pull_image - echo "" + echo_bold "---------------------------------------------------" + echo_bold "... comparing $ENGINE_A with $ENGINE_B" + echo_bold "... cleaning up previous containers and images" + $ENGINE_A system prune -f > /dev/null + $ENGINE_B system prune -f > /dev/null + pull_image + echo "" } function create_containers() { - echo_bold "... creating $NUM_CONTAINERS containers" - for i in $(eval echo "{0..$NUM_CONTAINERS}"); do - $ENGINE_A create $IMAGE >> /dev/null - $ENGINE_B create $IMAGE >> /dev/null - done + echo_bold "... creating $NUM_CONTAINERS containers" + for i in $(eval echo "{0..$NUM_CONTAINERS}"); do + $ENGINE_A create $IMAGE >> /dev/null + $ENGINE_B create $IMAGE >> /dev/null + done } diff --git a/hack/perf/ps.sh b/hack/perf/ps.sh index 42e2ba4b0f2..dceec95006c 100755 --- a/hack/perf/ps.sh +++ b/hack/perf/ps.sh @@ -5,8 +5,8 @@ setup echo_bold "List $NUM_CONTAINERS created containers" create_containers hyperfine --warmup 10 --runs $RUNS \ - "$ENGINE_A ps -a" \ - "$ENGINE_B ps -a" + "$ENGINE_A ps -a" \ + "$ENGINE_B ps -a" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/rm.sh b/hack/perf/rm.sh index 0e4a05893d5..4cd7e263fd9 100755 --- a/hack/perf/rm.sh +++ b/hack/perf/rm.sh @@ -4,10 +4,10 @@ source ./helpers.bash setup echo_bold "Remove $RUNS containers in a row" hyperfine --warmup 10 --runs $RUNS \ - --prepare "$ENGINE_A create --name=123 $IMAGE" \ - --prepare "$ENGINE_B create --name=123 $IMAGE" \ - "$ENGINE_A rm 123" \ - "$ENGINE_B rm 123" + --prepare "$ENGINE_A create --name=123 $IMAGE" \ + --prepare "$ENGINE_B create --name=123 $IMAGE" \ + "$ENGINE_A rm 123" \ + "$ENGINE_B rm 123" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/run.sh b/hack/perf/run.sh index 32dff386ce9..7e87716a2a8 100755 --- a/hack/perf/run.sh +++ b/hack/perf/run.sh @@ -4,18 +4,18 @@ source ./helpers.bash setup echo_bold "Run $RUNS containers in a row" hyperfine --warmup 10 --runs $RUNS \ - --prepare "$ENGINE_A rm -f 123 || true" \ - --prepare "$ENGINE_B rm -f 123 || true" \ - "$ENGINE_A run --name=123 $IMAGE true" \ - "$ENGINE_B run --name=123 $IMAGE true" + --prepare "$ENGINE_A rm -f 123 || true" \ + --prepare "$ENGINE_B rm -f 123 || true" \ + "$ENGINE_A run --name=123 $IMAGE true" \ + "$ENGINE_B run --name=123 $IMAGE true" setup echo_bold "Run and remove $RUNS containers in a row" hyperfine --warmup 10 --runs $RUNS \ - --prepare "$ENGINE_A rm -f 123 || true" \ - --prepare "$ENGINE_B rm -f 123 || true" \ - "$ENGINE_A run --rm --name=123 $IMAGE true" \ - "$ENGINE_B run --rm --name=123 $IMAGE true" + --prepare "$ENGINE_A rm -f 123 || true" \ + --prepare "$ENGINE_B rm -f 123 || true" \ + "$ENGINE_A run --rm --name=123 $IMAGE true" \ + "$ENGINE_B run --rm --name=123 $IMAGE true" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/start.sh b/hack/perf/start.sh index 467a7df124f..cdfbd024822 100755 --- a/hack/perf/start.sh +++ b/hack/perf/start.sh @@ -4,10 +4,10 @@ source ./helpers.bash setup echo_bold "Start $RUNS containers in a row" hyperfine --warmup 10 --runs $RUNS \ - --prepare "$ENGINE_A rm -f 123 || true; $ENGINE_A create --name=123 $IMAGE true" \ - --prepare "$ENGINE_B rm -f 123 || true; $ENGINE_B create --name=123 $IMAGE true" \ - "$ENGINE_A start 123" \ - "$ENGINE_B start 123" + --prepare "$ENGINE_A rm -f 123 || true; $ENGINE_A create --name=123 $IMAGE true" \ + --prepare "$ENGINE_B rm -f 123 || true; $ENGINE_B create --name=123 $IMAGE true" \ + "$ENGINE_A start 123" \ + "$ENGINE_B start 123" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/stop.sh b/hack/perf/stop.sh index 93534ccabd9..0c415286224 100755 --- a/hack/perf/stop.sh +++ b/hack/perf/stop.sh @@ -4,10 +4,10 @@ source ./helpers.bash setup echo_bold "Stop $RUNS containers in a row" hyperfine --warmup 10 --runs $RUNS \ - --prepare "$ENGINE_A rm -f 123 || true; $ENGINE_A run -d --name=123 $IMAGE top" \ - --prepare "$ENGINE_B rm -f 123 || true; $ENGINE_B run -d --name=123 $IMAGE top" \ - "$ENGINE_A stop 123" \ - "$ENGINE_B stop 123" + --prepare "$ENGINE_A rm -f 123 || true; $ENGINE_A run -d --name=123 $IMAGE top" \ + --prepare "$ENGINE_B rm -f 123 || true; $ENGINE_B run -d --name=123 $IMAGE top" \ + "$ENGINE_A stop 123" \ + "$ENGINE_B stop 123" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/perf/system-df.sh b/hack/perf/system-df.sh index f5f690c06cc..0d9dfbac06c 100755 --- a/hack/perf/system-df.sh +++ b/hack/perf/system-df.sh @@ -5,8 +5,8 @@ setup echo_bold "List $NUM_CONTAINERS created containers" create_containers hyperfine --warmup 10 --runs $RUNS \ - "$ENGINE_A system df" \ - "$ENGINE_B system df" + "$ENGINE_A system df" \ + "$ENGINE_B system df" # Clean up $ENGINE_A system prune -f >> /dev/null diff --git a/hack/podman-commands.sh b/hack/podman-commands.sh index 0455287d4c8..6cc21fe2fbe 100755 --- a/hack/podman-commands.sh +++ b/hack/podman-commands.sh @@ -17,13 +17,12 @@ function die() { exit 1 } - # Run 'podman help' (possibly against a subcommand, e.g. 'podman help image') # and return a list of each first word under 'Available Commands', that is, # the command name but not its description. function podman_commands() { - $PODMAN help "$@" |\ - awk '/^Available Commands:/{ok=1;next}/^Options:/{ok=0}ok { print $1 }' |\ + $PODMAN help "$@" | + awk '/^Available Commands:/{ok=1;next}/^Options:/{ok=0}ok { print $1 }' | grep . # Special case: podman-completion is a hidden command @@ -40,7 +39,7 @@ function podman_man() { # This md file has a table of the form: # | [podman-cmd(1)\[(podman-cmd.1.md) | Description ... | # For all such, print the 'cmd' portion (the one in brackets). - sed -ne 's/^|\s\+\[podman-\([a-z]\+\)(1.*/\1/p' /dev/null; then + if expr "$usage" : '.*\[command\]$' > /dev/null; then compare_help_and_man "$@" $cmd fi done @@ -88,11 +87,10 @@ function compare_help_and_man() { rm -f /tmp/${basename}_{help,man}.txt } - compare_help_and_man if [ $rc -ne 0 ]; then - cat <&2 exit 1 } @@ -66,16 +66,22 @@ die () { while getopts "i:u:p:P:hv" opt; do case "$opt" in - i) PODMAN_REGISTRY_IMAGE=$OPTARG ;; - u) PODMAN_REGISTRY_USER=$OPTARG ;; - p) PODMAN_REGISTRY_PASS=$OPTARG ;; - P) PODMAN_REGISTRY_PORT=$OPTARG ;; - h) echo "$usage"; exit 0;; - v) verbose=1 ;; - \?) echo "Run '$ME -h' for help" >&2; exit 1;; + i) PODMAN_REGISTRY_IMAGE=$OPTARG ;; + u) PODMAN_REGISTRY_USER=$OPTARG ;; + p) PODMAN_REGISTRY_PASS=$OPTARG ;; + P) PODMAN_REGISTRY_PORT=$OPTARG ;; + h) + echo "$usage" + exit 0 + ;; + v) verbose=1 ;; + \?) + echo "Run '$ME -h' for help" >&2 + exit 1 + ;; esac done -shift $((OPTIND-1)) +shift $((OPTIND - 1)) # END option processing ############################################################################### @@ -100,11 +106,11 @@ function podman() { fi # Reset $PODMAN, so ps/logs/stop use same args as the initial start - PODMAN="$(<${PODMAN_REGISTRY_WORKDIR}/PODMAN)" + PODMAN="$(< ${PODMAN_REGISTRY_WORKDIR}/PODMAN)" - ${PODMAN} --root ${PODMAN_REGISTRY_WORKDIR}/root \ - --runroot ${PODMAN_REGISTRY_WORKDIR}/runroot \ - "$@" + ${PODMAN} --root ${PODMAN_REGISTRY_WORKDIR}/root \ + --runroot ${PODMAN_REGISTRY_WORKDIR}/runroot \ + "$@" } ############### @@ -116,7 +122,7 @@ function must_pass() { "$@" &> $log if [ $? -ne 0 ]; then echo "$ME: Command failed: $*" >&2 - cat $log >&2 + cat $log >&2 # If we ever get here, it's a given that the registry is not running. # Clean up after ourselves. @@ -129,16 +135,16 @@ function must_pass() { # wait_for_port # Returns once port is available on localhost ################### function wait_for_port() { - local port=$1 # Numeric port + local port=$1 # Numeric port local host=127.0.0.1 local _timeout=5 # Wait while [ $_timeout -gt 0 ]; do - { exec {unused_fd}<> /dev/tcp/$host/$port; } &>/dev/null && return + { exec {unused_fd}<> /dev/tcp/$host/$port; } &> /dev/null && return sleep 1 - _timeout=$(( $_timeout - 1 )) + _timeout=$(($_timeout - 1)) done die "Timed out waiting for port $port" @@ -151,8 +157,8 @@ function wait_for_port() { function do_start() { # If called without a port, assign a random one in the 5xxx range if [ -z "${PODMAN_REGISTRY_PORT}" ]; then - for port in $(shuf -i 5000-5999);do - if ! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then + for port in $(shuf -i 5000-5999); do + if ! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &> /dev/null; then PODMAN_REGISTRY_PORT=$port break fi @@ -179,7 +185,7 @@ function do_start() { # Preserve initial podman path & args, so all subsequent invocations # of this script are consistent with the first one. - echo "$PODMAN" >${PODMAN_REGISTRY_WORKDIR}/PODMAN + echo "$PODMAN" > ${PODMAN_REGISTRY_WORKDIR}/PODMAN local AUTHDIR=${PODMAN_REGISTRY_WORKDIR}/auth mkdir -p $AUTHDIR @@ -191,21 +197,21 @@ function do_start() { set +e # Give it three tries, to compensate for flakes - podman pull ${PODMAN_REGISTRY_IMAGE} &>/dev/null || - podman pull ${PODMAN_REGISTRY_IMAGE} &>/dev/null || + podman pull ${PODMAN_REGISTRY_IMAGE} &> /dev/null || + podman pull ${PODMAN_REGISTRY_IMAGE} &> /dev/null || must_pass podman pull ${PODMAN_REGISTRY_IMAGE} # Registry image needs a cert. Self-signed is good enough. local CERT=$AUTHDIR/domain.crt - must_pass openssl req -newkey rsa:4096 -nodes -sha256 \ - -keyout ${AUTHDIR}/domain.key -x509 -days 2 \ - -out ${AUTHDIR}/domain.crt \ - -subj "/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=localhost" + must_pass openssl req -newkey rsa:4096 -nodes -sha256 \ + -keyout ${AUTHDIR}/domain.key -x509 -days 2 \ + -out ${AUTHDIR}/domain.crt \ + -subj "/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=localhost" # Store credentials where container will see them. We can't run # this one via must_pass because we need its stdout. - htpasswd -Bbn ${PODMAN_REGISTRY_USER} ${PODMAN_REGISTRY_PASS} \ - > $AUTHDIR/htpasswd + htpasswd -Bbn ${PODMAN_REGISTRY_USER} ${PODMAN_REGISTRY_PASS} \ + > $AUTHDIR/htpasswd if [ $? -ne 0 ]; then rm -rf ${PODMAN_REGISTRY_WORKDIR} die "Command failed: htpasswd" @@ -213,19 +219,19 @@ function do_start() { # In case someone needs to debug echo "${PODMAN_REGISTRY_USER}:${PODMAN_REGISTRY_PASS}" \ - > $AUTHDIR/htpasswd-plaintext + > $AUTHDIR/htpasswd-plaintext # Run the registry container. - must_pass podman run --quiet -d \ - -p ${PODMAN_REGISTRY_PORT}:5000 \ - --name registry \ - -v $AUTHDIR:/auth:Z \ - -e "REGISTRY_AUTH=htpasswd" \ - -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ - -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ - -e "REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt" \ - -e "REGISTRY_HTTP_TLS_KEY=/auth/domain.key" \ - ${PODMAN_REGISTRY_IMAGE} + must_pass podman run --quiet -d \ + -p ${PODMAN_REGISTRY_PORT}:5000 \ + --name registry \ + -v $AUTHDIR:/auth:Z \ + -e "REGISTRY_AUTH=htpasswd" \ + -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ + -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ + -e "REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt" \ + -e "REGISTRY_HTTP_TLS_KEY=/auth/domain.key" \ + ${PODMAN_REGISTRY_IMAGE} # Confirm that registry started and port is active wait_for_port $PODMAN_REGISTRY_PORT @@ -236,7 +242,6 @@ function do_start() { done } - function do_stop() { podman stop registry podman rm -f registry @@ -250,12 +255,10 @@ function do_stop() { fi } - function do_ps() { podman ps -a } - function do_logs() { podman logs registry } @@ -269,11 +272,11 @@ action=${1?ACTION$missing} shift case "$action" in - start) do_start ;; - stop) do_stop ;; - ps) do_ps ;; - logs) do_logs ;; - *) die "Unknown action '$action'; must be start / stop / ps / logs" ;; +start) do_start ;; +stop) do_stop ;; +ps) do_ps ;; +logs) do_logs ;; +*) die "Unknown action '$action'; must be start / stop / ps / logs" ;; esac # END command-line processing diff --git a/hack/podman-socat b/hack/podman-socat index 9190faf86a4..3b7c1a838ca 100755 --- a/hack/podman-socat +++ b/hack/podman-socat @@ -8,12 +8,12 @@ if [[ $(id -u) != 0 ]]; then exit 2 fi -if ! command -v socat >/dev/null 2>&1; then +if ! command -v socat > /dev/null 2>&1; then echo 1>&2 "socat not found on PATH" fi PODMAN=${PODMAN:-podman} -if ! command -v "$PODMAN" >/dev/null 2>&1; then +if ! command -v "$PODMAN" > /dev/null 2>&1; then echo 1>&2 "$PODMAN not found on PATH" fi @@ -55,7 +55,7 @@ trap "cleanup $TMPDIR" EXIT mkdir -p "${TMPDIR}"/{podman,crio,crio-run,cni/net.d,ctnr,tunnel} export CNI_CONFIG_PATH=${TMPDIR}/cni/net.d -cat >"$CNI_CONFIG_PATH"/87-podman-bridge.conflist <<-EOT +cat > "$CNI_CONFIG_PATH"/87-podman-bridge.conflist <<- EOT { "cniVersion": "0.3.0", "name": "podman", @@ -96,7 +96,7 @@ PODMAN="$PODMAN $PODMAN_ARGS" PODMAN_HOST="${TMPDIR}/podman/podman-socat.sock" SOCAT_HOST="${TMPDIR}/podman/podman.sock" -cat <<-EOT +cat <<- EOT Podman service running at unix://$SOCAT_HOST See /tmp/podman-socat.log for API stream capture See /tmp/podman-service.log for service logging @@ -106,7 +106,7 @@ usage: sudo bin/podman-remote --url unix://$SOCAT_HOST images ^C to exit EOT -$PODMAN system service --timeout=0 "unix://$PODMAN_HOST" >/tmp/podman-service.log 2>&1 & +$PODMAN system service --timeout=0 "unix://$PODMAN_HOST" > /tmp/podman-service.log 2>&1 & REAP_PIDS=$! -socat -v "UNIX-LISTEN:$SOCAT_HOST",fork,reuseaddr,unlink-early "UNIX-CONNECT:$PODMAN_HOST" >/tmp/podman-socat.log 2>&1 +socat -v "UNIX-LISTEN:$SOCAT_HOST",fork,reuseaddr,unlink-early "UNIX-CONNECT:$PODMAN_HOST" > /tmp/podman-socat.log 2>&1 diff --git a/hack/podmanv2-retry b/hack/podmanv2-retry index 1f3be0731b7..6c8fe369e57 100755 --- a/hack/podmanv2-retry +++ b/hack/podmanv2-retry @@ -19,10 +19,9 @@ die() { exit 1 } -test -n "$PODMAN_V2" || die "Please set \$PODMAN_V2 (path to podman v2)" +test -n "$PODMAN_V2" || die "Please set \$PODMAN_V2 (path to podman v2)" test -n "$PODMAN_FALLBACK" || die "Please set \$PODMAN_FALLBACK (path to podman)" - result=$(${PODMAN_V2} "$@" 2>&1) rc=$? diff --git a/hack/sqlite_tag.sh b/hack/sqlite_tag.sh index 0248355cf37..72b056cd773 100755 --- a/hack/sqlite_tag.sh +++ b/hack/sqlite_tag.sh @@ -2,6 +2,6 @@ ${CPP:-${CC:-cc} -E} ${CPPFLAGS} - &> /dev/null << EOF #include EOF -if test $? -eq 0 ; then - echo libsqlite3 +if test $? -eq 0; then + echo libsqlite3 fi diff --git a/hack/systemd_tag.sh b/hack/systemd_tag.sh index 5af3228816d..f6a360e7884 100755 --- a/hack/systemd_tag.sh +++ b/hack/systemd_tag.sh @@ -2,6 +2,6 @@ ${CPP:-${CC:-cc} -E} ${CPPFLAGS} - > /dev/null 2> /dev/null << EOF #include EOF -if test $? -eq 0 ; then - echo systemd +if test $? -eq 0; then + echo systemd fi diff --git a/hack/tree_status.sh b/hack/tree_status.sh index 8c9c2abe8fa..3745210fe47 100755 --- a/hack/tree_status.sh +++ b/hack/tree_status.sh @@ -4,16 +4,15 @@ set -e SUGGESTION="${SUGGESTION:-run \"make vendor\" and commit all changes.}" STATUS=$(git status --porcelain) -if [[ -z $STATUS ]] -then - echo "tree is clean" +if [[ -z $STATUS ]]; then + echo "tree is clean" else - echo "tree is dirty, please $SUGGESTION" - echo "" - echo "$STATUS" - echo "" - echo "---------------------- Diff below ----------------------" - echo "" - git --no-pager diff - exit 1 + echo "tree is dirty, please $SUGGESTION" + echo "" + echo "$STATUS" + echo "" + echo "---------------------- Diff below ----------------------" + echo "" + git --no-pager diff + exit 1 fi diff --git a/hack/xref-docker-options b/hack/xref-docker-options index 133d678f36f..46ccad07ab3 100755 --- a/hack/xref-docker-options +++ b/hack/xref-docker-options @@ -7,21 +7,21 @@ # implemented in podman but hidden (so of course not in man pages); # some are not implemented and never will be (swarm). declare -a hidden=( - "docker --config" # Hidden - "docker --context" # Hidden - "docker --debug" # Hidden - "docker --host" # Hidden - "docker -D" # Hidden - "docker -H" # Hidden + "docker --config" # Hidden + "docker --context" # Hidden + "docker --debug" # Hidden + "docker --host" # Hidden + "docker -D" # Hidden + "docker -H" # Hidden - "docker .* --isolation" # Only for Windows containers - "docker .* --kernel-memory" # CGroupsV1 only, present but hidden - "docker .* --link" # Deprecated in docker - "docker .* --runtime" # Global option under podman - "docker .* --storage-opt" # Global option under podman + "docker .* --isolation" # Only for Windows containers + "docker .* --kernel-memory" # CGroupsV1 only, present but hidden + "docker .* --link" # Deprecated in docker + "docker .* --runtime" # Global option under podman + "docker .* --storage-opt" # Global option under podman - "docker (container|image) ls" # Hidden alias to list - "docker context" # Hidden + "docker (container|image) ls" # Hidden alias to list + "docker context" # Hidden # Hidden "docker (container |)logs --details" @@ -58,15 +58,15 @@ index de9ef8630..b9e4bd0ef 100755 \$section = lc \$1; " -patch --quiet -p1 <<<"$DIFF" +patch --quiet -p1 <<< "$DIFF" # Sometimes this produces no output at all. Likely cause is that you # have inconsistent .md files, solution is 'make docs'. If that doesn't # work, remove the '2>&1 \' from the line below and rerun. I don't feel # it's worth the time to improve the error handling here. -PODMAN=/usr/bin/docker $TMP_SCRIPT 2>&1 \ - | sed -ne 's/^.*podman \+\(.*\) --help. lists .\(.*\)., which is not.*/- [ ] docker \1 \2/p' \ - | sed -e 's/ \+/ /g' \ - | grep -vE "($hidden_re)\$" +PODMAN=/usr/bin/docker $TMP_SCRIPT 2>&1 | + sed -ne 's/^.*podman \+\(.*\) --help. lists .\(.*\)., which is not.*/- [ ] docker \1 \2/p' | + sed -e 's/ \+/ /g' | + grep -vE "($hidden_re)\$" rm -f $TMP_SCRIPT From 835d8fa115b3a75e11e290b467ae6c807807a099 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 25 May 2026 22:49:40 -0700 Subject: [PATCH 3/3] Makefile: add shfmt target to format ./hack/ only Signed-off-by: Kir Kolyshkin --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9d4b3bc6b97..37c848b9cae 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS} # possible, as long as they don't disturb the formatting # (i.e. DO NOT ADD A 'v' prefix!) GOLANGCI_LINT_VERSION := 2.12.2 +SHFMT_VERSION := 3.13.1 PYTHON ?= $(shell command -v python3 python|head -n1) PKG_MANAGER ?= $(shell command -v dnf yum|head -n1) # ~/.local/bin is not in PATH on all systems @@ -291,6 +292,11 @@ golangci-lint: .install.golangci-lint CGO_ENABLED=0 GOOS=freebsd hack/golangci-lint.sh CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 hack/golangci-lint.sh +.PHONY: shfmt +shfmt: .install.shfmt + ./bin/shfmt --version + ./bin/shfmt -d -w ./hack/ + .PHONY: test/checkseccomp/checkseccomp test/checkseccomp/checkseccomp: $(wildcard test/checkseccomp/*.go) $(GOCMD) build $(BUILDFLAGS) $(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./test/checkseccomp @@ -319,7 +325,7 @@ codespell: # Code validation target that **DOES NOT** require building podman binaries .PHONY: validate-source -validate-source: lint .commit-subject-check swagger-check tests-expect-exit pr-removes-fixed-skips +validate-source: lint shfmt .commit-subject-check swagger-check tests-expect-exit pr-removes-fixed-skips # Code validation target that **DOES** require building podman binaries .PHONY: validate-binaries @@ -1013,6 +1019,10 @@ install.tools: .install.golangci-lint ## Install needed tools .install.golangci-lint: VERSION=$(GOLANGCI_LINT_VERSION) ./hack/install_golangci.sh +.PHONY: .install.shfmt +.install.shfmt: + GOBIN=$(CURDIR)/bin $(GO) install mvdan.cc/sh/v3/cmd/shfmt@v$(SHFMT_VERSION) + .PHONY: .install.swagger .install.swagger: $(MAKE) -C test/tools build/swagger