[vdr] 03/21: Make sure we can update from old plugin versions and merge config changes from the previous version to the new conf.d/conf.avaul configs
Tobias Grimm
tiber-guest at moszumanska.debian.org
Wed Mar 25 00:19:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
tiber-guest pushed a commit to branch e-tobi
in repository vdr.
commit 2001301a78d3d5dc27b0a13e2b3980c8493d95aa
Author: etobi <git at e-tobi.net>
Date: Sun Mar 22 11:50:04 2015 +0100
Make sure we can update from old plugin versions and merge config changes from the previous version to the new conf.d/conf.avaul configs
---
debian/dh-addon-vdrplugin/dh_vdrplugin_enable | 9 ++-
debian/dh-addon-vdrplugin/dh_vdrplugin_migrate | 92 ++++++++++++++++++++++
debian/dh-addon-vdrplugin/postinst-vdrplugin | 12 ---
.../dh-addon-vdrplugin/postinst-vdrplugin-enable | 22 ++++++
.../dh-addon-vdrplugin/postinst-vdrplugin-migrate | 56 +++++++++++++
debian/dh-addon-vdrplugin/postrm-vdrplugin | 12 ---
debian/dh-addon-vdrplugin/postrm-vdrplugin-enable | 29 +++++++
debian/dh-addon-vdrplugin/postrm-vdrplugin-migrate | 29 +++++++
debian/dh-addon-vdrplugin/preinst-vdrplugin-enable | 22 ++++++
.../dh-addon-vdrplugin/preinst-vdrplugin-migrate | 22 ++++++
debian/dh-addon-vdrplugin/vdrplugin.pm | 2 +
debian/vdr-dev.install | 6 +-
12 files changed, 284 insertions(+), 29 deletions(-)
diff --git a/debian/dh-addon-vdrplugin/dh_vdrplugin_enable b/debian/dh-addon-vdrplugin/dh_vdrplugin_enable
index a250f3d..bb1d6e8 100755
--- a/debian/dh-addon-vdrplugin/dh_vdrplugin_enable
+++ b/debian/dh-addon-vdrplugin/dh_vdrplugin_enable
@@ -161,9 +161,12 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
# Now pass the configs to be symlinked to the postinst/postrm templates
#
my @enabled_configs = grep { looks_like_number($config_files{$_}) } (keys %config_files);
- my $configs = join(' ', map { (basename($_), $config_files{$_}) } (@enabled_configs));
- autoscript($package, "postinst", "postinst-vdrplugin", "s/#PLUGINCONFIGS#/$configs/");
- autoscript($package, "postrm", "postrm-vdrplugin", "s/#PLUGINCONFIGS#/$configs/");
+ if (@enabled_configs) {
+ my $configs = join(' ', map { (basename($_), $config_files{$_}) } (@enabled_configs));
+ autoscript($package, "preinst", "preinst-vdrplugin-enable", "s/#ENABLEDCONFIGS#/$configs/");
+ autoscript($package, "postinst", "postinst-vdrplugin-enable", "s/#ENABLEDCONFIGS#/$configs/");
+ autoscript($package, "postrm", "postrm-vdrplugin-enable", "s/#ENABLEDCONFIGS#/$configs/");
+ }
}
=head1 SEE ALSO
diff --git a/debian/dh-addon-vdrplugin/dh_vdrplugin_migrate b/debian/dh-addon-vdrplugin/dh_vdrplugin_migrate
new file mode 100755
index 0000000..fba6836
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/dh_vdrplugin_migrate
@@ -0,0 +1,92 @@
+#! /usr/bin/perl -w
+
+=head1 NAME
+
+dh_vdrplugin_migrate - migrates old config files to /etc/vdr/conf.avail
+
+=cut
+
+use strict;
+use Debian::Debhelper::Dh_Lib;
+use Scalar::Util qw(looks_like_number);
+
+=head1 SYNOPSIS
+
+B<dh_vdrplugin_migrate> [S<I<debhelper options>>]
+
+=head1 DESCRIPTION
+
+dh_vdrplugin_migrate is a debhelper program that is responsible for migrating
+the settings from the old config file /etc/vdr/plugins/plugin.*.conf to the
+new config file(s) in /etc/vdr/conf.avail.
+
+=head1 EXAMPLES
+
+dh_vdrplugin is usually called indirectly in a rules file via the dh command.
+
+ %:
+ dh --with vdrplugin $@
+
+It can also be called directly, prior to calling dh_gencontrol.
+
+=head1 CONFORMS TO
+
+Debian policy, version 3.8.1
+
+=cut
+
+init ();
+
+no locale;
+
+sub get_plugins_from_config {
+ my ($config_file) = @_;
+ my @plugins;
+ open(my $conf, '<', $config_file);
+ while(<$conf>) {
+ if ($_ =~ /^\[(.+)\]/) {
+ push(@plugins, $1);
+ }
+ }
+ close($conf);
+ return @plugins;
+}
+
+sub get_plugins_from_lib_dir {
+ my ($package_dir) = @_;
+ return map { $_ =~ /libvdr-(.+?)\./ && $1 } <$package_dir/usr/lib/vdr/plugins/libvdr-*.so.*>;
+}
+
+foreach my $package (@{$dh{DOPACKAGES}}) {
+ my $package_dir=tmpdir($package);
+
+ my @old_configs;
+ my @old_new_config_pairs;
+ foreach my $config_file (<$package_dir/etc/vdr/conf.avail/*.conf>) {
+ my @plugins = get_plugins_from_config($config_file);
+ foreach my $plugin (@plugins) {
+ push(@old_configs, "/etc/vdr/plugins/plugin.$plugin.conf");
+ push(@old_new_config_pairs, "/etc/vdr/plugins/plugin.$plugin.conf " . "/etc/vdr/conf.avail/" . basename($config_file));
+ }
+ }
+ if (@old_new_config_pairs) {
+ my $oldconfigs = join(' ', @old_configs);
+ autoscript($package, "preinst", "preinst-vdrplugin-migrate", "s|#PKGNAME#|$package|; s|#OLDCONFIGS#|$oldconfigs|");
+ autoscript($package, "postrm", "postrm-vdrplugin-migrate", "s|#OLDCONFIGS#|$oldconfigs|");
+
+ my $configs = join(' ', @old_new_config_pairs);
+ autoscript($package, "postinst", "postinst-vdrplugin-migrate", "s|#CONFIGS#|$configs|");
+ }
+}
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+This program is not a part of debhelper.
+
+=head1 AUTHOR
+
+Tobias Grimm <tobias.grimm at e-tobi.net>
+
+=cut
diff --git a/debian/dh-addon-vdrplugin/postinst-vdrplugin b/debian/dh-addon-vdrplugin/postinst-vdrplugin
deleted file mode 100644
index 84f8f30..0000000
--- a/debian/dh-addon-vdrplugin/postinst-vdrplugin
+++ /dev/null
@@ -1,12 +0,0 @@
-dh_vdrplugin_create_symlinks() {
- while [ $# -gt 1 ] ; do
- local config=$1
- local priority=$2
- shift 2
- ln -sr "/etc/vdr/conf.avail/$config" "/etc/vdr/conf.d/$priority-$config"
- done
-}
-
-if [ "$1" = configure -a -z "$2" ]; then
- dh_vdrplugin_create_symlinks #PLUGINCONFIGS#
-fi
diff --git a/debian/dh-addon-vdrplugin/postinst-vdrplugin-enable b/debian/dh-addon-vdrplugin/postinst-vdrplugin-enable
new file mode 100644
index 0000000..6b80a3b
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/postinst-vdrplugin-enable
@@ -0,0 +1,22 @@
+#
+# Automatically create symlink in /etc/vdr/conf.d to enable the VDR plugin
+# if the plugin was installed or upgraded from a version which did not
+# supported the conf.d mechanism.
+#
+dh_vdrplugin_create_symlinks() {
+ while [ $# -gt 1 ] ; do
+ local config=$1
+ local priority=$2
+ shift 2
+ if [ -e "/etc/vdr/conf.d/$priority-$config.dpkg-vdrplugin-enable" ] ; then
+ rm "/etc/vdr/conf.d/$priority-$config.dpkg-vdrplugin-enable"
+ if [ -e "/etc/vdr/conf.avail/$config" ] ; then
+ ln -sr "/etc/vdr/conf.avail/$config" "/etc/vdr/conf.d/$priority-$config"
+ fi
+ fi
+ done
+}
+
+if [ "$1" = configure ]; then
+ dh_vdrplugin_create_symlinks #ENABLEDCONFIGS#
+fi
diff --git a/debian/dh-addon-vdrplugin/postinst-vdrplugin-migrate b/debian/dh-addon-vdrplugin/postinst-vdrplugin-migrate
new file mode 100644
index 0000000..b8a9184
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/postinst-vdrplugin-migrate
@@ -0,0 +1,56 @@
+#
+# Update new config in /etc/vdr/conf.avail with the settings from the old config
+# /etc/vdr/plugins/plugin.*.conf.
+#
+dh_vdrplugin_migrate_config() {
+ perl -e '
+ use warnings;
+ use strict;
+
+ my ($originalConfig, $newConfig, $tmpConfig) = @ARGV;
+
+ open(my $originalConfigFile , "<" , $originalConfig);
+ open(my $newConfigFile , "<" , $newConfig);
+ open(my $modifiedConfigFile , ">" , "$tmpConfig");
+
+ my %options = ();
+ while(<$originalConfigFile>) {
+ if ( $_ =~ /^(\s*-.+?)[\s=]/ ) {
+ $options{$1}=$_;
+ }
+ }
+
+ while(<$newConfigFile>) {
+ my $line = $_;
+ while (my ($key, $value) = each(%options)) {
+ $line = $value if $line =~ /^$key/;
+ }
+ print $modifiedConfigFile $line;
+ }
+
+ close($originalConfigFile);
+ close($newConfigFile);
+ close($modifiedConfigFile);
+ ' $@
+}
+
+dh_vdrplugin_migrate_configs() {
+ while [ $# -gt 1 ] ; do
+ local oldconfig="$1"
+ local newconfig="$2"
+ shift 2
+ rm -f "$oldconfig.dpkg-remove"
+ if [ -e "$oldconfig.dpkg-migrate" ]; then
+ if [ -e "$newconfig" ] ; then
+ mv "$newconfig" "$newconfig.dpkg-dist"
+ dh_vdrplugin_migrate_config "$oldconfig.dpkg-migrate" "$newconfig.dpkg-dist" "$newconfig.tmp"
+ mv -f "$newconfig.tmp" "$newconfig"
+ fi
+ mv "$oldconfig.dpkg-migrate" "$oldconfig.dpkg-bak"
+ fi
+ done
+}
+
+if [ "$1" = configure ]; then
+ dh_vdrplugin_migrate_configs #CONFIGS#
+fi
diff --git a/debian/dh-addon-vdrplugin/postrm-vdrplugin b/debian/dh-addon-vdrplugin/postrm-vdrplugin
deleted file mode 100644
index fdb43fc..0000000
--- a/debian/dh-addon-vdrplugin/postrm-vdrplugin
+++ /dev/null
@@ -1,12 +0,0 @@
-dh_vdrplugin_delete_symlinks() {
- while [ $# -gt 1 ] ; do
- local config=$1
- local priority=$2
- shift 2
- rm -f "/etc/vdr/conf.d/$priority-$config"
- done
-}
-
-if [ "$1" = "remove" ] ; then
- dh_vdrplugin_delete_symlinks #PLUGINCONFIGS#
-fi
diff --git a/debian/dh-addon-vdrplugin/postrm-vdrplugin-enable b/debian/dh-addon-vdrplugin/postrm-vdrplugin-enable
new file mode 100644
index 0000000..ad4fdba
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/postrm-vdrplugin-enable
@@ -0,0 +1,29 @@
+#
+# Remove automatically created conf.d symlink of vdr plugin
+#
+dh_vdrplugin_delete_symlinks() {
+ while [ $# -gt 1 ] ; do
+ local config=$1
+ local priority=$2
+ shift 2
+ rm -f "/etc/vdr/conf.d/$priority-$config"
+ done
+}
+
+#
+# Remove any tag files which may have been created by preinst
+#
+dh_vdrplugin_cleanup() {
+ while [ $# -gt 1 ] ; do
+ local config=$1
+ local priority=$2
+ shift 2
+ rm -f "/etc/vdr/conf.d/$priority-$config.dpkg-vdrplugin-enable"
+ done
+}
+
+if [ "$1" = "remove" ] ; then
+ dh_vdrplugin_delete_symlinks #ENABLEDCONFIGS#
+fi
+
+dh_vdrplugin_cleanup #ENABLEDCONFIGS#
diff --git a/debian/dh-addon-vdrplugin/postrm-vdrplugin-migrate b/debian/dh-addon-vdrplugin/postrm-vdrplugin-migrate
new file mode 100644
index 0000000..2afd86d
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/postrm-vdrplugin-migrate
@@ -0,0 +1,29 @@
+dh_vdrplugin_restore_config() {
+ while [ $# -gt 0 ] ; do
+ local oldconfig="$1"
+ shift
+ if [ -e "$oldconfig.dpkg-remove" ] ; then
+ mv "$oldconfig.dpkg-remove" "$oldconfig"
+ fi
+ if [ -e "$oldconfig.dpkg-migrate" ] ; then
+ mv "$oldconfig.dpkg-migrate" "$oldconfig"
+ end
+ fi
+ done
+}
+
+dh_vdrplugin_cleanup_config_backups() {
+ while [ $# -gt 0 ] ; do
+ rm -f "$1.dpkg-bak"
+ shift
+ done
+}
+
+case "$1" in
+ abort-install|abort-upgrade)
+ dh_vdrplugin_restore_config #OLDCONFIGS#
+ ;;
+ purge)
+ dh_vdrplugin_cleanup_config_backups
+ ;;
+esac
diff --git a/debian/dh-addon-vdrplugin/preinst-vdrplugin-enable b/debian/dh-addon-vdrplugin/preinst-vdrplugin-enable
new file mode 100644
index 0000000..cae1fbc
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/preinst-vdrplugin-enable
@@ -0,0 +1,22 @@
+#
+# To enable a vdr plugin, its config must be symlinked to /etc/vdr/conf.d.
+# This must only be done when installing a plugin package or upgrading
+# from an old package, which does not support the conf.d mechanism.
+#
+# Before installing, we remember if the plugin-config in conf.avail
+# does not exist (because this is a new installation or an upgrade
+# from an old installation or the config was removed by the admin)
+# by creating a /etc/vdr/conf.d/*.dpkg-vdr-plugin-enable "tag"-file.
+#
+dh_vdrplugin_prepare_enable() {
+ while [ $# -gt 0 ] ; do
+ local config=$1
+ local priority=$2
+ shift 2
+ if [ ! -e "/etc/vdr/conf.avail/$config" ] ; then
+ touch "/etc/vdr/conf.d/$priority-$config.dpkg-vdrplugin-enable"
+ fi
+ done
+}
+
+dh_vdrplugin_prepare_enable #ENABLEDCONFIGS#
diff --git a/debian/dh-addon-vdrplugin/preinst-vdrplugin-migrate b/debian/dh-addon-vdrplugin/preinst-vdrplugin-migrate
new file mode 100644
index 0000000..c37548e
--- /dev/null
+++ b/debian/dh-addon-vdrplugin/preinst-vdrplugin-migrate
@@ -0,0 +1,22 @@
+dh_vdrplugin_prep_migrate_config() {
+ local pkgname="$1"
+ shift
+ while [ $# -gt 0 ] ; do
+ local oldconfig="$1"
+ shift
+ if [ -e "$oldconfig" ] ; then
+ local md5sum="$(md5sum $oldconfig | sed -e 's/ .*//')"
+ local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $pkgname | sed -n -e "\' $oldconfig ' { s/ obsolete$//; s/.* //; p }")"
+ if [ "$md5sum" = "$old_md5sum" ]; then
+ mv "$oldconfig" "$oldconfig.dpkg-remove"
+ else
+ mv "$oldconfig" "$oldconfig.dpkg-migrate"
+ fi
+ fi
+ done
+}
+
+case "$1" in
+ install|upgrade)
+ dh_vdrplugin_prep_migrate_config #PKGNAME# #OLDCONFIGS#
+esac
diff --git a/debian/dh-addon-vdrplugin/vdrplugin.pm b/debian/dh-addon-vdrplugin/vdrplugin.pm
index 0ad5f6d..c3a1d90 100644
--- a/debian/dh-addon-vdrplugin/vdrplugin.pm
+++ b/debian/dh-addon-vdrplugin/vdrplugin.pm
@@ -6,4 +6,6 @@ insert_after("dh_shlibdeps", "dh_vdrplugin_depends");
insert_after("dh_install", "dh_vdrplugin_enable");
+insert_after("dh_vdrplugin_enable", "dh_vdrplugin_migrate");
+
1
diff --git a/debian/vdr-dev.install b/debian/vdr-dev.install
index 1b83399..1d0ea39 100644
--- a/debian/vdr-dev.install
+++ b/debian/vdr-dev.install
@@ -7,7 +7,9 @@ debian/plugin-template/ usr/share/vdr-dev/
debian/abi-version usr/share/vdr-dev/
debian/dh-addon-vdrplugin/vdrplugin.pm usr/share/perl5/Debian/Debhelper/Sequence/
-debian/dh-addon-vdrplugin/postinst-vdrplugin usr/share/debhelper/autoscripts/
-debian/dh-addon-vdrplugin/postrm-vdrplugin usr/share/debhelper/autoscripts/
+debian/dh-addon-vdrplugin/preinst-vdrplugin* usr/share/debhelper/autoscripts/
+debian/dh-addon-vdrplugin/postinst-vdrplugin* usr/share/debhelper/autoscripts/
+debian/dh-addon-vdrplugin/postrm-vdrplugin* usr/share/debhelper/autoscripts/
debian/dh-addon-vdrplugin/dh_vdrplugin_depends usr/bin/
debian/dh-addon-vdrplugin/dh_vdrplugin_enable usr/bin/
+debian/dh-addon-vdrplugin/dh_vdrplugin_migrate usr/bin/
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vdr-dvb/vdr.git
More information about the pkg-vdr-dvb-changes
mailing list