From 5e0a3769a2147abdce170a71f9b1c56f3269d4f8 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 15 Jan 2021 12:29:07 -0800 Subject: [PATCH] tests/rootless.sh: fix/ignore shellcheck warnings Signed-off-by: Kir Kolyshkin --- Makefile | 2 +- tests/rootless.sh | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index cafe6d1e4a7..c4ee761a446 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ validate: $(GO) vet $(MOD_VENDOR) ./... shellcheck: - shellcheck tests/integration/*.bats tests/integration/*.sh + shellcheck tests/integration/*.bats tests/integration/*.sh tests/*.sh # TODO: add shellcheck for more sh files shfmt: diff --git a/tests/rootless.sh b/tests/rootless.sh index ced022012bc..edd9d1c05da 100755 --- a/tests/rootless.sh +++ b/tests/rootless.sh @@ -27,7 +27,7 @@ ALL_FEATURES=("idmap" "cgroup") if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then ALL_FEATURES=("idmap") fi -ROOT="$(readlink -f "$(dirname "${BASH_SOURCE}")/..")" +ROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")" # FEATURE: Opportunistic new{uid,gid}map support, allowing a rootless container # to be set up with the usage of helper setuid binaries. @@ -93,7 +93,8 @@ function cleanup() { # List of cgroups. We handle name= cgroups as well as combined # (comma-separated) cgroups and correctly split and/or strip them. -ALL_CGROUPS=($(cat /proc/self/cgroup | cut -d: -f2 | sed -E '{s/^name=//;s/,/\n/;/^$/D}')) +# shellcheck disable=SC2207 +ALL_CGROUPS=($(cut -d: -f2 "$CGROUP_MOUNT/cgroup.subtree_control"; done + # shellcheck disable=SC2013 + for f in $(cat "$CGROUP_MOUNT/cgroup.controllers"); do echo "+$f" >"$CGROUP_MOUNT/cgroup.subtree_control"; done set +x # Create the cgroup. mkdir -p "$CGROUP_MOUNT/$CGROUP_PATH" @@ -143,7 +145,7 @@ function disable_cgroup() { # feature knobs this shouldn't take too long -- but the number of tested # combinations is O(2^n)). function powerset() { - eval printf '%s' $(printf '{,%s+}' "$@"): + eval printf '%s' "$(printf '{,%s+}' "$@")": } features_powerset="$(powerset "${ALL_FEATURES[@]}")" @@ -155,26 +157,26 @@ features_powerset="$(powerset "${ALL_FEATURES[@]}")" IFS=: idx=0 for enabled_features in $features_powerset; do - idx="$(($idx + 1))" + ((idx++)) echo "[$(printf '%.2d' "$idx")] run rootless tests ... (${enabled_features%%+})" unset IFS for feature in "${ALL_FEATURES[@]}"; do hook_func="disable_$feature" - grep -E "(^|\+)$feature(\+|$)" <<<$enabled_features &>/dev/null && hook_func="enable_$feature" + grep -E "(^|\+)$feature(\+|$)" <<<"$enabled_features" &>/dev/null && hook_func="enable_$feature" "$hook_func" done # Run the test suite! - echo path: $PATH + echo "path: $PATH" export ROOTLESS_FEATURES="$enabled_features" if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then # We use `ssh rootless@localhost` instead of `sudo -u rootless` for creating systemd user session. # Alternatively we could use `machinectl shell`, but it is known not to work well on SELinux-enabled hosts as of April 2020: # https://bugzilla.redhat.com/show_bug.cgi?id=1788616 - ssh -t -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/rootless.key rootless@localhost -- PATH="$PATH" RUNC_USE_SYSTEMD="$RUNC_USE_SYSTEMD" bats -t "$ROOT/tests/integration$ROOTLESS_TESTPATH" + ssh -t -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "$HOME/rootless.key" rootless@localhost -- PATH="$PATH" RUNC_USE_SYSTEMD="$RUNC_USE_SYSTEMD" bats -t "$ROOT/tests/integration$ROOTLESS_TESTPATH" else - sudo -HE -u rootless PATH="$PATH" $(which bats) -t "$ROOT/tests/integration$ROOTLESS_TESTPATH" + sudo -HE -u rootless PATH="$PATH" "$(which bats)" -t "$ROOT/tests/integration$ROOTLESS_TESTPATH" fi cleanup done