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