debian package: provide a manpage built from README file and fix setting version and date in script

This commit is contained in:
Benjamin Renard 2024-07-17 11:36:09 +02:00
parent fb02ac9269
commit b61ab45ae1
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
2 changed files with 69 additions and 29 deletions

View file

@ -1,16 +1,21 @@
#!/bin/bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
QUIET_ARG=""
[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet"
set -e
QUIET_MODE=0
[[ "$1" == "--quiet" ]] && QUIET_MODE=1
# Enter source directory
cd "$( dirname "$0" )" || exit
CHECK_FILE="$( find "." -name 'check_*' ! -name '*~' -type f -executable | head -n 1 )"
PACKAGE_NAME="$( basename "$CHECK_FILE" | tr '_' '-' )"
if [[ -d dist ]]; then
echo "Clean previous build..."
rm -fr dist
fi
echo "Clean previous build..."
rm -fr dist
CHECK_FILE="$( find "." -maxdepth 1 -name 'check_*' ! -name '*~' -type f -executable | head -n 1 )"
PACKAGE_NAME="$( basename "$CHECK_FILE" | tr '_' '-' )"
echo "Detect version using git describe..."
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
@ -18,13 +23,46 @@ VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
echo "Create building environemt..."
BDIR="dist/$PACKAGE_NAME-$VERSION"
mkdir -p "$BDIR"
RSYNC_ARG=""
[[ -z "$QUIET_ARG" ]] && RSYNC_ARG="-v"
rsync -a "$RSYNC_ARG" debian/ "$BDIR/debian/"
RSYNC_ARGS=( )
[[ $QUIET_MODE -eq 0 ]] && RSYNC_ARGS+=( -v )
rsync -a "${RSYNC_ARGS[@]}" debian/ "$BDIR/debian/"
cp "$CHECK_FILE" "$BDIR/"
echo "Set VERSION=$VERSION in gitdch using sed..."
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$CHECK_FILE" )"
if [[ -e "README.md" ]]; then
echo "Build manpage from README.md file..."
MAN_TITLE=$( basename "$CHECK_FILE" )
MAN_MD_FILE="$BDIR/$( basename "$CHECK_FILE" ).1.md"
MAN_FILE="$BDIR/$( basename "$CHECK_FILE" ).1"
echo "# ${MAN_TITLE^^} 1" \
"$( git log --follow --format=%ad --date iso README.md | head -n 1 | awk '{print $1}')" \
"$PACKAGE_NAME" \
'"User Manuals"' > "$MAN_MD_FILE"
sed 1d README.md >> "$MAN_MD_FILE"
if ! which go-md2man > /dev/null; then
ARG_ARGS=()
[[ $QUIET_MODE -eq 0 ]] && ARG_ARGS+=( -qq )
apt update "${ARG_ARGS[@]}"
apt install -y "${ARG_ARGS[@]}" go-md2man
fi
go-md2man -in "$MAN_MD_FILE" -out "$MAN_FILE"
basename "$MAN_FILE" >> "$BDIR/debian/manpages"
grep -Eq '^Build-Depends: .*go-md2man' "$BDIR/debian/control" || \
sed -i 's/^Build-Depends: \(.*\)$/Build-Depends: \1, go-md2man/' "$BDIR/debian/control"
fi
if grep -Eq '^VERSION *=' "$BDIR/$( basename "$CHECK_FILE" )"; then
echo "Set VERSION=$VERSION in $( basename "$CHECK_FILE" ) using sed..."
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$CHECK_FILE" )"
elif grep -Eq '^# Version:' "$BDIR/$( basename "$CHECK_FILE" )"; then
echo "Set Version = $VERSION in $( basename "$CHECK_FILE" ) using sed..."
sed -i "s/^#\(\s*Version:\s*\).*$/#\1$VERSION/" "$BDIR/$( basename "$CHECK_FILE" )"
fi
if grep -Eq '^# Date:' "$BDIR/$( basename "$CHECK_FILE" )"; then
DATE="$( git log --follow --format=%ad --date iso "$CHECK_FILE" | head -n 1 )"
echo "Set Date = $DATE in $( basename "$CHECK_FILE" ) using sed..."
sed -i "s/^#\(\s*Date:\s*\).*$/#\1$DATE/" "$BDIR/$( basename "$CHECK_FILE" )"
fi
if [[ -z "$DEBIAN_CODENAME" ]]; then
echo "Retrieve debian codename using lsb_release..."
@ -35,7 +73,7 @@ fi
echo "Generate debian changelog using gitdch..."
GITDCH_ARGS=('--verbose')
[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning')
[[ $QUIET_MODE -eq 1 ]] && GITDCH_ARGS=('--warning')
if [[ -n "$MAINTAINER_NAME" ]]; then
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
@ -60,4 +98,5 @@ fi
echo "Build debian package..."
cd "$BDIR" || exit
[[ $QUIET_MODE -eq 0 ]] && export DH_VERBOSE=1
dpkg-buildpackage

View file

@ -20,7 +20,8 @@
# ~/.pgpass).
#
# Author: Benjamin Renard <brenard@easter-eggs.com>
# Date: Wed Jul 17 10:56:43 2024 +0200
# Version: dev
# Date: dev
# Source: https://gitea.zionetrix.net/bn8/check_pg_streaming_replication
# SPDX-License-Identifier: GPL-3.0-or-later
#