diff --git a/functions.sh b/functions.sh index f67bbb0..4766614 100644 --- a/functions.sh +++ b/functions.sh @@ -141,3 +141,53 @@ ensure_container_not_running () { return 0 fi } + +# check: pod $1 exists? +check_pod_exists () { + podman pod exists ${1} +} + +# ok if pod exists +ensure_pod_exists () { + if ! check_pod_exists ${1}; then + echo "ERROR : pod ${1} does not exists" + exit 1 + else + return 0 + fi +} + +# ok if pod does not exists +ensure_pod_not_exists () { + if check_pod_exists ${1}; then + echo "ERROR : pod ${1} exists" + exit 1 + else + return 0 + fi +} + +# check: pod ${1} is running? +check_pod_running () { + [[ "podman pod inspect -f '{{.State}}' ${1}" == "Running" ]] +} + +# ok if pod is running +ensure_pod_running () { + if ! check_pod_running ${1}; then + echo "ERROR : pod ${1} is not running" + exit 1 + else + return 0 + fi +} + +# ok if pod is not running +ensure_pod_not_running () { + if check_pod_running ${1}; then + echo "ERROR : pod ${1} is running" + exit 1 + else + return 0 + fi +}