From 0343c6bbc4fa9a1c4ecea5d3faf25cb75af68bed Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Fri, 10 Nov 2017 21:30:41 -0500 Subject: [PATCH 1/6] open ports to browse smb browsing smb/samba shares requires having ports 1025 - 65535 open. this patch grabs the ip address from wlan0 and opens the ports when the source ip is within the local subnet. --- host-bin/startkodi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/host-bin/startkodi b/host-bin/startkodi index 1910a4896..1a7316611 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -14,5 +14,10 @@ By default, it will log into the primary user on the first chroot found. Options are directly passed to enter-chroot; run enter-chroot to list them." +# Forward ports needed to browse smb shares +if test -n "$(ip -4 -o addr show dev wlan0| awk '{split($4,a,"/");print a[1]}')"; then + iptables -I INPUT 1 -p udp --source $(ip -4 -o addr show dev wlan0| awk '{split($4,a,"/");print a[1]}')/255.255.255.0 --dport 1025:65535 -j ACCEPT +fi + exec sh -e "`dirname "\`readlink -f -- "$0"\`"`/enter-chroot" -t kodi "$@" "" \ exec croutonpowerd -i xinit /usr/bin/kodi --standalone From 1a5877c1772ece697c8dcf3552d5afe788e8d3cf Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Sun, 12 Nov 2017 12:45:07 -0500 Subject: [PATCH 2/6] use better command to get ip address switched from: ip -4 -o addr show dev wlan0| awk '{split($4,a,"/");print a[1]}' to: ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}' also used a variable to get line length down. --- host-bin/startkodi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/host-bin/startkodi b/host-bin/startkodi index 1a7316611..74208780f 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -15,8 +15,12 @@ By default, it will log into the primary user on the first chroot found. Options are directly passed to enter-chroot; run enter-chroot to list them." # Forward ports needed to browse smb shares -if test -n "$(ip -4 -o addr show dev wlan0| awk '{split($4,a,"/");print a[1]}')"; then - iptables -I INPUT 1 -p udp --source $(ip -4 -o addr show dev wlan0| awk '{split($4,a,"/");print a[1]}')/255.255.255.0 --dport 1025:65535 -j ACCEPT +MYIP=$(ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}') + +if test -n $MYIP; then + iptables -I INPUT 1 -p udp \ + --source $MYIP/255.255.255.0 \ + --dport 1025:65535 -j ACCEPT fi exec sh -e "`dirname "\`readlink -f -- "$0"\`"`/enter-chroot" -t kodi "$@" "" \ From 749acc0b82f30e0041f576eef291eeeb1a62ec22 Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Sun, 12 Nov 2017 12:56:21 -0500 Subject: [PATCH 3/6] change test to see if command succeeds removed the -n from the test to check whether it succeeds, rather than whether the return exists. --- host-bin/startkodi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host-bin/startkodi b/host-bin/startkodi index 74208780f..7d6c5f2f1 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -17,7 +17,7 @@ Options are directly passed to enter-chroot; run enter-chroot to list them." # Forward ports needed to browse smb shares MYIP=$(ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}') -if test -n $MYIP; then +if test $MYIP; then iptables -I INPUT 1 -p udp \ --source $MYIP/255.255.255.0 \ --dport 1025:65535 -j ACCEPT From a3c6eb8407d837ca99e129559f4b7424584d66ad Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Sun, 12 Nov 2017 13:29:48 -0500 Subject: [PATCH 4/6] improve syntax thanks @divx118 --- host-bin/startkodi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host-bin/startkodi b/host-bin/startkodi index 7d6c5f2f1..00382a45e 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -17,9 +17,9 @@ Options are directly passed to enter-chroot; run enter-chroot to list them." # Forward ports needed to browse smb shares MYIP=$(ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}') -if test $MYIP; then +if [ -n "$MYIP" ]; then iptables -I INPUT 1 -p udp \ - --source $MYIP/255.255.255.0 \ + --source "$MYIP"/255.255.255.0 \ --dport 1025:65535 -j ACCEPT fi From bbed58d5826735620fdb35a98b803e8f53bc7152 Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Sun, 12 Nov 2017 15:26:39 -0500 Subject: [PATCH 5/6] fixed indentation --- host-bin/startkodi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/host-bin/startkodi b/host-bin/startkodi index 00382a45e..65680b9f8 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -18,9 +18,9 @@ Options are directly passed to enter-chroot; run enter-chroot to list them." MYIP=$(ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}') if [ -n "$MYIP" ]; then - iptables -I INPUT 1 -p udp \ - --source "$MYIP"/255.255.255.0 \ - --dport 1025:65535 -j ACCEPT + iptables -I INPUT 1 -p udp \ + --source "$MYIP"/255.255.255.0 \ + --dport 1025:65535 -j ACCEPT fi exec sh -e "`dirname "\`readlink -f -- "$0"\`"`/enter-chroot" -t kodi "$@" "" \ From 9f676c1834c43e41070a9b1a10e4c428ab9cec89 Mon Sep 17 00:00:00 2001 From: Zach Guithues Date: Wed, 15 Nov 2017 13:45:22 -0500 Subject: [PATCH 6/6] Fixed spacing --- host-bin/startkodi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host-bin/startkodi b/host-bin/startkodi index 65680b9f8..89f47561a 100755 --- a/host-bin/startkodi +++ b/host-bin/startkodi @@ -15,7 +15,7 @@ By default, it will log into the primary user on the first chroot found. Options are directly passed to enter-chroot; run enter-chroot to list them." # Forward ports needed to browse smb shares -MYIP=$(ip route get 1 | awk -F 'src ' '{ split($2,a," ");print a[1];exit}') +MYIP="$(ip route get 1 | awk -F 'src ' '{ split($2,a," "); print a[1]; exit}')" if [ -n "$MYIP" ]; then iptables -I INPUT 1 -p udp \