diff --git a/packages/addons/service/net-snmp/changelog.txt b/packages/addons/service/net-snmp/changelog.txt
index d2e563e110..91643534b8 100644
--- a/packages/addons/service/net-snmp/changelog.txt
+++ b/packages/addons/service/net-snmp/changelog.txt
@@ -1,3 +1,6 @@
+101
+- make addon configurable
+
100
- Initial addon
- net-snmp 5.7.3
diff --git a/packages/addons/service/net-snmp/package.mk b/packages/addons/service/net-snmp/package.mk
index 4113518f28..74c74976da 100644
--- a/packages/addons/service/net-snmp/package.mk
+++ b/packages/addons/service/net-snmp/package.mk
@@ -18,12 +18,12 @@
PKG_NAME="net-snmp"
PKG_VERSION="5.7.3"
-PKG_REV="100"
+PKG_REV="101"
PKG_ARCH="any"
PKG_LICENSE="BSD"
PKG_SITE="http://www.net-snmp.org"
PKG_URL="http://sourceforge.net/projects/net-snmp/files/$PKG_NAME/$PKG_VERSION/$PKG_NAME-$PKG_VERSION.tar.gz"
-PKG_DEPENDS_TARGET="toolchain"
+PKG_DEPENDS_TARGET="toolchain libnl"
PKG_SECTION="service"
PKG_SHORTDESC="Simple Network Management Protocol utilities."
PKG_LONGDESC="Simple Network Management Protocol (SNMP) is a widely used protocol for monitoring the health and welfare of network equipment."
@@ -39,14 +39,22 @@ PKG_CONFIGURE_OPTS_TARGET="--with-defaults \
--disable-debugging \
--disable-deprecated \
--disable-snmptrapd-subagent \
- --disable-perl-cc-checks \
- --with-perl-modules=no \
- --enable-mini-agent \
+ --disable-scripts \
--enable-static=no \
--enable-shared=yes \
- --with-logfile=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID}/ \
- --with-persistent-directory=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID}/ \
- --disable-embedded-perl"
+ --enable-mini-agent \
+ --with-nl \
+ --with-logfile=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID} \
+ --with-persistent-directory=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID} \
+ --sysconfdir=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID} \
+ --prefix=/storage/.kodi/addons/${PKG_ADDON_ID} \
+ --exec-prefix=/storage/.kodi/addons/${PKG_ADDON_ID} \
+ --datarootdir=/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID}/share \
+ --bindir=/storage/.kodi/addons/${PKG_ADDON_ID}/bin \
+ --sbindir=/storage/.kodi/addons/${PKG_ADDON_ID}/bin \
+ --libdir=/storage/.kodi/addons/${PKG_ADDON_ID}/lib \
+ --disable-embedded-perl \
+ --with-sysroot=$SYSROOT_PREFIX"
make_target() {
make
@@ -57,8 +65,11 @@ makeinstall_target() {
}
addon() {
- mkdir -p $ADDON_BUILD/$PKG_ADDON_ID
- cp -r $PKG_BUILD/.$TARGET_NAME/usr/bin $PKG_BUILD/.$TARGET_NAME/usr/lib $PKG_BUILD/.$TARGET_NAME/usr/share $ADDON_BUILD/$PKG_ADDON_ID/
- cp $PKG_BUILD/.$TARGET_NAME/usr/sbin/snmpd $ADDON_BUILD/$PKG_ADDON_ID/bin/snmpd
+ mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/lib
+ cp -r $PKG_BUILD/.$TARGET_NAME/storage/.kodi/addons/${PKG_ADDON_ID}/bin $PKG_BUILD/.$TARGET_NAME/storage/.kodi/userdata/addon_data/${PKG_ADDON_ID}/share $ADDON_BUILD/$PKG_ADDON_ID/
+ #Do not copy symlinks
+ find $PKG_BUILD/.$TARGET_NAME/storage/.kodi/addons/${PKG_ADDON_ID}/lib/ -type f -name '*.so.*' -exec cp '{}' $ADDON_BUILD/$PKG_ADDON_ID/lib/ \;
+ #remove all but major version from so file
+ for f in $ADDON_BUILD/$PKG_ADDON_ID/lib/*.so.* ; do mv "$f" "${f%.*.*}" ; done
}
diff --git a/packages/addons/service/net-snmp/patches/net-snmp-0001-read_config.c.patch b/packages/addons/service/net-snmp/patches/net-snmp-0001-read_config.c.patch
new file mode 100644
index 0000000000..6f52ff5a1f
--- /dev/null
+++ b/packages/addons/service/net-snmp/patches/net-snmp-0001-read_config.c.patch
@@ -0,0 +1,11 @@
+--- a/snmplib/read_config.c 2014-12-08 14:23:22.000000000 -0600
++++ b/snmplib/read_config.c 2017-03-30 12:21:16.351042803 -0500
+@@ -1618,7 +1618,7 @@
+ * save a warning header to the top of the new file
+ */
+ snprintf(fileold, sizeof(fileold),
+- "%s%s# Please save normal configuration tokens for %s in SNMPCONFPATH/%s.conf.\n# Only \"createUser\" tokens should be placed here by %s administrators.\n%s",
++ "%s%s# Please save normal configuration tokens for %s in /storage/.kodi/userdata/addon_data/service.net-snmp/share/snmp/%s.conf.\n# Only \"createUser\" tokens should be placed here by %s administrators.\n%s",
+ "#\n# net-snmp (or ucd-snmp) persistent data file.\n#\n############################################################################\n# STOP STOP STOP STOP STOP STOP STOP STOP STOP \n",
+ "#\n# **** DO NOT EDIT THIS FILE ****\n#\n# STOP STOP STOP STOP STOP STOP STOP STOP STOP \n############################################################################\n#\n# DO NOT STORE CONFIGURATION ENTRIES HERE.\n",
+ type, type, type,
diff --git a/packages/addons/service/net-snmp/patches/net-snmp-0002-net-snmp-create-v3-user.in.patch b/packages/addons/service/net-snmp/patches/net-snmp-0002-net-snmp-create-v3-user.in.patch
new file mode 100644
index 0000000000..397341c400
--- /dev/null
+++ b/packages/addons/service/net-snmp/patches/net-snmp-0002-net-snmp-create-v3-user.in.patch
@@ -0,0 +1,15 @@
+--- a/net-snmp-create-v3-user.in 2014-12-08 14:23:22.000000000 -0600
++++ b/net-snmp-create-v3-user.in 2017-03-30 13:20:56.336794994 -0500
+@@ -28,10 +28,8 @@
+ NSC_SRCDIR="NET-SNMP-SOURCE-DIR"
+ fi
+
+-if @PSCMD@ | egrep ' snmpd *$' > /dev/null 2>&1 ; then
+- echo "Apparently at least one snmpd demon is already running."
+- echo "You must stop them in order to use this command."
+- exit 1
++if @PSCMD@ | egrep 'snmpd'> /dev/null 2>&1 ; then
++ systemctl stop service.net-snmp.service
+ fi
+
+ Aalgorithm="MD5"
diff --git a/packages/addons/service/net-snmp/source/bin/snmpd.start b/packages/addons/service/net-snmp/source/bin/snmpd.start
index 79c318bf53..52fa473e8d 100644
--- a/packages/addons/service/net-snmp/source/bin/snmpd.start
+++ b/packages/addons/service/net-snmp/source/bin/snmpd.start
@@ -24,4 +24,4 @@ ADDON_ID=service.net-snmp
ADDON_DIR="$HOME/.kodi/addons/$ADDON_ID"
ADDON_HOME="$HOME/.kodi/userdata/addon_data/$ADDON_ID"
-$ADDON_DIR/bin/snmpd -LS0-6d -c $ADDON_DIR/snmpd.conf -M /storage/.kodi/addons/service.net-snmp/share/snmp/mibs -p /var/run/snmpd.pid
+$ADDON_DIR/bin/snmpd -f -LS0-6d -c $ADDON_HOME/share/snmp/snmpd.conf -M $ADDON_DIR/share/snmp/mibs -p /var/run/snmpd.pid
diff --git a/packages/addons/service/net-snmp/source/default.py b/packages/addons/service/net-snmp/source/default.py
index 1a91d91ede..df1cdb88a3 100644
--- a/packages/addons/service/net-snmp/source/default.py
+++ b/packages/addons/service/net-snmp/source/default.py
@@ -15,3 +15,63 @@
# You should have received a copy of the GNU General Public License
# along with LibreELEC. If not, see .
################################################################################
+import xbmc
+import xbmcvfs
+import xbmcaddon
+from os import system
+
+
+class MyMonitor(xbmc.Monitor):
+ def __init__(self, *args, **kwargs):
+ xbmc.Monitor.__init__(self)
+
+ def onSettingsChanged(self):
+ writeconfig()
+
+
+# addon
+__addon__ = xbmcaddon.Addon(id='service.net-snmp')
+__addonpath__ = xbmc.translatePath(__addon__.getAddonInfo('path'))
+__addonhome__ = xbmc.translatePath(__addon__.getAddonInfo('profile'))
+if not xbmcvfs.exists(xbmc.translatePath(__addonhome__ + 'share/snmp/')):
+ xbmcvfs.mkdirs(xbmc.translatePath(__addonhome__ + 'share/snmp/'))
+config = xbmc.translatePath(__addonhome__ + 'share/snmp/snmpd.conf')
+persistent = xbmc.translatePath(__addonhome__ + 'snmpd.conf')
+
+
+def writeconfig():
+ system("systemctl stop service.net-snmp.service")
+ community = __addon__.getSetting("COMMUNITY")
+ location = __addon__.getSetting("LOCATION")
+ contact = __addon__.getSetting("CONTACT")
+ snmpversion = __addon__.getSetting("SNMPVERSION")
+
+ if xbmcvfs.exists(persistent):
+ xbmcvfs.delete(persistent)
+
+ file = xbmcvfs.File(config, 'w')
+ file.write('com2sec local default {}\n'.format(community))
+ file.write('group localgroup {} local\n'.format(snmpversion))
+ file.write('access localgroup "" any noauth exact all all none\n')
+ file.write('view all included .1 80\n')
+ file.write('syslocation {}\n'.format(location))
+ file.write('syscontact {}\n'.format(contact))
+ file.write('dontLogTCPWrappersConnects yes\n')
+ file.close()
+
+ if snmpversion == "v3":
+ snmppassword = __addon__.getSetting("SNMPPASSWORD")
+ snmpuser = __addon__.getSetting("SNMPUSER")
+ system("net-snmp-config --create-snmpv3-user -a {0} {1}".format(snmppassword,snmpuser))
+
+ system("systemctl start service.net-snmp.service")
+
+
+if not xbmcvfs.exists(config):
+ writeconfig()
+
+monitor = MyMonitor()
+while not monitor.abortRequested():
+ if monitor.waitForAbort():
+ break
+
diff --git a/packages/addons/service/net-snmp/source/resources/language/English/strings.xml b/packages/addons/service/net-snmp/source/resources/language/English/strings.xml
new file mode 100644
index 0000000000..1744d66685
--- /dev/null
+++ b/packages/addons/service/net-snmp/source/resources/language/English/strings.xml
@@ -0,0 +1,11 @@
+
+
+
+ General
+ Community
+ Location
+ Contact
+ SNMP Version
+ SNMP User
+ SNMP Password
+
diff --git a/packages/addons/service/net-snmp/source/resources/settings.xml b/packages/addons/service/net-snmp/source/resources/settings.xml
new file mode 100644
index 0000000000..a3f9505943
--- /dev/null
+++ b/packages/addons/service/net-snmp/source/resources/settings.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/addons/service/net-snmp/source/snmpd.conf b/packages/addons/service/net-snmp/source/snmpd.conf
deleted file mode 100644
index df025fa93a..0000000000
--- a/packages/addons/service/net-snmp/source/snmpd.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-com2sec local default libreelec
-group localgroup v2c local
-access localgroup "" any noauth exact all all none
-
-view all included .1 80
-
-syslocation HOME
-syscontact root@libreelec
-
-dontLogTCPWrappersConnects yes
diff --git a/packages/addons/service/net-snmp/source/system.d/service.net-snmp.service b/packages/addons/service/net-snmp/source/system.d/service.net-snmp.service
index bec1832670..b2da3b4845 100644
--- a/packages/addons/service/net-snmp/source/system.d/service.net-snmp.service
+++ b/packages/addons/service/net-snmp/source/system.d/service.net-snmp.service
@@ -4,9 +4,11 @@ After=network-online.target
Requires=network-online.target
[Service]
-Type=forking
+Type=notification
ExecStart=/bin/sh -c "exec sh /storage/.kodi/addons/service.net-snmp/bin/snmpd.start"
ExecStop=/bin/sh -c "exec sh /storage/.kodi/addons/service.net-snmp/bin/snmpd.stop"
+ExecReload=/bin/kill -HUP $MAINPID
+PIDFile=/var/run/snmpd.pid
[Install]
WantedBy=kodi.target