Page 1 of 1

Patch for upnp syntax

Posted: Mon May 31, 2021 1:09 pm
by G8SEZ
Some time ago there was a patch added to PiStar that fixed up the syntax used for the upnpc daemon arguments, but it was reversed for some reason and never reappeared.

I've been using the following patched version for many months and it works reliably for me so here it is, if you want to put it into PiStar Andy please feel free. I don't make any claim of ownership, this is just following what the man page says :) It also uses the hostname so you can see which host has requested the route. Unified diff follows...

--- pistar-upnp.service.old 2021-05-31 13:39:35.689836298 +0100
+++ pistar-upnp.service 2021-05-31 13:55:05.741203221 +0100
@@ -17,6 +17,8 @@
KILL=/bin/kill
SLEEP=/bin/sleep
ipVar=`hostname -I | cut -d' ' -f1`
+DURATION=600
+DESC=`hostname | cut -d'.' -f1`

# Pre-flight checks...
test -x ${DAEMON_PATH}${DAEMON} || exit 1
@@ -28,37 +30,37 @@

case "$1" in
start)
-# $DAEMON -a $ipVar 22 22 TCP > /dev/null 2>&1 &
-# $DAEMON -a $ipVar 80 80 TCP > /dev/null 2>&1 &
-# $DAEMON -a $ipVar 10022 10022 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 20001 20001 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30001 30001 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30051 30051 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30061 30061 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30062 30062 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30063 30063 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 30064 30064 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 40000 40000 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 42000 42000 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 42001 42001 UDP > /dev/null 2>&1 &
- $DAEMON -a $ipVar 42010 42010 UDP > /dev/null 2>&1 &
+# $DAEMON -e $DESC -a $ipVar 22 22 TCP $DURATION > /dev/null 2>&1 &
+# $DAEMON -e $DESC -a $ipVar 80 80 TCP $DURATION > /dev/null 2>&1 &
+# $DAEMON -e $DESC -a $ipVar 10022 10022 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 20001 20001 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30001 30001 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30051 30051 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30061 30061 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30062 30062 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30063 30063 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 30064 30064 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 40000 40000 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 42000 42000 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 42001 42001 UDP $DURATION > /dev/null 2>&1 &
+ $DAEMON -e $DESC -a $ipVar 42010 42010 UDP $DURATION > /dev/null 2>&1 &
;;

stop)
- $DAEMON -d $ipVar 22 22 TCP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 80 80 TCP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 10022 10022 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 20001 20001 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30001 30001 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30051 30051 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30061 30061 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30062 30062 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30063 30063 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 30064 30064 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 40000 40000 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 42000 42000 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 42001 42001 UDP > /dev/null 2>&1 &
- $DAEMON -d $ipVar 42010 42010 UDP > /dev/null 2>&1 &
+ $DAEMON -d 22 TCP > /dev/null 2>&1 &
+ $DAEMON -d 80 TCP > /dev/null 2>&1 &
+ $DAEMON -d 10022 UDP > /dev/null 2>&1 &
+ $DAEMON -d 20001 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30001 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30051 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30061 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30062 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30063 UDP > /dev/null 2>&1 &
+ $DAEMON -d 30064 UDP > /dev/null 2>&1 &
+ $DAEMON -d 40000 UDP > /dev/null 2>&1 &
+ $DAEMON -d 42000 UDP > /dev/null 2>&1 &
+ $DAEMON -d 42001 UDP > /dev/null 2>&1 &
+ $DAEMON -d 42010 UDP > /dev/null 2>&1 &
;;

*)

Re: Patch for upnp syntax

Posted: Wed Jun 02, 2021 10:36 am
by MW0MWZ
Thanks Brian, I had a look at the history, and it looks like I reverted one change to pull another - loosing the updates.
Added those changes back in now.

Re: Patch for upnp syntax

Posted: Wed Jun 02, 2021 12:08 pm
by G8SEZ
Thanks Andy, I see you've made the variable names a bit more user friendly.

One question, are all the $ signs in the daemon commands needed, you seem to have included some of them in the variable definitions.

Re: Patch for upnp syntax

Posted: Wed Jun 02, 2021 4:03 pm
by AF6VN
G8SEZ wrote: Wed Jun 02, 2021 12:08 pm Thanks Andy, I see you've made the variable names a bit more user friendly.

One question, are all the $ signs in the daemon commands needed, you seem to have included some of them in the variable definitions.
If DAEMON is an environment variable, the $ tells the shell to expand the value.

Code: Select all

pi-star@pi-star-3b(ro):~$ echo DAEMON
DAEMON
pi-star@pi-star-3b(ro):~$ echo $DAEMON

pi-star@pi-star-3b(ro):~$ sudo echo DAEMON
DAEMON
pi-star@pi-star-3b(ro):~$ sudo echo $DAEMON

pi-star@pi-star-3b(ro):~$
On my system, there is no DAEMON environment variable publically accessible, so it translates to blank.

Re: Patch for upnp syntax

Posted: Wed Jun 02, 2021 4:15 pm
by G8SEZ
AF6VN wrote: Wed Jun 02, 2021 4:03 pm
G8SEZ wrote: Wed Jun 02, 2021 12:08 pm Thanks Andy, I see you've made the variable names a bit more user friendly.

One question, are all the $ signs in the daemon commands needed, you seem to have included some of them in the variable definitions.
If DAEMON is an environment variable, the $ tells the shell to expand the value.

Code: Select all

pi-star@pi-star-3b(ro):~$ echo DAEMON
DAEMON
pi-star@pi-star-3b(ro):~$ echo $DAEMON

pi-star@pi-star-3b(ro):~$ sudo echo DAEMON
DAEMON
pi-star@pi-star-3b(ro):~$ sudo echo $DAEMON

pi-star@pi-star-3b(ro):~$
On my system, there is no DAEMON environment variable publically accessible, so it translates to blank.
It's set at the top of the pistar-upnp.service file, what I meant is that where:

ipVar=$(hostname -I | cut -d' ' -f1)

then if you use $ipVar that becomes:

$$(hostname -I | cut -d' ' -f1)

which may confuse the shell trying to execute the instruction, $$ is the PID of the shell process.

Re: Patch for upnp syntax

Posted: Thu Jun 03, 2021 8:09 am
by MW0MWZ

Code: Select all

hostVar=$(hostname | cut -d'.' -f1)
is the same as

Code: Select all

hostVar=`hostname | cut -d'.' -f1`

Code: Select all

$hostVar
will not include the leading $

Personally I find it easier to read when using this format rather than the back-tick, so when I update scripts I mostly change them over, there will be some back-ticks around for a while, but they are going away slowly.

back-ticks are the older style, parenthesis are the newer way of doing the same thing, there are some benefits, slashes etc are handled better when they are used in the parenthesis method for example... as with most of linux/unix and the many scripting options at hand - there are many ways to skin the same cat :)

Re: Patch for upnp syntax

Posted: Thu Jun 03, 2021 11:12 am
by G8SEZ
OK Andy, I certainly am no expert in shell syntax but I thought it worth checking.

Re: Patch for upnp syntax

Posted: Fri Jun 04, 2021 4:07 pm
by MW0MWZ
G8SEZ wrote: Thu Jun 03, 2021 11:12 am OK Andy, I certainly am no expert in shell syntax but I thought it worth checking.
its *always* worth the ask, either you help me catch a mistake, or learn something new, either way its a good result :)