diff --git a/otgether/otgEther.sh b/otgether/otgEther.sh index 483028f..b20a554 100644 --- a/otgether/otgEther.sh +++ b/otgether/otgEther.sh @@ -46,5 +46,22 @@ then done fi -# Add the static IP to /etc/dhcpcd.conf -echo -e "interface usb0 \nstatic ip_address=$1" | tee -a /etc/dhcpcd.conf +# Add the static IP to /etc/dhcpcd.conf, if one is set +# This is optional because on Windows in case there is +# a DHCP on the other end +if [ ! -z "$1" ] +then + echo -e "interface usb0 \nstatic ip_address=$1" | tee -a /etc/dhcpcd.conf + + # If a second argument is specified, add it as a router + if [ ! -z "$2" ] + then + echo -e "static routers=$2" | tee -a /etc/dhcpcd.conf + + # If a third argument is specified, add it as a nameserver + if [ ! -z "$3" ] + then + echo -e "static domain_name_servers=$3"| tee -a /etc/dhcpcd.conf + fi + fi +fi diff --git a/otgether/otgether.json b/otgether/otgether.json index 56e7353..512742a 100644 --- a/otgether/otgether.json +++ b/otgether/otgether.json @@ -1,11 +1,21 @@ { "name": "otgether", - "text": "Set Pi Zero OTG Mode to Ethernet\\nWith Static IP: %1\\nRequires restart to take effect", + "text": "Set Pi Zero OTG Mode to Ethernet\\nStatic IP (optional): %1\\nGateway (optional): %2\\nNameserver (optional): %3\\nRequires restart to take effect", "script": "otgEther.sh", "args": [ { "type": "text", "default": "169.254.64.64", + "maxLength":19 + }, + { + "type": "text", + "default": "", + "maxLength":16 + }, + { + "type": "text", + "default": "", "maxLength":16 } ], @@ -17,6 +27,6 @@ "raspbian-pibakery.img", "raspbian-lite-pibakery.img" ], - "shortDescription":"Set the Pi Zero to use Ethernet over OTG, with a static IP address.", - "longDescription":"The Raspberry Pi Zero has the ability to support OTG gadget mode over it's DATA usb port. This block enables the Ethernet gadget, allowing your Raspberry Pi to be networked to a computer over USB. You need to specify an IP address for your Raspberr Pi, so that you'll be able to connect to it." + "shortDescription":"Set the Pi Zero to use Ethernet over OTG, optionally with a static IP address. Also optionally set the gateway and nameserver.", + "longDescription":"The Raspberry Pi Zero has the ability to support OTG gadget mode over it's DATA usb port. This block enables the Ethernet gadget, allowing your Raspberry Pi to be networked to a computer over USB. You may specify an IP address (and optionally a netmask in the form XXX.XXX.XXX.XXX/YY) for your Raspberry Pi, so that you'll be able to connect to it. If one is not set, you must have DHCP on the other end. You can also set optional IP addresses for the gateway and nameserver, to enable outbound networking (for example IP Masquerading.) NOTE: in order to set a gateway, a static IP must be set, and in order to set a nameserver, both a static IP and gateway must be set." }