github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/hack/podmanv2-retry (about)

     1  #!/bin/bash
     2  #
     3  # podman-try - try running a command via PODMAN1; use PODMAN2 as fallback
     4  #
     5  # Intended for use with a podmanv2 client. If a command isn't yet
     6  # implemented, fall back to regular podman:
     7  #
     8  #    Set PODMAN_V2 to the path to a podman v2 client
     9  #    Set PODMAN_FALLBACK to the path to regular podman
    10  #
    11  # THIS IS IMPERFECT. In particular, it will not work if stdin is redirected
    12  # (e.g. 'podman ... < file' or 'something | podman'); nor for anything
    13  # that generates continuous output ('podman logs -f'); and probably more
    14  # situations.
    15  #
    16  
    17  die() {
    18      echo "$(basename $0): $*" >&2
    19      exit 1
    20  }
    21  
    22  test -n "$PODMAN_V2"       || die "Please set \$PODMAN_V2 (path to podman v2)"
    23  test -n "$PODMAN_FALLBACK" || die "Please set \$PODMAN_FALLBACK (path to podman)"
    24  
    25  
    26  result=$(${PODMAN_V2} "$@" 2>&1)
    27  rc=$?
    28  
    29  if [ $rc == 125 ]; then
    30      if [[ "$result" =~ unrecognized\ command|unknown\ flag|unknown\ shorthand ]]; then
    31          result=$(${PODMAN_FALLBACK} "$@")
    32          rc=$?
    33      fi
    34  fi
    35  
    36  echo -n "$result"
    37  exit $rc