Skip to content

Commit

Permalink
Remove sbin usage
Browse files Browse the repository at this point in the history
Fedora 42 has merged /usr/bin and /usr/sbin
https://fedoraproject.org/wiki/Changes/Unify_bin_and_sbin

This moves all of the lorax executables into bin, adjusts all the uses
of sbin including some tests, and some called by lorax and
livemedia-creator. These are now discovered using shutil.which instead
of being hard-coded.

It also removes checking for linker problems /usr/sbin since that would
just double the scan time.
  • Loading branch information
bcl committed Jan 28, 2025
1 parent ab55131 commit 267178e
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/livemedia-creator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Run this to create a bootable live iso::

You can run it directly from the lorax git repo like this::

sudo PATH=./src/sbin/:$PATH PYTHONPATH=./src/ ./src/sbin/livemedia-creator \
sudo PATH=./src/bin/:$PATH PYTHONPATH=./src/ ./src/bin/livemedia-creator \
--make-iso --iso=/extra/iso/boot.iso \
--ks=./docs/fedora-livemedia.ks --lorax-templates=./share/

Expand Down
6 changes: 3 additions & 3 deletions lorax.spec
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ make DESTDIR=$RPM_BUILD_ROOT mandir=%{_mandir} install
%doc docs/*ks
%{python3_sitelib}/pylorax
%{python3_sitelib}/*.egg-info
%{_sbindir}/lorax
%{_sbindir}/mkefiboot
%{_sbindir}/livemedia-creator
%{_bindir}/lorax
%{_bindir}/mkefiboot
%{_bindir}/livemedia-creator
%{_bindir}/mkksiso
%{_bindir}/image-minimizer
%dir %{_sysconfdir}/lorax
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
[os.path.join(root, fname)]))

# executable
data_files.append(("/usr/sbin", ["src/sbin/lorax", "src/sbin/mkefiboot",
"src/sbin/livemedia-creator"]))
data_files.append(("/usr/bin", ["src/bin/image-minimizer", "src/bin/mkksiso"]))
data_files.append(("/usr/bin", ["src/bin/lorax", "src/bin/mkefiboot",
"src/bin/livemedia-creator",
"src/bin/image-minimizer", "src/bin/mkksiso"]))

setup(name="lorax",
version="42.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ ConditionKernelCommandLine=!inst.rngd=0
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/rngd
ExecStart=/usr/sbin/rngd -f $RNGD_ARGS
ExecStart=/usr/bin/rngd -f $RNGD_ARGS
2 changes: 1 addition & 1 deletion share/templates.d/99-generic/config_files/common/profile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PS1="[anaconda \u@\h \W]\\$ "
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/sysimage/sbin:/mnt/sysimage/usr/sbin:/mnt/sysimage/bin:/mnt/sysimage/usr/bin
PATH=/usr/bin:/mnt/sysimage/usr/bin
export PATH PS1
2 changes: 1 addition & 1 deletion share/templates.d/99-generic/runtime-cleanup.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ removefrom shadow-utils --allbut /usr/bin/chage /usr/*bin/chpasswd \
/usr/*bin/groupadd /usr/*bin/useradd

## no services to turn on/off (keep the /etc/init.d link though)
removefrom initscripts /usr/sbin/* /usr/share/locale/* /usr/share/doc/* /usr/share/man/*
removefrom initscripts /usr/bin/* /usr/share/locale/* /usr/share/doc/* /usr/share/man/*

## no storage device monitoring
removepkg device-mapper-event
Expand Down
5 changes: 3 additions & 2 deletions src/sbin/livemedia-creator → src/bin/livemedia-creator
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ log = logging.getLogger("livemedia-creator")

import glob
import os
import shutil
import sys
import tempfile

Expand Down Expand Up @@ -91,7 +92,7 @@ def main():
errors.append("qemu needs to be installed.")

if is_install and opts.no_virt \
and not os.path.exists("/usr/sbin/anaconda"):
and not shutil.which("anaconda"):
errors.append("no-virt requires anaconda to be installed.")

if opts.make_appliance and not opts.app_template:
Expand Down Expand Up @@ -144,7 +145,7 @@ def main():
if opts.virt_uefi and not os.path.isdir(opts.fw_path):
errors.append("The UEFI firmware directory is missing: %s" % opts.fw_path)

if opts.domacboot and not os.path.exists("/usr/sbin/mkfs.hfsplus"):
if opts.domacboot and not shutil.which("mkfs.hfsplus"):
errors.append("mkfs.hfsplus is missing. Install hfsplus-tools, or pass --nomacboot")

if os.getuid() != 0:
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions src/pylorax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ def configure(self, conf_file="/etc/lorax/lorax.conf"):
if line and not line.startswith("#"):
self.output.ignore(line)

# cron does not have sbin in PATH,
# so we have to add it ourselves
os.environ["PATH"] = "{0}:/sbin:/usr/sbin".format(os.environ["PATH"])

# remove some environmental variables that can cause problems with package scripts
env_remove = ('DISPLAY', 'DBUS_SESSION_BUS_ADDRESS')
list(os.environ.pop(k) for k in env_remove if k in os.environ)
Expand Down
5 changes: 4 additions & 1 deletion src/pylorax/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,10 @@ def make_live_images(opts, work_dir, disk_img):
log.debug("sys_root = %s", sys_root)

# Make sure free blocks are actually zeroed so it will compress
rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", rootfs_img])
ext4path = shutil.which("fsck.ext4")
if not ext4path:
raise RuntimeError("Cannot find fsck.ext4 executable in PATH")
rc = execWithRedirect(ext4path, ["-y", "-f", "-E", "discard", rootfs_img])
if rc != 0:
log.error("Problem zeroing free blocks of %s", disk_img)
return None
Expand Down
2 changes: 1 addition & 1 deletion src/pylorax/ltmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def removefrom(self, pkg, *globs):
Examples:
removefrom usbutils /usr/bin/*
removefrom xfsprogs --allbut /sbin/*
removefrom xfsprogs --allbut /bin/*
'''
cmd = "%s %s" % (pkg, " ".join(globs)) # save for later logging
keepmatches = False
Expand Down
8 changes: 3 additions & 5 deletions src/pylorax/treebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from shutil import copytree, copy2
from subprocess import CalledProcessError
from pathlib import Path
import itertools
import libdnf5 as dnf5
from libdnf5.common import QueryCmp_EQ as EQ

Expand Down Expand Up @@ -183,13 +182,12 @@ def verify(self):

ELF_MAGIC = b'\x7fELF'

# Iterate over all files in /usr/bin and /usr/sbin
# Iterate over all files in /usr/bin
# NOTE: Fedora 42 has merged these into the same directory
# For ELF files, gather them into a list and we'll check them all at
# the end. For files with a #!, check them as we go
elf_files = []
usr_bin = Path(self.vars.root + '/usr/bin')
usr_sbin = Path(self.vars.root + '/usr/sbin')
for path in (str(x) for x in itertools.chain(usr_bin.iterdir(), usr_sbin.iterdir()) \
for path in (str(x) for x in Path(self.vars.root + '/usr/bin').iterdir() \
if x.is_file()):
with open(path, "rb") as f:
magic = f.read(4)
Expand Down
2 changes: 1 addition & 1 deletion tests/lorax/test_build_bootiso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -e
. /usr/share/beakerlib/beakerlib.sh
. "$(dirname $0)/lib/lib.sh"

CLI="${CLI:-./src/sbin/lorax}"
CLI="${CLI:-./src/bin/lorax}"

# Make up a name (slightly unsafe), should not exist before running lorax so use -u
rlJournalStart
Expand Down
2 changes: 1 addition & 1 deletion tests/mkksiso/test_boot_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
[ "$(id -u)" -eq 0 ] || (echo "$0 must be run as root"; exit 1)

. /usr/share/beakerlib/beakerlib.sh
CLI="${CLI:-./src/sbin/mkksiso}"
CLI="${CLI:-./src/bin/mkksiso}"

rlJournalStart
rlPhaseStartSetup "Setup repo with fake rpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/mkksiso/test_liveimg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
[ "$(id -u)" -eq 0 ] || (echo "$0 must be run as root"; exit 1)

. /usr/share/beakerlib/beakerlib.sh
CLI="${CLI:-./src/sbin/mkksiso}"
CLI="${CLI:-./src/bin/mkksiso}"

rlJournalStart
rlPhaseStartSetup "Setup a fake root image"
Expand Down
2 changes: 1 addition & 1 deletion tests/pylorax/test_imgutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def mkfakerootdir(rootdir):
Use this for testing the mk* functions that compress a directory tree
"""
dirs = ["/root", "/usr/sbin/", "/usr/local/", "/home/bart", "/etc/"]
dirs = ["/root", "/usr/bin/", "/usr/local/", "/home/bart", "/etc/"]
files = ["/etc/passwd", "/home/bart/.bashrc", "/root/.bashrc"]
for d in dirs:
os.makedirs(joinpaths(rootdir, d))
Expand Down

0 comments on commit 267178e

Please sign in to comment.