This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=aeee5b5ac27d19b6001d1ae912384ed7defa942c

commit aeee5b5ac27d19b6001d1ae912384ed7defa942c
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Apr 29 23:40:49 2023 +0200

    dpkg-db-keeper: Add helper script to assist with tracking database changes
    
    A simplified version of this script has been in constant use to assist
    in dpkg development for years now, so that changes performed to the db
    can be easily tracked and studied, when running dpkg versions from git.
    
    But it is also generally helpful for record tracking of what has changed
    over time in the system.
---
 debian/dpkg.install   |  1 +
 src/.gitignore        |  1 +
 src/Makefile.am       |  2 ++
 src/dpkg-db-keeper.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 t/shellcheck.t        |  1 +
 5 files changed, 64 insertions(+)

diff --git a/debian/dpkg.install b/debian/dpkg.install
index 5196e3967..907419f7b 100644
--- a/debian/dpkg.install
+++ b/debian/dpkg.install
@@ -15,6 +15,7 @@ usr/bin/dpkg-statoverride
 usr/bin/dpkg-trigger
 usr/bin/update-alternatives
 usr/lib/dpkg/dpkg-db-backup usr/libexec/dpkg/
+usr/lib/dpkg/dpkg-db-keeper usr/libexec/dpkg/
 usr/share/dpkg/*table
 usr/share/dpkg/sh/dpkg-error.sh
 usr/share/lintian/profiles
diff --git a/src/.gitignore b/src/.gitignore
index 9922e0170..3a122bf11 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,5 +1,6 @@
 dpkg
 dpkg-db-backup
+dpkg-db-keeper
 dpkg-deb
 dpkg-divert
 dpkg-maintscript-helper
diff --git a/src/Makefile.am b/src/Makefile.am
index 435816558..31d1a9e75 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,10 +39,12 @@ bin_SCRIPTS = \
 
 pkglibexec_SCRIPTS = \
        dpkg-db-backup \
+       dpkg-db-keeper \
        # EOL
 
 EXTRA_DIST += \
        dpkg-db-backup.sh \
+       dpkg-db-keeper.sh \
        dpkg-maintscript-helper.sh \
        dpkg-realpath.sh \
        # EOL
diff --git a/src/dpkg-db-keeper.sh b/src/dpkg-db-keeper.sh
new file mode 100755
index 000000000..8c99a4c20
--- /dev/null
+++ b/src/dpkg-db-keeper.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright © 2023 Guillem Jover <[email protected]>
+#
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+PROGNAME=$(basename "$0")
+ADMINDIR=/var/lib/dpkg
+
+PKGDATADIR_DEFAULT=src
+PKGDATADIR="${DPKG_DATADIR:-$PKGDATADIR_DEFAULT}"
+
+# shellcheck source=src/sh/dpkg-error.sh
+. "$PKGDATADIR/sh/dpkg-error.sh"
+
+setup_colors
+
+# This script is used to track any change in the dpkg database for later
+# inspection, either as a matter of record tracking or to aid in debugging
+# dpkg behavior. It can be installed as a post-invoke hook such as:
+#
+# ,--- /etc/dpkg/dpkg.cfg.d/db-keeper ---
+# post-invoke "/usr/libexec/dpkg-db-keeper"
+# `---
+
+if [ -n "$DPKG_ROOT" ]; then
+  # Only operate on the main system.
+  exit 0
+fi
+
+if ! command -v git >/dev/null; then
+  # Do nothing if there is no git.
+  exit 0
+fi
+
+: "${DPKG_ADMINDIR:=/var/lib/dpkg}"
+
+cd "$DPKG_ADMINDIR" || exit 0
+
+if [ ! -e .git ]; then
+  # Initialize the git repo.
+  git init
+fi
+
+git add -A
+git commit -m 'Commit dpkg db updates'
+
+exit 0
diff --git a/t/shellcheck.t b/t/shellcheck.t
index fdc6dcc9a..6429cb26e 100644
--- a/t/shellcheck.t
+++ b/t/shellcheck.t
@@ -38,6 +38,7 @@ my @files = qw(
     debian/dpkg.cron.daily
     debian/dpkg.postrm
     src/dpkg-db-backup.sh
+    src/dpkg-db-keeper.sh
     src/dpkg-maintscript-helper.sh
     src/dpkg-realpath.sh
 );

-- 
Dpkg.Org's dpkg

Reply via email to