dcavalca / rpms / systemd

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