diff --git a/contrib/release/debian-packages.sh b/contrib/release/debian-packages.sh new file mode 100755 --- /dev/null +++ b/contrib/release/debian-packages.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash + +export LC_ALL=C + +set -euo pipefail + +DEFAULT_PPA="bitcoin-abc" +DPUT_CONFIG_FILE=~/".dput.cf" + +help_message() { + echo "Build and sign Debian packages and push to a PPA." + echo "Usage: $0 package_version signer" + echo + echo "Example usage: $0 0.21.2 \"Jason B. Cox \"" + echo + echo "package_version must be of the form: MAJOR.MINOR.REVISION[.OPTIONALPATCH]" + echo "OPTIONALPATCH may be necessary when source files have changed but the version revision has not, as the PPA will" + echo "reject source archives of the same name." + echo + echo "signer must be of the form: 'YOUR NAME '" + echo + echo "Note: This script will prompt you to sign with your PGP key." + echo + echo "-d, --dry-run Build and sign the packages, but do not push them to the PPA." + echo "-h, --help Display this help message." + echo "-p, --ppa PPA hostname. Defaults to: '${DEFAULT_PPA}'. If no config file exists at ${DPUT_CONFIG_FILE}" + echo " then one will be created using '${DEFAULT_PPA}'. Setting this option to a hostname other than" + echo " the default will require that you add the necessary settings to the config file." +} + +DRY_RUN="false" +NUM_EXPECTED_ARGUMENTS=2 +PPA="${DEFAULT_PPA}" + +# Parse command line arguments +while [[ $# -ne 0 ]]; do +case $1 in + -d|--dry-run) + DRY_RUN="true" + shift # shift past argument + ;; + -h|--help) + help_message + exit 0 + ;; + -p|--ppa) + PPA="$2" + shift # shift past argument + shift # shift past value + ;; + *) + if [ "$#" -le "${NUM_EXPECTED_ARGUMENTS}" ]; then + break + fi + echo "Unknown argument: $1" + help_message + exit 1 + ;; +esac +done + +# Check for dependencies +if ! command -v dput > /dev/null; then + echo "Error: 'dput' is not installed." + exit 10 +fi +if ! command -v debuild > /dev/null; then + echo "Error: 'debuild' is not installed." + exit 11 +fi + +if [ "$#" -ne "${NUM_EXPECTED_ARGUMENTS}" ]; then + echo "Error: Expects ${NUM_EXPECTED_ARGUMENTS} arguments" + echo + help_message + exit 20 +fi + +PACKAGE_VERSION="$1" +echo "Package version:" +echo "${PACKAGE_VERSION}" | grep -E "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?" || { + echo "Error: package_version is not formatted correctly" + echo + help_message + exit 20 +} + +SIGNER="$2" +echo "Signer:" +echo "${SIGNER}" | grep ".* <.*@.*>" || { + echo "Error: signer is not formatted correctly" + echo + help_message + exit 21 +} + +# Generate default dput config file if none exists +if [ ! -f ${DPUT_CONFIG_FILE} ]; then + echo "Info: No dput config file exists. Creating ${DPUT_CONFIG_FILE} now..." + cat > ${DPUT_CONFIG_FILE} < debian/changelog <