#!/bin/sh

test -d "$CRUFT_ROOT/lib/systemd/system" || exit 0  # Devuan

grep -e ^CacheDirectory= -e ^StateDirectory= "$CRUFT_ROOT"/usr/lib/systemd/system/*.service | while IFS=':=' read -r service kind path
do
    service="${service##"${CRUFT_ROOT}"}"

    case "$kind" in
        CacheDirectory)
            fullpath="/var/cache/$path"
            ;;
        StateDirectory)
            fullpath="/var/lib/$path"
            ;;
    esac
    if test -d "$CRUFT_ROOT$fullpath"
    then
        echo "@$service"
        find "$CRUFT_ROOT$fullpath" 2>/dev/null | sed "s#^$CRUFT_ROOT##"
    fi
done
