#!/usr/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# Fail visibly when settings for the retired outer Quadlet remain in effect.
# An optional root prefix is used by the regression fixture.
set -eu
shopt -s nullglob dotglob
root=${1:-}
found=0
for base in /etc /run /usr/lib /usr/share; do
    directory="$root$base/containers/systemd"
    for path in "$directory/qm.container" "$directory/qm.container.d/"*.conf; do
        if [[ -f "$path" || -L "$path" ]]; then
            echo "QM: legacy outer Quadlet configuration requires migration: $path" >&2
            found=1
        fi
    done
done
if (( found )); then
    echo 'Convert container settings to /etc/qmc.conf.d/*.conf and service settings to qm.service.d.' >&2
    echo 'Move the old files outside the Quadlet directories, then restart qm.service.' >&2
    echo 'See the QM configuration migration guide; application Quadlets inside QM are unchanged.' >&2
fi
exit "$found"
