|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Builds a Debian source package for Launchpad PPA upload. |
| 4 | +# The package ships pre-built native binaries for amd64 and arm64. |
| 5 | +# |
| 6 | +# Usage: ./scripts/build-source-package.sh <version> <distro> <gpg_key_id> [include_orig] |
| 7 | +# |
| 8 | +# The optional include_orig flag (true/false, default true) controls whether the |
| 9 | +# orig tarball is included in the upload (-sa) or omitted (-sd). Launchpad requires |
| 10 | +# the orig tarball to be identical across all uploads for the same upstream version, |
| 11 | +# so only the first distro upload should include it; subsequent distros should set |
| 12 | +# this to "false" so Launchpad reuses the tarball already on file. |
| 13 | +# |
| 14 | +# Example: ./scripts/build-source-package.sh 2.7.1 noble ABC123DEF456 true |
| 15 | +# ./scripts/build-source-package.sh 2.7.1 jammy ABC123DEF456 false |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +VERSION="${1:?Usage: build-source-package.sh <version> <distro> <gpg_key_id> [include_orig]}" |
| 20 | +DISTRO="${2:?Usage: build-source-package.sh <version> <distro> <gpg_key_id> [include_orig]}" |
| 21 | +GPG_KEY_ID="${3:?Usage: build-source-package.sh <version> <distro> <gpg_key_id> [include_orig]}" |
| 22 | +INCLUDE_ORIG="${4:-true}" |
| 23 | + |
| 24 | +PACKAGE_NAME="crip" |
| 25 | +SOURCE_DIR="${PACKAGE_NAME}-${VERSION}" |
| 26 | +ORIG_TARBALL="${PACKAGE_NAME}_${VERSION}.orig.tar.gz" |
| 27 | + |
| 28 | +echo "==> Building source package for ${PACKAGE_NAME} ${VERSION} (${DISTRO})" |
| 29 | + |
| 30 | +# Create source directory with pre-built binaries |
| 31 | +mkdir -p "${SOURCE_DIR}/binaries" |
| 32 | +cp binary/amd64/crip "${SOURCE_DIR}/binaries/crip-amd64" |
| 33 | +cp binary/aarch64/crip "${SOURCE_DIR}/binaries/crip-arm64" |
| 34 | + |
| 35 | +# Reuse existing orig tarball if present (all distros must share the same one for Launchpad) |
| 36 | +if [ ! -f "${ORIG_TARBALL}" ]; then |
| 37 | + echo "==> Creating orig tarball ${ORIG_TARBALL}" |
| 38 | + tar -czf "${ORIG_TARBALL}" "${SOURCE_DIR}" |
| 39 | +fi |
| 40 | + |
| 41 | +# Create debian packaging directory |
| 42 | +mkdir -p "${SOURCE_DIR}/debian/source" |
| 43 | + |
| 44 | +# debian/source/format |
| 45 | +echo "3.0 (quilt)" > "${SOURCE_DIR}/debian/source/format" |
| 46 | + |
| 47 | +# debian/compat |
| 48 | +echo "12" > "${SOURCE_DIR}/debian/compat" |
| 49 | + |
| 50 | +# debian/control |
| 51 | +cat > "${SOURCE_DIR}/debian/control" << 'EOF' |
| 52 | +Source: crip |
| 53 | +Section: utils |
| 54 | +Priority: optional |
| 55 | +Maintainer: Hakan Altindag <hakangoudberg@hotmail.com> |
| 56 | +Build-Depends: debhelper (>= 12) |
| 57 | +Standards-Version: 4.5.1 |
| 58 | +Homepage: https://github.com/Hakky54/certificate-ripper |
| 59 | +
|
| 60 | +Package: crip |
| 61 | +Architecture: amd64 arm64 |
| 62 | +Depends: ${misc:Depends} |
| 63 | +Description: CLI tool to extract server certificates |
| 64 | + Certificate Ripper is a CLI tool to extract server certificates from |
| 65 | + HTTPS, WSS, FTPS, IMAPS, and SMTPS servers. Extracted certificates |
| 66 | + can be printed in human-readable or PEM format, and exported to |
| 67 | + PKCS12, JKS, DER, or PEM files. |
| 68 | +EOF |
| 69 | + |
| 70 | +# debian/rules |
| 71 | +cat > "${SOURCE_DIR}/debian/rules" << 'RULES' |
| 72 | +#!/usr/bin/make -f |
| 73 | +%: |
| 74 | + dh $@ |
| 75 | +
|
| 76 | +override_dh_auto_build: |
| 77 | + # Nothing to build, we ship pre-compiled native binaries |
| 78 | +
|
| 79 | +override_dh_auto_install: |
| 80 | + install -D -m 755 binaries/crip-$(DEB_HOST_ARCH) debian/crip/usr/bin/crip |
| 81 | +
|
| 82 | +override_dh_strip: |
| 83 | + # Skip stripping, binary is a GraalVM native-image |
| 84 | +
|
| 85 | +override_dh_shlibdeps: |
| 86 | + # Skip shared library dependency detection |
| 87 | +RULES |
| 88 | +chmod 755 "${SOURCE_DIR}/debian/rules" |
| 89 | + |
| 90 | +# debian/changelog |
| 91 | +cat > "${SOURCE_DIR}/debian/changelog" << EOF |
| 92 | +crip (${VERSION}-1~${DISTRO}) ${DISTRO}; urgency=medium |
| 93 | +
|
| 94 | + * Release ${VERSION} |
| 95 | +
|
| 96 | + -- ${DEBFULLNAME} <${DEBEMAIL}> $(date -R) |
| 97 | +EOF |
| 98 | + |
| 99 | +# debian/copyright |
| 100 | +cat > "${SOURCE_DIR}/debian/copyright" << 'EOF' |
| 101 | +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ |
| 102 | +Upstream-Name: certificate-ripper |
| 103 | +Upstream-Contact: Hakan Altindag <hakangoudberg@hotmail.com> |
| 104 | +Source: https://github.com/Hakky54/certificate-ripper |
| 105 | +
|
| 106 | +Files: * |
| 107 | +Copyright: 2021 Thunderberry |
| 108 | +License: Apache-2.0 |
| 109 | +
|
| 110 | +License: Apache-2.0 |
| 111 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 112 | + you may not use this file except in compliance with the License. |
| 113 | + You may obtain a copy of the License at |
| 114 | + . |
| 115 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 116 | + . |
| 117 | + Unless required by applicable law or agreed to in writing, software |
| 118 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 119 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 120 | + See the License for the specific language governing permissions and |
| 121 | + limitations under the License. |
| 122 | +EOF |
| 123 | + |
| 124 | +# debian/source/lintian-overrides (pre-built native binaries have no source) |
| 125 | +cat > "${SOURCE_DIR}/debian/source/lintian-overrides" << 'EOF' |
| 126 | +crip source: source-is-missing [binaries/crip-amd64] |
| 127 | +crip source: source-is-missing [binaries/crip-arm64] |
| 128 | +EOF |
| 129 | + |
| 130 | +# Build the unsigned source package (-d skips build dependency checks since we ship pre-built binaries) |
| 131 | +# -sa includes the orig tarball (for the first distro upload) |
| 132 | +# -sd omits it (for subsequent distros, Launchpad reuses the one already uploaded) |
| 133 | +if [ "${INCLUDE_ORIG}" = "true" ]; then |
| 134 | + SA_FLAG="-sa" |
| 135 | +else |
| 136 | + SA_FLAG="-sd" |
| 137 | +fi |
| 138 | + |
| 139 | +cd "${SOURCE_DIR}" |
| 140 | +debuild -S ${SA_FLAG} -d -us -uc |
| 141 | +cd .. |
| 142 | + |
| 143 | +# Sign the source package (gpg-agent has the passphrase pre-cached from the workflow) |
| 144 | +debsign -k"${GPG_KEY_ID}" "${PACKAGE_NAME}_${VERSION}-1~${DISTRO}_source.changes" |
| 145 | + |
| 146 | +echo "==> Source package built successfully for ${DISTRO}" |
| 147 | + |
0 commit comments