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..e3b203d --- /dev/null +++ b/build.sh @@ -0,0 +1,179 @@ +#!/bin/bash +# vim: shiftwidth=4 tabstop=4 expandtab + +INSTALL_BUILD_DEPS=0 +INSTALL_BUILD_DEPS_ONLY=0 +PURGE_SOURCE_DIRECTORY=0 + +function usage() { + [ $# -gt 0 ] && echo -e "$*\n" > /dev/stderr + cat << EOF +Usage: $0 [-h|I|-O|-P|-x] + -h|--help Show this message + -I|--install-build-deps Install build dependencies before building package + -O|--install-build-deps-only Only install build dependencies + -P|--purge-sources-directory Purge debian package sources directory after building package + -x|--trace Enable bash tracing (set -x) +EOF + [ $# -gt 0 ] && exit 1 +} + +idx=1 +while [ $idx -le $# ]; do + OPT=${!idx} + case $OPT in + -h|--help) + usage + ;; + -I|--install-build-deps) + INSTALL_BUILD_DEPS=1 + ;; + -O|--install-build-deps-only) + INSTALL_BUILD_DEPS=1 + INSTALL_BUILD_DEPS_ONLY=1 + ;; + -P|--purge-sources-directory) + PURGE_SOURCE_DIRECTORY=1 + ;; + -x|--trace) + set -x + ;; + *) + usage "Unknown parameter '$OPT'" + esac + (( idx+=1 )) +done + +# Enter source directory +cd "$( dirname "$0" )" + +# Install build dependencies +if [ $INSTALL_BUILD_DEPS -eq 1 ]; then + apt-get update + apt-get install --no-install-recommends --yes devscripts equivs sed rsync git lsb-release \ + wget ca-certificates bash-completion +fi + +DEBIAN_RELEASE=$( lsb_release -r -s | sed 's/\..*$//' ) + +# Install build dependencies based on Debian release +if [ $INSTALL_BUILD_DEPS -eq 1 ]; then + # On Debian Stretch, install GitPython using pip because strect version of python3-git have bugs + if [ "$DEBIAN_RELEASE" -eq 9 ]; then + apt-get install --no-install-recommends --yes python3-pip + python3 -m pip install GitPython + else + apt-get install --no-install-recommends --yes python3-git + fi +fi + +# Install GPG key (if provided) +if [ -n "$GPG_KEY" ]; then + [ $INSTALL_BUILD_DEPS -eq 1 ] && apt-get install --no-install-recommends --yes gnupg2 + [ $INSTALL_BUILD_DEPS_ONLY -eq 0 ] && echo "$GPG_KEY" | base64 -d | gpg --import +fi + +# Stop here on install build deps only mode +[ $INSTALL_BUILD_DEPS_ONLY -eq 1 ] && exit 0 + +# Retrieve source package name +SOURCE_PACKAGE_NAME=$( grep -E ^Source: debian/control | sed 's/^Source: //' ) + +# Generate EE debian codename +DEBIAN_CODENAME=$( lsb_release -c -s ) +[ "$DEBIAN_RELEASE" -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee" + +# Clean previous build +rm -fr dist + +# Compute version using git describe +# Note : If no tag exist, git describe will fail: in this case, compute a 0.0 version with same +# format as git describe +VERSION="$( git describe --tags 2> /dev/null )" || \ + VERSION="0.0-$( git log --oneline | wc -l )-$( git describe --tags --always )" + +# Fix version format to match with Python specs +# See: https://peps.python.org/pep-0440/ +# shellcheck disable=SC2001 +VERSION=$( sed 's/[^0-9]*\([0-9][^-]*\)-\(.*\)/\1+\2/' <<< "$VERSION" ) + +# Compute debian package version by adding EE debian version suffix +DEB_VERSION_SUFFIX="~ee${DEBIAN_RELEASE}0+1" +DEB_VERSION="${VERSION}${DEB_VERSION_SUFFIX}" + +# Create dist directory +mkdir dist +DIST_DIR=dist/$SOURCE_PACKAGE_NAME-$DEB_VERSION +rsync -av \ + --exclude 'dist' \ + --exclude '.*' \ + --exclude 'build.sh' \ + --exclude 'setup.cfg' \ + ./ "$DIST_DIR/" + +# Set version in package files +mapfile -t FILES < <( awk '{print $1}' < "debian/install" ) +[[ "${#FILES[@]}" -eq 0 ]] && echo "No file found in debian/install file!" && exit 1 +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';/" "$DIST_DIR/$( basename "$FILE" )" + ;; + application/x-shellscript) + echo " - in $FILE (shellscript)" + sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$DIST_DIR/$( basename "$FILE" )" + ;; + esac +done + +# Check gitdch is installed +GITDCH=$(which gitdch) +set -e +if [ -z "$GITDCH" ]; then + TMP_GITDCH=$(mktemp -d) + echo "Temporary install gitdch in $TMP_GITDCH" + wget -O "$TMP_GITDCH"/gitdch https://gitea.zionetrix.net/bn8/gitdch/raw/master/gitdch + chmod +x "$TMP_GITDCH"/gitdch + GITDCH=$TMP_GITDCH/gitdch +else + TMP_GITDCH="" +fi + +# Compute gitdch extra args +GITDCH_EXTRA_ARGS=() +[ -n "$DEBFULLNAME" ] && GITDCH_EXTRA_ARGS+=( "--maintainer-name" "$DEBFULLNAME" ) +[ -n "$DEBEMAIL" ] && GITDCH_EXTRA_ARGS+=( "--maintainer-email" "$DEBEMAIL" ) + +if [ -e debian/changelog ]; then + LAST_MANUAL_COMMIT_ID=$( git log --oneline -n1 -- debian/changelog | awk '{print $1}' ) + GITDCH_EXTRA_ARGS+=( "--append" "--revision" "${LAST_MANUAL_COMMIT_ID}..HEAD" ) +fi + +# Generate debian changelog using generate_debian_changelog.py +$GITDCH \ + --package-name "$SOURCE_PACKAGE_NAME" \ + --version "${DEB_VERSION}" \ + --version-suffix "${DEB_VERSION_SUFFIX}" \ + --code-name "$DEBIAN_CODENAME" \ + --output "$DIST_DIR"/debian/changelog \ + --release-notes dist/release-notes.md \ + --clean-tags-regex '\-ee[0-9]{2,3}$' \ + --exclude "^CI: " \ + --exclude "\.gitlab-ci(\.yml)?" \ + --exclude "build(\.sh)?" \ + --exclude "README(\.md)?" \ + --exclude "^Merge branch " \ + --verbose "${GITDCH_EXTRA_ARGS[@]}" + +# Clean temporary gitdch installation +[ -n "$TMP_GITDCH" ] && rm -fr "$TMP_GITDCH" + +# Build debian package +BUILD_ARGS="" +[ -z "$GPG_KEY" ] && BUILD_ARGS="--no-sign" || echo "GPG key provide, enable package signing." +cd "$DIST_DIR"/ +if dpkg-buildpackage $BUILD_ARGS; then + # Handle PURGE_SOURCE_DIRECTORY option + [[ $PURGE_SOURCE_DIRECTORY -eq 0 ]] || rm -fr "../../$DIST_DIR" +fi 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..70e28e8 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..5ae0f12 --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: check-backuppc +Section: admin +Priority: optional +Maintainer: APT Easter-eggs - check-backuppc +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