17a6f38
import re, sys, os, collections
17a6f38
17a6f38
buildroot = sys.argv[1]
453bbcb
no_bootloader = '--no-bootloader' in sys.argv
b8d3767
b8d3767
known_files = '''
b8d3767
%ghost %config(noreplace) /etc/crypttab
b8d3767
%ghost %attr(0444,root,root) /etc/udev/hwdb.bin
b8d3767
/etc/inittab
b8d3767
/usr/lib/systemd/purge-nobody-user
1d61a36
# This directory is owned by openssh-server, but we don't want to introduce
1d61a36
# a dependency. So let's copy the config and co-own the directory.
245a258
%dir %attr(0700,root,root) /etc/ssh/sshd_config.d
b8d3767
%ghost %config(noreplace) /etc/vconsole.conf
b8d3767
%ghost %config(noreplace) /etc/X11/xorg.conf.d/00-keyboard.conf
b8d3767
%ghost %attr(0664,root,root) %verify(not group) /run/utmp
b8d3767
%ghost %attr(0664,root,root) %verify(not group) /var/log/wtmp
b8d3767
%ghost %attr(0660,root,root) %verify(not group) /var/log/btmp
b8d3767
%ghost %attr(0664,root,root) %verify(not md5 size mtime group) /var/log/lastlog
b8d3767
%ghost %config(noreplace) /etc/hostname
b8d3767
%ghost %config(noreplace) /etc/localtime
b8d3767
%ghost %config(noreplace) /etc/locale.conf
b8d3767
%ghost %attr(0444,root,root) %config(noreplace) /etc/machine-id
b8d3767
%ghost %config(noreplace) /etc/machine-info
b8d3767
%ghost %attr(0700,root,root) %dir /var/cache/private
b8d3767
%ghost %attr(0700,root,root) %dir /var/lib/private
b8d3767
%ghost %dir /var/lib/private/systemd
b8d3767
%ghost %dir /var/lib/private/systemd/journal-upload
b8d3767
%ghost /var/lib/private/systemd/journal-upload/state
b8d3767
%ghost %dir /var/lib/systemd/timesync
b8d3767
%ghost /var/lib/systemd/timesync/clock
b8d3767
%ghost %dir /var/lib/systemd/backlight
b8d3767
%ghost /var/lib/systemd/catalog/database
b8d3767
%ghost %dir /var/lib/systemd/coredump
b8d3767
%ghost /var/lib/systemd/journal-upload
b8d3767
%ghost %dir /var/lib/systemd/linger
b8d3767
%ghost %attr(0600,root,root) /var/lib/systemd/random-seed
b8d3767
%ghost %dir /var/lib/systemd/rfkill
b8d3767
%ghost %dir %verify(not mode group) /var/log/journal
b8d3767
%ghost %dir /var/log/journal/remote
b8d3767
%ghost %attr(0700,root,root) %dir /var/log/private
3a8edc7
'''
b8d3767
1d61a36
known_files = {line.split()[-1]:line for line in known_files.splitlines()
1d61a36
               if line and not line.startswith('#')}
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
0708112
outputs = {suffix: open(f'.file-list-{suffix}', 'w')
0708112
           for suffix in (
0708112
                   'libs',
0708112
                   'udev',
0708112
                   'ukify',
0708112
                   'boot',
0708112
                   'pam',
0708112
                   'rpm-macros',
0708112
                   'devel',
0708112
                   'container',
0708112
                   'networkd',
0708112
                   'networkd-defaults',
0708112
                   'oomd-defaults',
0708112
                   'remote',
0708112
                   'resolve',
0708112
                   'tests',
0708112
                   'standalone-repart',
0708112
                   'standalone-tmpfiles',
0708112
                   'standalone-sysusers',
0708112
                   'standalone-shutdown',
0708112
                   'main',
0708112
           )}
0708112
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 $
be4317e
                    /run$|
9653e12
                    /var(/cache|/log|/lib|/run|)$
17a6f38
    ''', n, re.X):
17a6f38
        continue
903ce88
903ce88
    if n.endswith('.standalone'):
903ce88
        if 'repart' in n:
0708112
            o = outputs['standalone-repart']
903ce88
        elif 'tmpfiles' in n:
0708112
            o = outputs['standalone-tmpfiles']
903ce88
        elif 'sysusers' in n:
0708112
            o = outputs['standalone-sysusers']
903ce88
        elif 'shutdown' in n:
0708112
            o = outputs['standalone-shutdown']
903ce88
        else:
903ce88
            assert False, 'Found .standalone not belonging to known packages'
903ce88
903ce88
    elif '/security/pam_' in n or '/man8/pam_' in n:
0708112
        o = outputs['pam']
ced9237
    elif '/rpm/' in n:
0708112
        o = outputs['rpm-macros']
17a6f38
    elif '/usr/lib/systemd/tests' in n:
0708112
        o = outputs['tests']
903ce88
    elif 'ukify' in n:
0708112
        o = outputs['ukify']
3c4f941
    elif re.search(r'/libsystemd-(shared|core)-.*\.so$', n):
0708112
        o = outputs['main']
98684a8
    elif re.search(r'/libcryptsetup-token-systemd-.*\.so$', n):
0708112
        o = outputs['udev']
0078f9a
    elif re.search(r'/lib.*\.pc|/man3/|/usr/include|\.so$', n):
0708112
        o = outputs['devel']
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):
0708112
        o = outputs['remote']
0078f9a
17a6f38
    elif re.search(r'''mymachines|
17a6f38
                       machinectl|
17a6f38
                       systemd-nspawn|
1c98102
                       systemd-vmspawn|
17a6f38
                       import-pubring.gpg|
17a6f38
                       systemd-(machined|import|pull)|
17a6f38
                       /machine.slice|
17a6f38
                       /machines.target|
17a6f38
                       var-lib-machines.mount|
17a6f38
                       org.freedesktop.(import|machine)1
17a6f38
    ''', n, re.X):
0708112
        o = outputs['container']
0078f9a
f93a134
    # .network.example files go into systemd-networkd, and the matching files
f93a134
    # without .example go into systemd-networkd-defaults
f93a134
    elif (re.search(r'''/usr/lib/systemd/network/.*\.network$''', n)
f93a134
          and os.path.exists(f'./{n}.example')):
0708112
        o = outputs['networkd-defaults']
f93a134
f93a134
    elif re.search(r'''/usr/lib/systemd/network/.*\.network|
283a994
                       networkd|
283a994
                       networkctl|
04e2850
                       org.freedesktop.network1|
901acf5
                       sysusers\.d/systemd-network.conf|
77e1213
                       tmpfiles\.d/systemd-network.conf|
77e1213
                       systemd\.network|
77e1213
                       systemd\.netdev
283a994
    ''', n, re.X):
0708112
        o = outputs['networkd']
0078f9a
17a6f38
    elif '.so.' in n:
0708112
        o = outputs['libs']
b24b99d
5cae6af
    elif re.search(r'10-oomd-.*defaults.conf|lib/systemd/oomd.conf.d', n, re.X):
0708112
        o = outputs['oomd-defaults']
5cae6af
17a6f38
    elif re.search(r'''udev(?!\.pc)|
17a6f38
                       hwdb|
17a6f38
                       bootctl|
711d924
                       boot-update|
aed5718
                       bless-boot|
aed5718
                       boot-system-token|
4081159
                       bsod|
17a6f38
                       kernel-install|
f66faf9
                       installkernel|
17a6f38
                       vconsole|
17a6f38
                       backlight|
17a6f38
                       rfkill|
17a6f38
                       random-seed|
17a6f38
                       modules-load|
9653e12
                       timesync|
b24b99d
                       crypttab|
4a979fe
                       cryptenroll|
17a6f38
                       cryptsetup|
17a6f38
                       kmod|
17a6f38
                       quota|
db1cfc0
                       pstore|
17a6f38
                       sleep|suspend|hibernate|
17a6f38
                       systemd-tmpfiles-setup-dev|
aff1671
                       network/98-default-mac-none.link|
17a6f38
                       network/99-default.link|
db1cfc0
                       growfs|makefs|makeswap|mkswap|
db1cfc0
                       fsck|
db1cfc0
                       repart|
17a6f38
                       gpt-auto|
db1cfc0
                       volatile-root|
b24b99d
                       veritysetup|
b24b99d
                       integritysetup|
b24b99d
                       integritytab|
db1cfc0
                       remount-fs|
0b51ecf
                       /initrd|
e8cc280
                       systemd-pcr|
b2ad8fb
                       systemd-measure|
17a6f38
                       /boot$|
17a6f38
                       /kernel/|
17a6f38
                       /kernel$|
b24b99d
                       /modprobe.d|
b24b99d
                       binfmt|
b24b99d
                       sysctl|
b24b99d
                       coredump|
b24b99d
                       homed|home1|
5cae6af
                       oomd|
b24b99d
                       portabled|portable1
b24b99d
    ''', n, re.X):     # coredumpctl, homectl, portablectl are included in the main package because
b24b99d
                       # they can be used to interact with remote daemons. Also, the user could be
b24b99d
                       # confused if those user-facing binaries are not available.
0708112
        o = outputs['udev']
b24b99d
7a81930
    elif re.search(r'''/boot/efi|
1a6178c
                       /usr/lib/systemd/boot|
7a81930
                       sd-boot|systemd-boot\.|loader.conf
7a81930
    ''', n, re.X):
0708112
        o = outputs['boot']
54a3b6f
b24b99d
    elif re.search(r'''resolved|resolve1|
be0f563
                       systemd-resolve|
be0f563
                       resolvconf|
b24b99d
                       systemd\.(positive|negative)
b24b99d
    ''', n, re.X):     # resolvectl and nss-resolve are in the main package.
0708112
        o = outputs['resolve']
b24b99d
17a6f38
    else:
0708112
        o = outputs['main']
17a6f38
17a6f38
    if n in known_files:
4c7acde
        prefix = known_files[n].split()[:-1]
17a6f38
    elif file.is_dir() and not file.is_symlink():
4c7acde
        prefix = ['%dir']
c6e8c30
    elif 'README' in n:
4c7acde
        prefix = ['%doc']
17a6f38
    elif n.startswith('/etc'):
4c7acde
        prefix = ['%config(noreplace)']
4c7acde
        if file.stat().st_size == 0:
4c7acde
            prefix += ['%ghost']
17a6f38
    else:
4c7acde
        prefix = []
4c7acde
    prefix = ' '.join(prefix + ['']) if prefix else ''
17a6f38
17a6f38
    suffix = '*' if '/man/' in n else ''
17a6f38
17a6f38
    print(f'{prefix}{n}{suffix}', file=o)
0e8fc18
0e8fc18
if [print(f'ERROR: no file names were written to {o.name}')
453bbcb
    for name, o in outputs.items()
453bbcb
    if (o.tell() == 0 and
a3dfa11
        not (no_bootloader and name in ('ukify', 'boot')))
453bbcb
    ]:
0e8fc18
    sys.exit(1)