Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Nov 2013 21:54:09 GMT
From:      Ryan Frederick <ryanrfrederick@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/184011: Patch for Preliminary pkgng Support in net-mgmt/nagios-check_ports
Message-ID:  <201311152154.rAFLs9NA099100@oldred.freebsd.org>
Resent-Message-ID: <201311152200.rAFM004t078005@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         184011
>Category:       ports
>Synopsis:       Patch for Preliminary pkgng Support in net-mgmt/nagios-check_ports
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 15 22:00:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Ryan Frederick
>Release:        10.0-BETA3
>Organization:
>Environment:
FreeBSD system.name 10.0-BETA3 FreeBSD 10.0-BETA3 #0 r257580: Sun Nov  3 19:43:01 UTC 2013     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Currently net-mgmt/nagios-check_ports doesn't include any support for the pkgng utilities and therefore doesn't work on FreeBSD >= 10. Attached is a patch to the port's directory tree that provides (somewhat dirty) support for the pkgng utilities on FreeBSD >= 10.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -ruN nagios-check_ports.old/Makefile nagios-check_ports/Makefile
--- nagios-check_ports.old/Makefile	2013-09-20 17:24:43.000000000 -0500
+++ nagios-check_ports/Makefile	2013-11-15 13:39:10.552788000 -0600
@@ -11,13 +11,15 @@
 MAINTAINER=	freebsd@troback.com
 COMMENT=	Nagios Plugin to monitor your FreeBSD Ports
 
-RUN_DEPENDS=	portaudit:${PORTSDIR}/ports-mgmt/portaudit
-
 NO_BUILD=	yes
-
 NO_STAGE=	yes
+
 .include <bsd.port.pre.mk>
 
+.if ${OSVERSION} < 1000000
+RUN_DEPENDS=	portaudit:${PORTSDIR}/ports-mgmt/portaudit
+.endif
+
 do-install:
 	@${MKDIR} ${PREFIX}/libexec/nagios
 	${INSTALL_SCRIPT} ${WRKSRC}/check_ports ${PREFIX}/libexec/nagios/
diff -ruN nagios-check_ports.old/files/patch-check_ports nagios-check_ports/files/patch-check_ports
--- nagios-check_ports.old/files/patch-check_ports	2012-07-14 09:29:18.000000000 -0500
+++ nagios-check_ports/files/patch-check_ports	2013-11-15 15:26:14.322618000 -0600
@@ -1,11 +1,12 @@
---- check_ports	2011-08-23 07:01:14.000000000 +0000
-+++ check_ports	2011-08-24 02:32:14.000000000 +0000
-@@ -30,20 +30,15 @@
+--- check_ports	2009-03-10 03:46:27.000000000 -0500
++++ check_ports	2013-11-15 15:12:09.554760492 -0600
+@@ -30,20 +30,16 @@
  #
  
  # please change locations appropriate
 -PORTAUDIT=/usr/local/sbin/portaudit
  PKG_VERSION=/usr/sbin/pkg_version
++PKG=/usr/sbin/pkg
  JEXEC=/usr/sbin/jexec
  JLS=/usr/sbin/jls
 -PORTDIR=/usr/ports
@@ -22,7 +23,15 @@
  VERSION=0.6.1
  DATE="10 Mar 2009"
  PROJECTURL=http://code.adminlife.net/check_ports
-@@ -68,7 +63,7 @@
+@@ -56,6 +52,7 @@
+ PORTSAGE=0
+ UPDATES=0
+ PKGVERSION_OPTS="-Ivl "\<""
++PKG_OPTS="version -Ivl "\<""
+ 
+ ###### functions ######
+ 
+@@ -68,7 +65,7 @@
  
  # print help msg and exit
  print_help() {
@@ -31,23 +40,119 @@
    printf "options:\n"
    printf "  -h\t\tshow this help message and exit.\n\n"
    printf "  -a\t\tshows if any updates are available.\n"
-@@ -82,7 +77,9 @@
+@@ -82,7 +79,12 @@
    printf "  \t\tHighly recommended before first run.\n\n"
    printf "  -u \t\trun check_ports in unprivileged mode.\n"
    printf "  \t\tMuch slower but more secure.\n\n"
 -  printf "  -v\t\tshow version number.\n"
 +  printf "  -v\t\tshow version number.\n\n"
 +  printf "  -I <path>\tPath to INDEX file.\n\n"
-+  printf "  -P <path>\tPath to portaudit.\n"
++  if [ ${RELEASE} -lt 10]
++  then
++    printf "  -P <path>\tPath to portaudit.\n"
++  fi
    exit 0
  }
  
-@@ -254,13 +251,13 @@
+@@ -128,6 +130,16 @@
+   fi
+ }
+ 
++# pkg accessible?
++check_pkg() {
++  if [ -x ${PKG} ]
++  then
++    return 0
++  else
++    return 1
++ fi
++}
++
+ # jexec accessible?
+ check_jexec() {
+   if [ -x ${JEXEC} ]
+@@ -172,21 +184,42 @@
+     printf "  OK:    Your operating system is FreeBSD, main release ${RELEASE}.\n"
+   fi
+ 
+-  check_portaudit
+-  if [ $? -eq 1 ]
++  if [ ${RELEASE} -lt 10 ]
+   then
+-    printf "  ERROR: portaudit not found!\n"
+-  else
+-    printf "  OK:    portaudit found at ${PORTAUDIT}\n"
+-  fi
++    check_portaudit
++    if [ $? -eq 1 ]
++    then
++      printf "  ERROR: portaudit not found!\n"
++    else
++      printf "  OK:    portaudit found at ${PORTAUDIT}\n"
++    fi
+ 
+-  check_pkg_version
+-  if [ $? -eq 1 ]
+-  then
+-    printf "  ERROR: pkg_version not found at ${PKG_VERSION}.\n"
+-    printf "         Update information will not be available!\n"
++    check_pkg_version
++    if [ $? -eq 1 ]
++    then
++      printf "  ERROR: pkg_version not found at ${PKG_VERSION}.\n"
++      printf "         Update information will not be available!\n"
++    else
++      printf "  OK:    pkg_version found at ${PKG_VERSION}\n"
++    fi
++
++    check_portaudit_db
++    PORTAUDIT_DB_DATE=$(${PORTAUDIT} -d | awk -F ": " '{print $2}')
++    if [ $? -eq 1 ]
++    then
++      printf "  ERROR: portaudit database too old (Last Update: ${PORTAUDIT_DB_DATE}) - update with portaudit -F\n"
++    else
++      printf "  OK:    portaudit database is up to date (Last Update: ${PORTAUDIT_DB_DATE}).\n"
++    fi
+   else
+-    printf "  OK:    pkg_version found at ${PKG_VERSION}\n"
++    check_pkg
++    if [ $? -eq 1 ]
++    then
++      printf "  ERROR: pkg not found at ${PKG}.\n"
++      printf "         Update and security information will not be available!\n"
++    else
++      printf "  OK:    pkg found at ${PKG}\n"
++    fi
+   fi
+ 
+   check_jexec
+@@ -197,15 +230,6 @@
+     printf "  OK:    jexec found at ${JEXEC}\n"
+   fi
+ 
+-  check_portaudit_db
+-  PORTAUDIT_DB_DATE=$(${PORTAUDIT} -d | awk -F ": " '{print $2}')
+-  if [ $? -eq 1 ]
+-  then
+-    printf "  ERROR: portaudit database too old (Last Update: ${PORTAUDIT_DB_DATE}) - update with portaudit -F\n"
+-  else
+-    printf "  OK:    portaudit database is up to date (Last Update: ${PORTAUDIT_DB_DATE}).\n"
+-  fi
+-
+   check_portindex
+   if [ $? -eq 1 ]
+   then
+@@ -254,24 +278,34 @@
    # count lines from portversion if asked
    if [ ${ANY_UPDATE} -eq 1 -o ${WARN_ON_ANY_UPDATE} -eq 1  ]
    then
 -    UPDATES=$(${PKG_VERSION} ${PKGVERSION_OPTS} | grep -c "needs updating" -)
-+    UPDATES=$(${PKG_VERSION} ${PKGVERSION_OPTS} ${PORTINDEX} | grep -c "needs updating")
++    if [ ${RELEASE} -lt 10 ]
++    then
++      UPDATES=$(${PKG_VERSION} ${PKGVERSION_OPTS} ${PORTINDEX} | grep -c "needs updating")
++    else
++      UPDATES=$(${PKG} ${PKG_OPTS} ${PORTINDEX} | grep -c "needs updating")
++    fi
    fi
    
    # count lines from find
@@ -58,12 +163,47 @@
    fi
  
    # count lines from portaudit
-@@ -291,13 +288,13 @@
+-  PROBLEMS=$(${PORTAUDIT} | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++  if [ ${RELEASE} -lt 10 ]
++  then
++    PROBLEMS=$(${PORTAUDIT} | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++  else
++    PROBLEMS=$(${PKG} audit | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++  fi
+ 
+   run_gen_state
+ }
+ 
+ # main function for use in jails
+ run_main_jail() {
+-  if [ ${UNPRIV_MODE} -eq 1 ]
++  if [ ${UNPRIV_MODE} -eq 1 -a ${RELEASE} -lt 10 ]
+   then
+     mkdir ${TMP_PATH} >/dev/null 2>&1
+     ls -1 ${JAIL_PATH}/var/db/pkg/ > ${TMP_PATH}/${JAIL} 2>/dev/null
+@@ -285,19 +319,29 @@
+       print_state "only root can execute jail checks - users should use -u mode" "3"
+     else
+       # count lines from portaudit
+-      PROBLEMS=$(${JEXEC} ${JID}  ${PORTAUDIT} | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++      if [ ${RELEASE} -lt 10 ]
++      then
++        PROBLEMS=$(${JEXEC} ${JID}  ${PORTAUDIT} | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++      else
++        PROBLEMS=$(${PKG} -j ${JID} audit | grep "problem(s) in your installed packages found." | awk '{ print $1 }')
++      fi
+     fi
+   fi
    # count lines from pkg_version if asked and set PKG_DBDIR
    if [ ${ANY_UPDATE} -eq 1 -o ${WARN_ON_ANY_UPDATE} -eq 1  ]
    then
 -    UPDATES=$(PKG_DBDIR=${JAIL_PATH}/var/db/pkg ${PKG_VERSION} ${PKGVERSION_OPTS} | grep -c "needs updating" -)
-+    UPDATES=$(PKG_DBDIR=${JAIL_PATH}/var/db/pkg ${PKG_VERSION} ${PKGVERSION_OPTS} ${JAIL_PATH}${PORTINDEX} | grep -c "needs updating")
++    if [ ${RELEASE} -lt 10 ]
++    then
++      UPDATES=$(PKG_DBDIR=${JAIL_PATH}/var/db/pkg ${PKG_VERSION} ${PKGVERSION_OPTS} ${JAIL_PATH}${PORTINDEX} | grep -c "needs updating")
++    else
++      UPDATES=$(${PKG} -j ${JID} ${PKG_OPTS} ${JAIL_PATH}${PORTINDEX} | grep -c "needs updating")
++    fi
    fi
  
    # count lines from find
@@ -74,7 +214,7 @@
    fi
  
    run_gen_state
-@@ -305,12 +302,14 @@
+@@ -305,12 +349,14 @@
  
  ###### main ######
  
@@ -91,7 +231,7 @@
      r) ;; # parameter -r is now obsolete, we don't use portversion anymore
      a) ANY_UPDATE=1;;
      w) WARN_ON_ANY_UPDATE=1;;
-@@ -321,6 +320,14 @@
+@@ -321,6 +367,14 @@
    esac
  done
  


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311152154.rAFLs9NA099100>