check_backuppc/build.sh
2024-10-07 12:39:38 +02:00

76 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
QUIET_ARG=""
[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet"
# Enter source directory
cd "$( dirname "$0" )" || exit
mapfile -t FILES < <( awk '{print $1}' < "debian/install" )
[[ "${#FILES[@]}" -eq 0 ]] && echo "No file found in debian/install file!" && exit 1
PACKAGE_NAME="$( basename "$( head -n1 <<< "$FILES" )" | tr '_' '-' )"
echo "Clean previous build..."
rm -fr dist
echo "Detect version using git describe..."
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/"
cp "${FILES[@]}" "$BDIR/"
echo "Set version $VERSION in files..."
for FILE in "${FILES[@]}"; do
case "$( mimetype -b "$FILE" )" in
application/x-perl)
echo " - in $FILE (perl)"
sed -i "s/^my \$version *=.*$/my \$version = '$VERSION';/" "$BDIR/$( basename "$FILE" )"
;;
application/x-shellscript)
echo " - in $FILE (shellscript)"
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$FILE" )"
;;
esac
done
if [[ -z "$DEBIAN_CODENAME" ]]; then
echo "Retrieve debian codename using lsb_release..."
DEBIAN_CODENAME=$( lsb_release -c -s )
else
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
fi
echo "Generate debian changelog using gitdch..."
GITDCH_ARGS=('--verbose')
[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning')
if [[ -n "$MAINTAINER_NAME" ]]; then
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
fi
if [[ -n "$MAINTAINER_EMAIL" ]]; then
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
fi
gitdch \
--package-name "$PACKAGE_NAME" \
--version "${VERSION}" \
--code-name "$DEBIAN_CODENAME" \
--output "$BDIR"/debian/changelog \
--release-notes dist/release_notes.md \
"${GITDCH_ARGS[@]}"
if [[ -n "$MAINTAINER_NAME" ]] && [[ -n "$MAINTAINER_EMAIL" ]]; then
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" \
"$BDIR"/debian/control
fi
echo "Build debian package..."
cd "$BDIR" || exit
dpkg-buildpackage
# vim:set sw=4 ts=4 sts=4 ft=bash expandtab: