From c26326450b88a19b5ba035e4cb8e2d1486a54d5d Mon Sep 17 00:00:00 2001 From: Maeve Andrews Date: Thu, 26 Jan 2023 11:24:59 -0500 Subject: [PATCH] Add a --distro option to build-deb.py Add an optional --distro argument to build-deb.py, to specify the Debian version in the package name, which currently is "1". This option may prove useful when publishing packages to freedomofpress/apt-tools-prod, where packages from different distros with the same names but different contents are not accepted. --- install/linux/build-deb.py | 44 ++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/install/linux/build-deb.py b/install/linux/build-deb.py index 5d4303c..e28a6cf 100755 --- a/install/linux/build-deb.py +++ b/install/linux/build-deb.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- + +import argparse import inspect import os import shutil @@ -21,6 +23,22 @@ def run(cmd): def main(): + parser = argparse.ArgumentParser( + prog=sys.argv[0], + description="Dev script for building Dangerzone debs", + ) + # FIXME: The name of the distro is important, as it can help users who are upgrading + # from a distro version to another. If we *do* need to provide a name at some point, + # here's a suggestion on how we should tackle naming: + # + # https://github.com/freedomofpress/dangerzone/pull/322#issuecomment-1428665162 + parser.add_argument( + "--distro", + required=False, + help="The name of the Debian-based distro", + ) + args = parser.parse_args() + dist_path = os.path.join(root, "dist") deb_dist_path = os.path.join(root, "deb_dist") @@ -31,13 +49,31 @@ def main(): shutil.rmtree(deb_dist_path) print("* Building DEB package") - # This command also builds the Debian source package, and then creates the DEB - # package, meaning that we don't need to run `sdist_dsc` as well. - run(["python3", "setup.py", "--command-packages=stdeb.command", "bdist_deb"]) + # NOTE: This command first builds the Debian source package, and then creates the + # final DEB package. We could simply call `bdist_deb`, which performs `sdist_dsc` + # implicitly, but we wouldn't be able to pass the Debian version argument. Because + # we do this in a single invocation though, there's no performance cost. + if args.distro is None: + deb_ver_args = () + deb_ver = "1" + else: + deb_ver_args = ("--debian-version", args.distro) + deb_ver = args.distro + + run( + [ + "python3", + "setup.py", + "--command-packages=stdeb.command", + "sdist_dsc", + *deb_ver_args, + "bdist_deb", + ] + ) print("") print("* To install run:") - print("sudo dpkg -i deb_dist/dangerzone_{}-1_all.deb".format(version)) + print(f"sudo dpkg -i deb_dist/dangerzone_{version}-{deb_ver}_all.deb") if __name__ == "__main__":