]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
Add scripts/setup_container_runtime.sh
authorZack Cerza <zack@cerza.org>
Thu, 17 Apr 2025 18:13:09 +0000 (12:13 -0600)
committerZack Cerza <zack@cerza.org>
Fri, 18 Apr 2025 19:00:31 +0000 (13:00 -0600)
Signed-off-by: Zack Cerza <zack@cerza.org>
scripts/setup_container_runtime.sh [new file with mode: 0755]

diff --git a/scripts/setup_container_runtime.sh b/scripts/setup_container_runtime.sh
new file mode 100755 (executable)
index 0000000..6c72c4f
--- /dev/null
@@ -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