d0811f
import re, sys, os, collections
d0811f
d0811f
buildroot = sys.argv[1]
d0811f
known_files = sys.stdin.read().splitlines()
d0811f
known_files = {line.split()[-1]:line for line in known_files}
d0811f
d0811f
def files(root):
d0811f
    os.chdir(root)
d0811f
    todo = collections.deque(['.'])
d0811f
    while todo:
d0811f
        n = todo.pop()
d0811f
        files = os.scandir(n)
d0811f
        for file in files:
d0811f
            yield file
d0811f
            if file.is_dir() and not file.is_symlink():
d0811f
                todo.append(file)
d0811f
d0811f
o_libs = open('.file-list-libs', 'w')
d0811f
o_udev = open('.file-list-udev', 'w')
d0811f
o_pam = open('.file-list-pam', 'w')
d0811f
o_rpm_macros = open('.file-list-rpm-macros', 'w')
d0811f
o_devel = open('.file-list-devel', 'w')
d0811f
o_container = open('.file-list-container', 'w')
d0811f
o_remote = open('.file-list-remote', 'w')
d0811f
o_tests = open('.file-list-tests', 'w')
d0811f
o_rest = open('.file-list-rest', 'w')
d0811f
for file in files(buildroot):
d0811f
    n = file.path[1:]
d0811f
    if re.match(r'''/usr/(share|include)$|
d0811f
                    /usr/share/man(/man.|)$|
d0811f
                    /usr/share/zsh(/site-functions|)$|
d0811f
                    /usr/share/dbus-1$|
d0811f
                    /usr/share/dbus-1/system.d$|
d0811f
                    /usr/share/dbus-1/(system-|)services$|
d0811f
                    /usr/share/polkit-1(/actions|/rules.d|)$|
d0811f
                    /usr/share/pkgconfig$|
d0811f
                    /usr/share/bash-completion(/completions|)$|
d0811f
                    /usr(/lib|/lib64|/bin|/sbin|)$|
d0811f
                    /usr/lib.*/(security|pkgconfig)$|
d0811f
                    /usr/lib/rpm(/macros.d|)$|
d0811f
                    /usr/lib/firewalld(/services|)$|
d0811f
                    /usr/share/(locale|licenses|doc)|             # no $
d0811f
                    /etc(/pam\.d|/xdg|/X11|/X11/xinit|/X11.*\.d|)$|
d0811f
                    /etc/(dnf|dnf/protected.d)$|
d0811f
                    /usr/(src|lib/debug)|                         # no $
d0811f
                    /run$|
d0811f
                    /var(/cache|/log|/lib|/run|)$
d0811f
    ''', n, re.X):
d0811f
        continue
d0811f
    if '/security/pam_' in n or '/man8/pam_' in n:
d0811f
        o = o_pam
d0811f
    elif '/rpm/' in n:
d0811f
        o = o_rpm_macros
d0811f
    elif re.search(r'/lib.*\.pc|/man3/|/usr/include|(?
d0811f
        o = o_devel
d0811f
    elif '/usr/lib/systemd/tests' in n:
d0811f
        o = o_tests
d0811f
    elif re.search(r'''journal-(remote|gateway|upload)|
d0811f
                       systemd-remote\.conf|
d0811f
                       /usr/share/systemd/gatewayd|
d0811f
                       /var/log/journal/remote
d0811f
    ''', n, re.X):
d0811f
        o = o_remote
d0811f
    elif re.search(r'''mymachines|
d0811f
                       machinectl|
d0811f
                       systemd-nspawn|
d0811f
                       import-pubring.gpg|
d0811f
                       systemd-(machined|import|pull)|
d0811f
                       /machine.slice|
d0811f
                       /machines.target|
d0811f
                       var-lib-machines.mount|
d0811f
                       network/80-container-v[ez]|
d0811f
                       org.freedesktop.(import|machine)1
d0811f
    ''', n, re.X):
d0811f
        o = o_container
d0811f
    elif '.so.' in n:
d0811f
        o = o_libs
d0811f
    elif re.search(r'''udev(?!\.pc)|
d0811f
                       hwdb|
d0811f
                       bootctl|
d0811f
                       sd-boot|systemd-boot\.|loader.conf|
d0811f
                       bless-boot|
d0811f
                       boot-system-token|
d0811f
                       kernel-install|
d0811f
                       vconsole|
d0811f
                       backlight|
d0811f
                       rfkill|
d0811f
                       random-seed|
d0811f
                       modules-load|
d0811f
                       timesync|
d0811f
                       cryptsetup|
d0811f
                       kmod|
d0811f
                       quota|
d0811f
                       pstore|
d0811f
                       sleep|suspend|hibernate|
d0811f
                       systemd-tmpfiles-setup-dev|
d0811f
                       network/99-default.link|
d0811f
                       growfs|makefs|makeswap|mkswap|
d0811f
                       fsck|
d0811f
                       repart|
d0811f
                       gpt-auto|
d0811f
                       volatile-root|
d0811f
                       verity-setup|
d0811f
                       remount-fs|
d0811f
                       /boot$|
d0811f
                       /boot/efi|
d0811f
                       /kernel/|
d0811f
                       /kernel$|
d0811f
                       /modprobe.d
d0811f
    ''', n, re.X):
d0811f
        o = o_udev
d0811f
    else:
d0811f
        o = o_rest
d0811f
d0811f
    if n in known_files:
d0811f
        prefix = ' '.join(known_files[n].split()[:-1])
d0811f
        if prefix:
d0811f
            prefix += ' '
d0811f
    elif file.is_dir() and not file.is_symlink():
d0811f
        prefix = '%dir '
d0811f
    elif n.startswith('/etc'):
d0811f
        prefix = '%config(noreplace) '
d0811f
    else:
d0811f
        prefix = ''
d0811f
d0811f
    suffix = '*' if '/man/' in n else ''
d0811f
d0811f
    print(f'{prefix}{n}{suffix}', file=o)