From: Zack Cerza Date: Thu, 17 Apr 2025 18:13:09 +0000 (-0600) Subject: Add scripts/setup_container_runtime.sh X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7da3a5df23aef8c315ed9f713f812590f9ee707a;p=ceph-build.git Add scripts/setup_container_runtime.sh Signed-off-by: Zack Cerza --- diff --git a/scripts/setup_container_runtime.sh b/scripts/setup_container_runtime.sh new file mode 100755 index 000000000..6c72c4f16 --- /dev/null +++ b/scripts/setup_container_runtime.sh @@ -0,0 +1,48 @@ +#!/bin/bash -ex +# vim: ts=4 sw=4 expandtab +function setup_container_runtime () { + if command -v podman; then + PODMAN_MAJOR_VERSION=$(podman version -f json | jq -r '.Client.Version|split(".")[0]') + if [ "$PODMAN_MAJOR_VERSION" -lt 4 ]; then + echo "Found a very old podman; removing" + command -v dnf && sudo dnf remove -y podman + command -v apt && sudo apt remove -y podman + fi + fi + + if ! command -v podman; then + if command -v dnf; then + sudo dnf install -y podman + elif command -v apt-cache; then + apt-get update -q + VERSION=$(apt-cache show podman | grep Version: | sort -r | awk '/^Version:/{print $2; exit}') + if [[ "${VERSION:0:1}" -ge 4 ]]; then + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y podman + elif ! command -v docker; then + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y docker.io + fi + fi + fi + + if command -v podman; then + PODMAN_MAJOR_VERSION=$(podman version -f json | jq -r '.Client.Version|split(".")[0]') + if [ "$PODMAN_MAJOR_VERSION" -ge 4 ]; then + PODMAN_DIR="$HOME/.local/share/containers" + test -d $PODMAN_DIR && command -v restorecon && sudo restorecon -R -T0 -x $PODMAN_DIR + PODMAN_STORAGE_DIR="$PODMAN_DIR/storage" + if [ -d $PODMAN_STORAGE_DIR ]; then + sudo chgrp -R $(groups | cut -d' ' -f1) $PODMAN_STORAGE_DIR + if [ $(podman unshare du -s --block-size=1G $PODMAN_STORAGE_DIR | awk '{print $1}') -ge 50 ]; then + time podman image prune --filter=until="$(echo '24*7*2' | bc)h" --all --force + time podman system prune --force + test "$PODMAN_MAJOR_VERSION" -ge 5 && time podman system check --repair --quick + fi + fi + fi + fi +} + +# If the script is executed (as opposed to sourced), run the function now +if [ "$(basename -- "${0#-}")" = "$(basename -- "${BASH_SOURCE}")" ]; then + setup_container_runtime +fi