git: 7d8ac44c9024 - main - net-mgmt/librenms: Improve patching

From: Dan Langille <dvl_at_FreeBSD.org>
Date: Sun, 08 Oct 2023 18:41:04 UTC
The branch main has been updated by dvl:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7d8ac44c90242ecd1656ce0c5a5c68910afb712b

commit 7d8ac44c90242ecd1656ce0c5a5c68910afb712b
Author:     Dan Langille <dvl@FreeBSD.org>
AuthorDate: 2023-10-08 18:36:12 +0000
Commit:     Dan Langille <dvl@FreeBSD.org>
CommitDate: 2023-10-08 18:40:59 +0000

    net-mgmt/librenms: Improve patching
    
    Instead of patching to /usr/local, patch to %%LOCALBASE%%, then use
    SED to patch to ${LOCALBASE}
    
    Reported by:    osa
---
 net-mgmt/librenms/Makefile                         | 27 ++++++++++++----------
 .../files/patch-LibreNMS_Validations_System.php    |  2 +-
 .../librenms/files/patch-LibreNMS_____init____.py  |  2 +-
 net-mgmt/librenms/files/patch-LibreNMS_wrapper.py  |  2 +-
 net-mgmt/librenms/files/patch-snmp-scan.py         |  4 ++--
 5 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/net-mgmt/librenms/Makefile b/net-mgmt/librenms/Makefile
index 1b64004a9593..00627645df7a 100644
--- a/net-mgmt/librenms/Makefile
+++ b/net-mgmt/librenms/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	librenms
 PORTVERSION=	23.9.1
-PORTREVISION=	2
+PORTREVISION=	3
 PORTEPOCH=	1
 CATEGORIES=	net-mgmt
 MASTER_SITES=	LOCAL/dvl:vendor
@@ -150,17 +150,20 @@ _OTHER_DIRS=	database/seeders/config html/plugins html/js/lang \
 		vendor/symfony/string/Resources/bin
 
 post-patch:
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/LibreNMS/Validations/Php.php
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/LibreNMS/Util/Version.php
-	${REINPLACE_CMD}    's|%%PORTVERSION%%|${PORTVERSION}|g'              ${WRKSRC}/LibreNMS/Util/Version.php
-	${REINPLACE_CMD}    's|%%RELEASE_TIMESTAMP%%|${_RELEASE_TIMESTAMP}|g' ${WRKSRC}/LibreNMS/Util/Version.php
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/LibreNMS/Validations/System.php
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/includes/html/output/capture.inc.php
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/config.php.default
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/poller-wrapper.py
-	${REINPLACE_CMD}    's|%%LOCALBASE%%|${LOCALBASE}|g'                  ${WRKSRC}/dist/librenms-scheduler.cron
-	${REINPLACE_CMD}    's|%%WWWDIR%%|${WWWDIR}|g'                        ${WRKSRC}/dist/librenms-scheduler.cron
-	${REINPLACE_CMD}    's|%%USER%%|${WWWOWN}|g'                          ${WRKSRC}/dist/librenms-scheduler.cron
+	${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|g' \
+		${WRKSRC}/LibreNMS/__init__.py \
+		${WRKSRC}/LibreNMS/wrapper.py \
+		${WRKSRC}/LibreNMS/Util/Version.php \
+		${WRKSRC}/LibreNMS/Validations/Php.php \
+		${WRKSRC}/LibreNMS/Validations/System.php \
+		${WRKSRC}/config.php.default \
+		${WRKSRC}/includes/html/output/capture.inc.php \
+		${WRKSRC}/poller-wrapper.py \
+		${WRKSRC}/snmp-scan.py
+	${REINPLACE_CMD} 's|%%PORTVERSION%%|${PORTVERSION}|g'              ${WRKSRC}/LibreNMS/Util/Version.php
+	${REINPLACE_CMD} 's|%%RELEASE_TIMESTAMP%%|${_RELEASE_TIMESTAMP}|g' ${WRKSRC}/LibreNMS/Util/Version.php
+	${REINPLACE_CMD} 's|%%WWWDIR%%|${WWWDIR}|g'                        ${WRKSRC}/dist/librenms-scheduler.cron
+	${REINPLACE_CMD} 's|%%USER%%|${WWWOWN}|g'                          ${WRKSRC}/dist/librenms-scheduler.cron
 	${RM} ${WRKSRC}/LibreNMS/Validations/Updates.php
 	${RM} -rf ${WRKSRC}/logs
 
diff --git a/net-mgmt/librenms/files/patch-LibreNMS_Validations_System.php b/net-mgmt/librenms/files/patch-LibreNMS_Validations_System.php
index 744b3533df01..961ebfbeaaac 100644
--- a/net-mgmt/librenms/files/patch-LibreNMS_Validations_System.php
+++ b/net-mgmt/librenms/files/patch-LibreNMS_Validations_System.php
@@ -5,7 +5,7 @@
          $install_dir = $validator->getBaseDir();
  
 -        $lnms = str_replace('lnms:', '', rtrim(`whereis -b lnms 2>/dev/null`));
-+        $lnms = rtrim(`/usr/bin/find /usr/local/bin -name lnms`);
++        $lnms = rtrim(`/usr/bin/find %%LOCALBASE%%/bin -name lnms`);
          $path = rtrim(`echo "\$PATH"`);
  
          // if couldn't find lnms and we have PATH
diff --git a/net-mgmt/librenms/files/patch-LibreNMS_____init____.py b/net-mgmt/librenms/files/patch-LibreNMS_____init____.py
index a5a301d57649..a648688daae8 100644
--- a/net-mgmt/librenms/files/patch-LibreNMS_____init____.py
+++ b/net-mgmt/librenms/files/patch-LibreNMS_____init____.py
@@ -14,7 +14,7 @@
      if script.endswith(".php"):
          # save calling the sh process
 -        base = ("/usr/bin/env", "php")
-+        base = ("/usr/local/bin/php",)
++        base = ("%%LOCALBASE%%/bin/php",)
      else:
          base = ()
  
diff --git a/net-mgmt/librenms/files/patch-LibreNMS_wrapper.py b/net-mgmt/librenms/files/patch-LibreNMS_wrapper.py
index d0f9187b21cf..d37958f3ac0a 100644
--- a/net-mgmt/librenms/files/patch-LibreNMS_wrapper.py
+++ b/net-mgmt/librenms/files/patch-LibreNMS_wrapper.py
@@ -5,7 +5,7 @@
                      wrappers[wrapper_type]["executable"],
                  )
 -                command = "/usr/bin/env php {} -h {}".format(executable, device_id)
-+                command = "/usr/local/bin/php php {} -h {}".format(executable, device_id)
++                command = "%%LOCALBASE%%/bin/php php {} -h {}".format(executable, device_id)
                  if modules is not None and len(str(modules).strip()):
                      module_str = re.sub("\s", "", str(modules).strip())
                      command = command + " -m {}".format(module_str)
diff --git a/net-mgmt/librenms/files/patch-snmp-scan.py b/net-mgmt/librenms/files/patch-snmp-scan.py
index 8c8ad9ddfc03..35f95c508731 100644
--- a/net-mgmt/librenms/files/patch-snmp-scan.py
+++ b/net-mgmt/librenms/files/patch-snmp-scan.py
@@ -6,7 +6,7 @@
              arguments = [
 -                "/usr/bin/env",
 -                "lnms",
-+                "/usr/local/bin/lnms",
++                "%%LOCALBASE%%/bin/lnms",
                  "device:add",
                  "-g",
                  POLLER_GROUP,
@@ -15,7 +15,7 @@
      try:
          CONFIG = json.loads(
 -            check_output(["/usr/bin/env", "php", "config_to_json.php"]).decode()
-+            check_output(["/usr/local/bin/php", "config_to_json.php"]).decode()
++            check_output(["%%LOCALBASE%%/bin/php", "config_to_json.php"]).decode()
          )
      except CalledProcessError as e:
          parser.error(