From 658bba67c018a0b51df08723cd4c3a57c2668d2e Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Thu, 14 Jan 2016 22:45:50 -0500 Subject: [PATCH] Introduce a scripts/ folder --- build-all.sh | 2 +- scripts/apt-compare-versions | 29 +++++++ scripts/bintray-upload-deb | 81 +++++++++++++++++++ buildorder.py => scripts/buildorder.py | 0 check-pie.sh => scripts/check-pie.sh | 0 .../check-versions.sh | 0 .../detect-hardlinks.sh | 0 list-packages.sh => scripts/list-packages.sh | 0 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100755 scripts/apt-compare-versions create mode 100755 scripts/bintray-upload-deb rename buildorder.py => scripts/buildorder.py (100%) rename check-pie.sh => scripts/check-pie.sh (100%) rename check-versions.sh => scripts/check-versions.sh (100%) rename detect-hardlinks.sh => scripts/detect-hardlinks.sh (100%) rename list-packages.sh => scripts/list-packages.sh (100%) diff --git a/build-all.sh b/build-all.sh index 942f6adda..e7cb32c2c 100755 --- a/build-all.sh +++ b/build-all.sh @@ -12,7 +12,7 @@ if [ -e $BUILDORDER_FILE ]; then else rm -Rf $HOME/termux /data/data $HOME/termux/_buildall mkdir -p $HOME/termux/_buildall - ./buildorder.py > $BUILDORDER_FILE + ./scripts/buildorder.py > $BUILDORDER_FILE fi if [ -e $BUILDSTATUS_FILE ]; then echo "Continuing build-all from: $BUILDSTATUS_FILE" diff --git a/scripts/apt-compare-versions b/scripts/apt-compare-versions new file mode 100755 index 000000000..b1225448f --- /dev/null +++ b/scripts/apt-compare-versions @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# apt-compare-versions: Simple script which takes two arguments and compares +# their version according to apt rules. This can be used to verify the ordering +# between two versions. +# +# Note that ~ (tilde) construct, which allows for beta and preview releases. +# A version with ~ is considered earlier than one without, so 1.6~beta1 is +# considered earlier than 1.6. If both versions contains ~ the version comparison +# is made first on the part preceding the tilde, then the part coming after, +# so 1.6~beta1 comes before 1.6~beta2. + +import apt_pkg, sys +apt_pkg.init_system() + +if len(sys.argv) != 3: + sys.exit('usage: apt-compare-versions ') + +version1 = sys.argv[1] +version2 = sys.argv[2] + +comparison_result = apt_pkg.version_compare(version1, version2) +if comparison_result > 0: + operator = ' > ' +elif comparison_result < 0: + operator = ' < ' +elif comparison_result == 0: + operator = ' == ' + +print(version1 + operator + version2) diff --git a/scripts/bintray-upload-deb b/scripts/bintray-upload-deb new file mode 100755 index 000000000..f50e8e791 --- /dev/null +++ b/scripts/bintray-upload-deb @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import argparse, os, re, sys, requests + +USERNAME = os.environ["BINTRAY_USERNAME"] +API_KEY = os.environ["BINTRAY_API_KEY"] +API_BASE = os.environ.get("BINTRAY_URL", "https://api.bintray.com/content") +ORGANIZATION = os.environ.get("BINTRAY_ORGANIZATION") +ALLOWED_ARCH = ["all", "arm", "i686", "aarch64", "x86_64"] + +VERSION_RE = re.compile("^\d+(\.\d+)+([^\-]+)?\-([\da-z]+)$") +VERIFY_FORMAT = """ +Does this look correct? +- Name: {a.name} +- Version: {a.version} +- Architecture: {a.architecture} +- Distribution: {a.distribution} +- Component: {a.component} +- BinTray Repo: {a.org}/{a.repo} + +(Please enter y/n): """ + + +def main(): + parser = argparse.ArgumentParser(description="Upload BinTray package.") + parser.add_argument("package") + parser.add_argument("--name", "-n") + parser.add_argument("--no-confirm", action='store_true', default=False) + parser.add_argument("--repo", "-r", default="main") + parser.add_argument("--org", "-o", default=ORGANIZATION) + parser.add_argument("--component", "-c", default="main") + parser.add_argument("--distribution", "-d", default="stable") + + args = parser.parse_args() + basename = os.path.basename(args.package) + + if not os.path.isfile(args.package): + raise ValueError("File {0} is not valid / does not exist.".format(args.package)) + + if not args.org: + raise ValueError("Organization is missing.") + + # Determine name, version and architecture from file name: + base, _ = os.path.splitext(basename) + name, version, arch = base.split("_") + if arch not in ALLOWED_ARCH: raise ValueError("Architecture {0} not discoverable".format(arch)) + if not VERSION_RE.match(version): raise ValueError("Version not discoverable ({0})".format(version)) + + args.architecture = arch + args.version = version + args.name = args.name or name + + url = "{url}/{a.org}/{a.repo}/{a.name}/{a.version}/pool/{a.component}" \ + "/{a.name[0]}/{basename}?publish=1".format( + url=API_BASE, a=args, basename=basename) + + if not args.no_confirm: + sys.stdout.write(VERIFY_FORMAT.format(a=args)) + if not sys.stdin.readline().rstrip() == "y": + print("\nNot submitting package.") + return + + print("Submitting package...") + + parameters = {"publish": "1"} + headers = { + "X-Bintray-Debian-Distribution": args.distribution, + "X-Bintray-Debian-Architecture": args.architecture, + "X-Bintray-Debian-Component": args.component + } + + with open(args.package, "rb") as package_fp: + response = requests.put(url, auth=(USERNAME, API_KEY), params=parameters, headers=headers, data=package_fp) + + if response.status_code != 201: + raise Exception("Failed to submit package: {0}\n{1}".format(response.status_code, response.text)) + + print("Submitted successfully.") + +if __name__ == "__main__": + main() diff --git a/buildorder.py b/scripts/buildorder.py similarity index 100% rename from buildorder.py rename to scripts/buildorder.py diff --git a/check-pie.sh b/scripts/check-pie.sh similarity index 100% rename from check-pie.sh rename to scripts/check-pie.sh diff --git a/check-versions.sh b/scripts/check-versions.sh similarity index 100% rename from check-versions.sh rename to scripts/check-versions.sh diff --git a/detect-hardlinks.sh b/scripts/detect-hardlinks.sh similarity index 100% rename from detect-hardlinks.sh rename to scripts/detect-hardlinks.sh diff --git a/list-packages.sh b/scripts/list-packages.sh similarity index 100% rename from list-packages.sh rename to scripts/list-packages.sh