# You can also contact me on http://blog.harvie.cz/
pkgname=gtk-gnutella-upnp
-pkgver=1.0
+pkgver=1.1
pkgrel=1
pkgdesc="Small wrapper to automatically enable upnp port-forwarding for gtk-gnutella (doesn't work with port randomizing)"
arch=('any')
url="http://gtk-gnutella.sourceforge.net/"
depends=(gtk-gnutella miniupnpc)
source=("gtk-gnutella-upnp.sh" "gtk-gnutella-upnp.desktop")
-md5sums=('943e64632715b699b23c149787ead1a3'
+md5sums=('a6c682400f582def99e99e0834d004d9'
'a80c6de2b89bd3f2d13dca3869c81c27')
build() {
#!/bin/bash
-upnpc="$(which upnpc)";
-gnet_port="$(grep listen_port ~/.gtk-gnutella/config_gnet | grep -o [0-9]* | head -n 1)";
-test "$gnet_port" -gt 1 || upnpc=true;
-"$upnpc" -r "$gnet_port" TCP "$gnet_port" TCP;
-"$upnpc" -r "$gnet_port" UDP "$gnet_port" UDP;
-echo -e '\n======================= GTK-GNUTELLA =======================\n'
-echo "listen_port=$gnet_port"
-gtk-gnutella $@;
-echo -e '\n===================== GTK-GNUTELLA-END =====================\n'
-"$upnpc" -d "$gnet_port" TCP "$gnet_port" UDP;
+gtk-gnutella-listen-port() {
+ grep listen_port ~/.gtk-gnutella/config_gnet | grep -o [0-9]* | head -n 1;
+}
+
+gtk-gnutella-upnpc() {
+ upnpc="$(which upnpc)";
+ test "$(echo $@ | grep -o [0-9]* | head -n 1)" -gt 1 || upnpc=true;
+ "$upnpc" $@ > ~/.gtk-gnutella/upnpc.log;
+}
+
+gtk-gnutella-upnp-daemon() {
+ sleep 1;
+ echo ======= gtk-gnutella-upnp-daemon started ========
+ while pgrep -x gtk-gnutella -u "$UID" >/dev/null; do
+ gnet_port="$(gtk-gnutella-listen-port)";
+ gtk-gnutella-upnpc -r "$gnet_port" TCP "$gnet_port" UDP;
+ sleep 60;
+ done;
+ echo Shutting down gtk-gnutella-upnp-daemon...
+ gnet_port="$(gtk-gnutella-listen-port)";
+ gtk-gnutella-upnpc -d "$gnet_port" TCP "$gnet_port" UDP;
+ echo ======= gtk-gnutella-upnp-daemon exited ========
+}
+
+gtk-gnutella-upnp-daemon &
+gtk-gnutella $@; echo;
+pkill -x sleep -P $!;
+wait $!;