Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling run.sh to work with busybox 'ash' #19

Open
PhracturedBlue opened this issue Dec 30, 2020 · 3 comments
Open

Enabling run.sh to work with busybox 'ash' #19

PhracturedBlue opened this issue Dec 30, 2020 · 3 comments

Comments

@PhracturedBlue
Copy link

I am trying to use the run.sh script on Alpine linux (which uses busybox). I ran into 2 issues with the run.sh script:

  1. Busybox 'ash' does not have arrays like bash does
  2. Busybox tail does not support the --pid argument
  3. Busybox 'trap' does not properly handle 'EXIT' signals

I fixed (1) by manually splitting the $LAN_PARENT, and (2) by using 'docker wait'. I haven't found a good solution for (3) yet. using trap _cleanup EXIT INT TERM doesn't seem to work either. Even if I end up installing bash, the fix for (2) is still needed though.

diff --git a/run.sh b/run.sh
index a09bf3a..88c06f3 100755
--- a/run.sh
+++ b/run.sh
@@ -172,9 +172,10 @@ _prepare_network() {
 			LAN_IFACE=br-${LAN_ID:0:12}
 
 			# test if $LAN_PARENT is a VLAN of $WAN_PARENT, create it if it doesn't exist and add it to the bridge
-			local lan_array=(${LAN_PARENT//./ })
-			if [[ ${lan_array[0]} = $WAN_PARENT ]] && ! ip link show $LAN_PARENT >/dev/null 2>&1 ; then
-				sudo ip link add link ${lan_array[0]} name $LAN_PARENT type vlan id ${lan_array[1]}
+			local lan_parent_iface=$(echo $LAN_PARENT | cut -d. -f1)
+			local lan_parent_vlan=$(echo $LAN_PARENT | cut -d. -f2)
+			if [[ ${lan_parent_iface} = $WAN_PARENT ]] && ! ip link show $LAN_PARENT >/dev/null 2>&1 ; then
+				sudo ip link add link ${lan_parent_iface} name $LAN_PARENT type vlan id ${lan_parent_vlan}
 			fi
 			sudo ip link set $LAN_PARENT master $LAN_IFACE
 		;;
@@ -220,4 +221,4 @@ main() {
 
 main
 trap "_cleanup" EXIT
-tail --pid=$pid -f /dev/null
+docker wait $CONTAINER
@oofnikj
Copy link
Owner

oofnikj commented Jan 3, 2021

This is a great idea. I'll have to play with this when I get some time.

Is there no way you can install bash?
Perhaps we could use sed or awk to do some of the string manipulation instead of relying on arrays?

@PhracturedBlue
Copy link
Author

Yes, I could install bash, but I'm trying to keep the set of installed packages on the base image at an absolute minimum (just enough to run docker).
You only have a single bash array (that I've run into) today and the 'cut' method above seems to work to eliminate it.

@gaby
Copy link

gaby commented Oct 22, 2021

@PhracturedBlue Everytime I run into this issue, just installing bash fixes everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants