From ab9787b60471f84a4bb47bbf5a826cf3f90835b7 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 7 Oct 2024 12:39:38 +0200 Subject: [PATCH] Add Debian package building files --- .gitignore | 1 + build.sh | 76 ++++++++++++++++++++++++++++++++++++++++ check_backuppc | 2 +- check_backuppc_du | 2 +- check_backuppc_nb_bkp_v3 | 6 ++++ debian/compat | 1 + debian/control | 12 +++++++ debian/copyright | 20 +++++++++++ debian/install | 3 ++ debian/rules | 4 +++ debian/source/format | 1 + 11 files changed, 126 insertions(+), 2 deletions(-) create mode 100755 build.sh create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/install create mode 100755 debian/rules create mode 100644 debian/source/format diff --git a/.gitignore b/.gitignore index b25c15b..59a2343 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +/dist diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5f63f8b --- /dev/null +++ b/build.sh @@ -0,0 +1,76 @@ +#!/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: diff --git a/check_backuppc b/check_backuppc index 13c6808..3074eac 100755 --- a/check_backuppc +++ b/check_backuppc @@ -44,7 +44,7 @@ Getopt::Long::Configure('bundling'); use lib "/usr/share/backuppc/lib"; use BackupPC::Lib; -my $version = '1.1.3'; +my $version = 'dev'; my $warnDaysOld = 2; my $critDaysOld = 7; my $warnDaysInProgress = 0.5; diff --git a/check_backuppc_du b/check_backuppc_du index e753898..e4c9395 100755 --- a/check_backuppc_du +++ b/check_backuppc_du @@ -42,7 +42,7 @@ Getopt::Long::Configure('bundling'); use lib "/usr/share/backuppc/lib"; use BackupPC::Lib; -my $version = '1.0'; +my $version = 'dev'; # Default quota (GB) my $quota = 100; my $opt_V = 0; diff --git a/check_backuppc_nb_bkp_v3 b/check_backuppc_nb_bkp_v3 index bdb9df8..fdc674d 100755 --- a/check_backuppc_nb_bkp_v3 +++ b/check_backuppc_nb_bkp_v3 @@ -1,5 +1,11 @@ #!/bin/bash +VERSION=dev +if [[ "$1" == "-v" ]] || [[ "$1" == "--version" ]] || [[ "$1" == "version" ]]; then + echo "$( basename "$0" ) - $VERSION" + exit 0 +fi + [[ ! -d /var/lib/backuppc/pc ]] && echo "BackupPC directory not found (/var/lib/backuppc/pc)." && exit 1 if ! cd "/var/lib/backuppc/pc"; then echo "Failed to enter in BackupPC directory (/var/lib/backuppc/pc)." diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b4de394 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +11 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..472c52c --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: check-backuppc +Section: admin +Priority: optional +Maintainer: Easter-eggs +Build-Depends: debhelper (>> 11.0.0) +Standards-Version: 3.9.6 + +Package: check-backuppc +Architecture: all +Depends: ${misc:Depends}, backuppc, libmonitoring-plugin-perl +Description: Monitoring plugin to check BackupPC instance + This Icinga/Nagios check plugins permit to check BackupPC instance diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..88b3490 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,20 @@ +This package was written by Benjamin Renard . + +Copyright (C) 2013-2024 Easter-eggs + +check-backuppc is licensed under the GNU general public license, version 2. + +check-backuppc is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2, or (at your option) any later version. + +check-backuppc is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +check-backuppc; see the file COPYING. If not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +On Debian systems, a copy of the GNU General Public License is available in +/usr/share/common-licenses/GPL-2 as part of the base-files package. diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..215a9ab --- /dev/null +++ b/debian/install @@ -0,0 +1,3 @@ +check_backuppc usr/lib/nagios/plugins +check_backuppc_du usr/lib/nagios/plugins +check_backuppc_nb_bkp_v3 usr/bin diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..7451f59 --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +#export DH_VERBOSE=1 +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +1.0