Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rootlesskit #76

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions ypkg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def main():
"i.e. no prompt", action="store_true")
parser.add_argument("-D", "--output-dir", type=str,
help="Set the output directory for resulting files")
parser.add_argument("-r", "--rootless", nargs='?', type=str,
help="Set which rootless binary to use e.g. fakeroot, rootlesskit")
# Main file
parser.add_argument("filename", help="Path to the ypkg YAML file",
nargs='?')
Expand All @@ -47,22 +49,17 @@ def main():
print("")
parser.print_help()
sys.exit(1)
elif args.filename:
recipe = f"{args.filename}"

needFakeroot = True
if os.geteuid() == 0:
if "FAKED_MODE" not in os.environ:
needFakeroot = False
if args.rootless:
rootless_bin = f"{args.rootless} "
else:
rootless_bin = ""

args = " ".join(sys.argv[1:])
vargs = sys.argv[1:]
cargs = " ".join([x for x in vargs if x != "-f" and x != "--force"])
try:
subprocess.check_call("ypkg-install-deps {}".format(args), shell=True)
if needFakeroot:
sub = "fakeroot "
else:
sub = ""
subprocess.check_call("{}ypkg-build {}".format(sub, cargs), shell=True)
subprocess.check_call("ypkg-install-deps {}".format(recipe), shell=True)
subprocess.check_call("{}ypkg-build {}".format(rootless_bin, recipe), shell=True)
except Exception as e:
print(e)
sys.exit(1)
Expand Down
8 changes: 8 additions & 0 deletions ypkg2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def readlink(path):
return os.path.normpath(os.readlink(path))


def is_rootlessmode():
if "FAKED_MODE" in os.environ:
return True
if "ROOTLESSKIT_PARENT_EUID" in os.environ:
return True
return False


pkgconfig32_dep = re.compile("^pkgconfig32\((.*)\)$")
pkgconfig_dep = re.compile("^pkgconfig\((.*)\)$")

Expand Down
10 changes: 4 additions & 6 deletions ypkg2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

from . import console_ui
from . import is_rootlessmode
from . import remove_prefix
from .compressdoc import compress_info_pages, compress_man_pages
from .ypkgspec import YpkgSpec
Expand Down Expand Up @@ -49,7 +50,6 @@ def show_version():
"\nthe License, or (at your option) any later version.")
sys.exit(0)


def main():
parser = argparse.ArgumentParser(description="Ypkg Package Build Tool")
parser.add_argument("-n", "--no-colors", help="Disable color output",
Expand Down Expand Up @@ -93,18 +93,16 @@ def main():
sys.exit(1)

# Test who we are
if os.geteuid() == 0:
if "FAKED_MODE" not in os.environ:
console_ui.emit_warning("Warning", "ypkg-build should be run via "
"fakeroot, not as real root user")
if os.geteuid() == 0 and is_rootlessmode() is True:
console_ui.emit_warning("Warning", "ypkg-build should be run via "
"fakeroot, not as real root user")
else:
console_ui.emit_error("Fail", "ypkg-build must be run with fakeroot, "
"or as the root user (not recommended)")
sys.exit(1)

build_package(args.filename, outputDir)


def clean_build_dirs(context):
if os.path.exists(context.get_build_dir()):
try:
Expand Down
3 changes: 2 additions & 1 deletion ypkg2/ypkgcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

from . import console_ui
from . import is_rootlessmode

import pisi.config
import os
Expand Down Expand Up @@ -246,7 +247,7 @@ def __init__(self, spec, emul32=False, avx2=False):
self.avx2 = avx2
self.build = BuildConfig()
self.init_config()
if os.geteuid() == 0 and "FAKED_MODE" not in os.environ:
if is_rootlessmode() is False and os.geteuid() == 0:
self.is_root = True

def get_path(self):
Expand Down