public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Robin Roevens <robin.roevens@disroot.org>
To: development@lists.ipfire.org
Subject: [PATCH v3 3/5] zabbix_agentd: Better configfile handling during update
Date: Thu, 10 Feb 2022 00:26:29 +0100	[thread overview]
Message-ID: <20220209232631.14673-4-robin.roevens@disroot.org> (raw)
In-Reply-To: <20220209232631.14673-1-robin.roevens@disroot.org>

[-- Attachment #1: Type: text/plain, Size: 6261 bytes --]

- Install user changeable configfiles as .ipfirenew-files to allow
  user to merge their config with the new version.  (warnings
  will be displayed during update when manual review is required).
  If the configfiles are not yet present, the .ipfirenew-files will be
  renamed to the actual configfiles. And if an existing configfile
  does not differ from the new one, the .ipfirenew-file will be removed.
- Make sure .ipfirenew files and userparameter_pakfire.conf are not
  included in backup during uninstall to prevent newer versions
  from being overwritten by backup restore during install.
- Explicitly remove installed sudoers file as it is not removed by
  remove_files due to the renaming from .ipfirenew
- Added comment in userparameter_pakfire.conf not to modify the file
  as it will be overwritten on update

Signed-off-by: Robin Roevens <robin.roevens(a)disroot.org>
---
 config/rootfiles/packages/zabbix_agentd       |  4 +--
 .../zabbix_agentd/userparameter_pakfire.conf  |  7 +++++
 lfs/zabbix_agentd                             |  7 +++--
 src/paks/zabbix_agentd/install.sh             | 29 +++++++++++++++++++
 src/paks/zabbix_agentd/uninstall.sh           |  8 +++++
 5 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/config/rootfiles/packages/zabbix_agentd b/config/rootfiles/packages/zabbix_agentd
index d9bbc3ccf..6f7090fe7 100644
--- a/config/rootfiles/packages/zabbix_agentd
+++ b/config/rootfiles/packages/zabbix_agentd
@@ -1,9 +1,9 @@
 etc/logrotate.d/zabbix_agentd
 etc/rc.d/init.d/zabbix_agentd
-etc/sudoers.d/zabbix
+etc/sudoers.d/zabbix.ipfirenew
 etc/zabbix_agentd
 etc/zabbix_agentd/scripts
-etc/zabbix_agentd/zabbix_agentd.conf
+etc/zabbix_agentd/zabbix_agentd.conf.ipfirenew
 etc/zabbix_agentd/zabbix_agentd.d
 etc/zabbix_agentd/zabbix_agentd.d/userparameter_pakfire.conf
 usr/bin/zabbix_get
diff --git a/config/zabbix_agentd/userparameter_pakfire.conf b/config/zabbix_agentd/userparameter_pakfire.conf
index aa2e80f5c..09ddf61c9 100644
--- a/config/zabbix_agentd/userparameter_pakfire.conf
+++ b/config/zabbix_agentd/userparameter_pakfire.conf
@@ -1,2 +1,9 @@
+#
+# IPFire specific configuration file 
+#
+#
+# DO NOT MODIFY - Changes will be overwritten when zabbix_agentd addon is
+#                 updated.
+#
 ### Parameter for monitoring pakfire status
 UserParameter=pakfire.status,sudo /opt/pakfire/pakfire status
diff --git a/lfs/zabbix_agentd b/lfs/zabbix_agentd
index 28fe97b4f..dae59fe48 100644
--- a/lfs/zabbix_agentd
+++ b/lfs/zabbix_agentd
@@ -90,8 +90,11 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
 	-rmdir /etc/zabbix_agentd/zabbix_agentd.conf.d
 	-mkdir -pv /etc/zabbix_agentd/zabbix_agentd.d
 	-mkdir -pv /etc/zabbix_agentd/scripts
+	# Remove original config
+	@rm -f /etc/zabbix_agentd/zabbix_agentd.conf
+	# And replace with our own config
 	install -v -m 644 $(DIR_SRC)/config/zabbix_agentd/zabbix_agentd.conf \
-		/etc/zabbix_agentd/zabbix_agentd.conf
+		/etc/zabbix_agentd/zabbix_agentd.conf.ipfirenew
 	install -v -m 644 $(DIR_SRC)/config/zabbix_agentd/userparameter_pakfire.conf \
 		/etc/zabbix_agentd/zabbix_agentd.d/userparameter_pakfire.conf
 
@@ -111,7 +114,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
 
 	# Install sudoers include file
 	install -v -m 644 $(DIR_SRC)/config/zabbix_agentd/sudoers \
-		/etc/sudoers.d/zabbix
+		/etc/sudoers.d/zabbix.ipfirenew
 
 	# Install include file for backup
 	install -v -m 644 $(DIR_SRC)/config/backup/includes/zabbix_agentd \
diff --git a/src/paks/zabbix_agentd/install.sh b/src/paks/zabbix_agentd/install.sh
index cf435918d..4ef4b5be6 100644
--- a/src/paks/zabbix_agentd/install.sh
+++ b/src/paks/zabbix_agentd/install.sh
@@ -23,6 +23,23 @@
 #
 . /opt/pakfire/lib/functions.sh
 
+review_required=false
+
+function setup_configfile() {
+	# Puts configfile in place if it does not already exist or 
+	# remove the shipped version if it does not differ from existing file
+	configfile=$1
+
+	if [ ! -f $configfile ]; then
+		mv $configfile.ipfirenew $configfile
+    elif diff -q $configfile $configfile.ipfirenew >/dev/null; then
+		rm -f $configfile.ipfirenew
+	else
+		echo "WARNING: new $configfile saved as $configfile.ipfirenew for manual review"
+		review_required=true
+	fi
+}
+
 if ! getent group zabbix &>/dev/null; then
 	groupadd -g 118 zabbix
 fi
@@ -41,6 +58,18 @@ ln -sf ../init.d/zabbix_agentd /etc/rc.d/rc6.d/K02zabbix_agentd
 # Create additonal directories and set permissions
 [ -d /var/log/zabbix ] || ( mkdir -pv /var/log/zabbix && chown zabbix.zabbix /var/log/zabbix )
 [ -d /usr/lib/zabbix ] || ( mkdir -pv /usr/lib/zabbix && chown zabbix.zabbix /usr/lib/zabbix )
+[ -d /etc/zabbix_agentd/scripts ] || ( mkdir -pv /etc/zabbix_agentd/scripts && chown zabbix.zabbix /etc/zabbix_agentd/scripts )
 
 restore_backup ${NAME}
+
+# Put zabbix configfiles in place
+setup_configfile /etc/zabbix_agentd/zabbix_agentd.conf
+setup_configfile /etc/sudoers.d/zabbix
+
+if $review_required; then
+	echo "WARNING: New versions of some configfile(s) where provided as .ipfirenew-files."
+	echo "         They may need manual review in order to take advantage of new features"
+	echo "         or even to make this version of ${NAME} work."
+fi
+
 start_service --background ${NAME}
diff --git a/src/paks/zabbix_agentd/uninstall.sh b/src/paks/zabbix_agentd/uninstall.sh
index edff3b818..0770b40f1 100644
--- a/src/paks/zabbix_agentd/uninstall.sh
+++ b/src/paks/zabbix_agentd/uninstall.sh
@@ -23,8 +23,16 @@
 #
 . /opt/pakfire/lib/functions.sh
 stop_service ${NAME}
+
+# Remove .ipfirenew files in advance so they won't be included in backup
+rm -rfv /etc/zabbix_agentd/zabbix_agentd.conf.ipfirenew /etc/sudoers.d/zabbix.ipfirenew
+# Remove IPFire provided userparameter config files in advance
+rm -rfv /etc/zabbix_agentd/zabbix_agentd.d/userparameter_pakfire.conf
+
 make_backup ${NAME}
 remove_files
 
+# Remove sudoers file
+rm -rvf /etc/sudoers.d/zabbix
 # Remove init-scripts and symlinks
 rm -rfv /etc/rc.d/rc*.d/*zabbix_agentd
-- 
2.34.1


-- 
Dit bericht is gescanned op virussen en andere gevaarlijke
inhoud door MailScanner en lijkt schoon te zijn.


  parent reply	other threads:[~2022-02-09 23:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 23:26 [PATCH v3 0/5] zabbix_agentd: Update to v5.0.20 (LTS) and more Robin Roevens
2022-02-09 23:26 ` [PATCH v3 1/5] zabbix_agentd: Update to v5.0.20 (LTS) Robin Roevens
2022-02-15 13:22   ` Michael Tremer
2022-02-16 23:35     ` Robin Roevens
2022-02-20 18:10       ` Michael Tremer
2022-02-20 22:18         ` Robin Roevens
2022-02-21 11:41           ` Michael Tremer
2022-02-21 23:48             ` Robin Roevens
2022-03-01 14:02               ` Michael Tremer
2022-02-09 23:26 ` [PATCH v3 2/5] zabbix_agentd: Fix agent modules dir and few minor bugs Robin Roevens
2022-02-09 23:26 ` Robin Roevens [this message]
2022-02-09 23:26 ` [PATCH v3 4/5] zabbix_agentd: By default only listen on GREEN ip Robin Roevens
2022-02-09 23:26 ` [PATCH v3 5/5] zabbix_agentd: Add IPFire specific userparameters Robin Roevens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220209232631.14673-4-robin.roevens@disroot.org \
    --to=robin.roevens@disroot.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox