# - work on device nodes
# - allow passing env vars
+def die(message, status=1):
+ assert status >= 1 and status < 128
+ sys.stderr.write(message + "\n")
+ sys.exit(status)
+
class OutputFormat(Enum):
raw_gpt = 1
raw_btrfs = 2
GPT_ROOT_NATIVE = GPT_ROOT_ARM_64
GPT_ROOT_NATIVE_VERITY = GPT_ROOT_ARM_64_VERITY
else:
- sys.stderr.write("Don't known the %s architecture.\n" % platform.machine())
- sys.exit(1)
+ die("Don't know the %s architecture." % platform.machine())
CLONE_NEWNS = 0x00020000
try:
passphrase_mode = os.stat('mkosi.passphrase').st_mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
if (passphrase_mode & stat.S_IRWXU > 0o600) or (passphrase_mode & (stat.S_IRWXG | stat.S_IRWXO) > 0):
- sys.stderr.write("Permissions of 'mkosi.passphrase' of '{}' are too open. When creating passphrase files please make sure to choose an access mode that restricts access to the owner only. Aborting.\n".format(oct(passphrase_mode)))
- sys.exit(1)
+ die("Permissions of 'mkosi.passphrase' of '{}' are too open. When creating passphrase files please make sure to choose an access mode that restricts access to the owner only. Aborting.\n".format(oct(passphrase_mode)))
args.passphrase = { 'type': 'file', 'content': 'mkosi.passphrase' }
args.release = r
if args.distribution is None:
- sys.stderr.write("Couldn't detect distribution.\n")
- sys.exit(1)
+ die("Couldn't detect distribution.")
if args.release is None:
if args.distribution == Distribution.fedora:
if args.bootable:
if args.distribution not in (Distribution.fedora, Distribution.arch, Distribution.debian):
- sys.stderr.write("Bootable images are currently supported only on Debian, Fedora and Arch Linux.\n")
- sys.exit(1)
+ die("Bootable images are currently supported only on Debian, Fedora and Arch Linux.")
if not args.output_format in (OutputFormat.raw_gpt, OutputFormat.raw_btrfs, OutputFormat.raw_squashfs):
- sys.stderr.write("Directory, subvolume and tar images cannot be booted.\n")
- sys.exit(1)
+ die("Directory, subvolume and tar images cannot be booted.")
if args.encrypt is not None:
if args.output_format not in (OutputFormat.raw_gpt, OutputFormat.raw_btrfs, OutputFormat.raw_squashfs):
- sys.stderr.write("Encryption is only supported for raw gpt, btrfs or squashfs images.\n")
- sys.exit(1)
+ die("Encryption is only supported for raw gpt, btrfs or squashfs images.")
if args.encrypt == "data" and args.output_format == OutputFormat.raw_btrfs:
- sys.stderr.write("'data' encryption mode not supported on btrfs, use 'all' instead.\n")
- sys.exit(1)
+ die("'data' encryption mode not supported on btrfs, use 'all' instead.")
if args.encrypt == "all" and args.verity:
- sys.stderr.write("'all' encryption mode may not be combined with Verity.\n")
- sys.exit(1)
+ die("'all' encryption mode may not be combined with Verity.")
if args.sign:
args.checksum = True
continue
if os.path.exists(f):
- sys.stderr.write("Output file " + f + " exists already. (Consider invocation with --force.)\n")
- sys.exit(1)
+ die("Output file " + f + " exists already. (Consider invocation with --force.)")
def yes_no(b):
return "yes" if b else "no"
def check_root():
if os.getuid() != 0:
- sys.stderr.write("Must be invoked as root.\n")
- sys.exit(1)
+ die("Must be invoked as root.")
def main():