From bb339ba519b1250b863999052fc43a6ae6e1934d Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sat, 7 Dec 2024 01:26:44 +0000 Subject: [PATCH] New script to build a package from the source (.rpm, .deb). --- Makefile.am | 2 +- docs/build-package.sh | 146 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 docs/build-package.sh diff --git a/Makefile.am b/Makefile.am index cc3f31e..e5ae3e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ bin_PROGRAMS = pv dist_doc_DATA = README.md docs/INSTALL docs/COPYING docs/NEWS.md docs/ACKNOWLEDGEMENTS.md docs/DEVELOPERS.md dist_man1_MANS = docs/pv.1 -EXTRA_DIST = docs/pv.1.md docs/benchmark.sh docs/test-on-vm-lab.sh +EXTRA_DIST = docs/pv.1.md docs/benchmark.sh docs/test-on-vm-lab.sh docs/build-package.sh pv_SOURCES = \ src/main/debug.c \ diff --git a/docs/build-package.sh b/docs/build-package.sh new file mode 100755 index 0000000..fca088d --- /dev/null +++ b/docs/build-package.sh @@ -0,0 +1,146 @@ +#!/bin/sh +# +# Usage: sh build-package.sh source-1.2.3.tar.gz +# +# Given a tar.gz, build a package for the current OS. +# +# Supports these packaging types: +# +# .deb (Debian, Ubuntu, etc) - requires dpkg-dev, debhelper +# .rpm (AlmaLinux, Rocky Linux, OpenSUSE etc) - requires rpmbuild +# +# If the MAINTAINER environment variable is set, this is used as a GPG key +# ID for package signing. +# +# The packages built with this script are not "official", in that they are +# not part of any Linux distribution and may not follow the distribution's +# policies. Use at your own risk. + +sourceArchive="$1" +test -n "${sourceArchive}" && test -f "${sourceArchive}" \ +|| { printf "%s: %s: %s\n" "${0##*/}" "${sourceArchive}" "source archive not found" 1>&2; exit 1; } + +packageName="pv" +packageSummary="Shell pipeline element to meter data passing through" +packageDescription="\ +pv (Pipe Viewer) can be inserted into any normal pipeline between two +processes to give a visual indication of how quickly data is passing +through, how long it has taken, how near to completion it is, and an +estimate of how long it will be until completion." +packageUrl="https://www.ivarch.com/programs/pv.shtml" +sourceUrl="https://www.ivarch.com/programs/sources/${packageName}-%{version}.tar.gz" +packageEmail="Andrew Wood " + +workDir="$(mktemp -d)" || exit 1 +trap 'rm -rf "${workDir}"' EXIT + +# Infer the version from the most recent NEWS entry. +version="$(tar xzf "${sourceArchive}" --wildcards -O '*/docs/NEWS.md' 2>/dev/null | awk '/^### [0-9]/{print $2}' | sed -n 1p)" + +if command -v rpmbuild >/dev/null 2>&1; then + # Build an RPM. + cat > "${workDir}"/spec </dev/null 2>&1; then + # Build a Debian package. + mkdir "${workDir}/build" "${workDir}/build/debian" "${workDir}/build/debian/source" + + tar xzf "${sourceArchive}" -C "${workDir}/build" --strip-components=1 + + printf "%s\n" "10" > "${workDir}/build/debian/compat" + touch "${workDir}/build/debian/copyright" + printf "%s\n" "3.0 (quilt)" > "${workDir}/build/debian/source/format" + + cat > "${workDir}/build/debian/rules" < "${workDir}/build/debian/control" <= 9) + +Package: ${packageName} +Architecture: any +Depends: \${misc:Depends} +Description: ${packageSummary} +$(printf "%s\n.\n" "${packageDescription}" | sed 's,^, ,') +EOF + + cat > "${workDir}/build/debian/changelog" <