#!/bin/sh

CURRENT_MAC="$(cat /etc/podman_label.conf)"; \

process_path() {
  local p="$1"
    PAST_MAC=$(/usr/sbin/pdpl-file "$p"| grep -oP '(?<=Level_|Уровень_)\d+')
    if (( CURRENT_MAC < PAST_MAC )); then
      /usr/sbin/pdpl-file -R -r  $PAST_MAC:::ccnr "$p"
      /usr/sbin/pdpl-file -R -r  $CURRENT_MAC:::ccnr "$p"
    else
      /usr/sbin/pdpl-file -R  $PAST_MAC:::ccnr "$p"
      /usr/sbin/pdpl-file -R  $CURRENT_MAC:::ccnr "$p"
    fi
}

paths=(
  /run/containers
  /run/netns
  /run/runc
  /run/libpod
  /run/lock
  /var/lib/containers
  /var/cache
)

if command -v /usr/sbin/pdpl-file >/dev/null 2>&1; then
  for p in "${paths[@]}"; do
    process_path "$p"
  done
fi
