danb35 / freenas-iocage-nextcloud

Script to create an iocage jail on FreeNAS for the latest Nextcloud 28 release, including Caddy, MariaDB or PostgreSQL, and Let's Encrypt
GNU General Public License v3.0
258 stars 71 forks source link

Handle custom netmask for JAIL_IP #114

Closed cfunkhouser closed 4 years ago

cfunkhouser commented 4 years ago

It was recently necessary for me to set a /16 for a JAIL_IP. This makes that possible.

Default behavior is maintained. New option is documented.

danb35 commented 4 years ago

validating the value, it has to be between 1-32 so if 0 or 33+

Is a netmask of less than 8 bits (i.e., larger than a class A network) even valid?

PrivatePuffin commented 4 years ago

Another option would be to allow adding /16 to the JAIL_IP And just splitting it in the script, defaulting to /24 if no subnet is added.

I think that is a way better user experience

danb35 commented 4 years ago

And just splitting it in the script, defaulting to /24 if no subnet is added.

I think I like this idea better, and will start working on it unless the PR is updated to do it first.

PrivatePuffin commented 4 years ago

@danb35 From the top of my head you could do this:

JAIL_IP=*ENTER IP With or Without Mask*
NETMASK=${JAIL_IP%*/}
JAIL_IP=${JAIL_IP%/*}
danb35 commented 4 years ago

That looks cleaner than what I came up with:

IP=$(echo ${JAIL_IP} | cut -f1 -d/)
NETMASK=$(echo ${JAIL_IP} | cut -f2 -d/)
if [ "${NETMASK}" = "${IP}" ]
then
  NETMASK="24"
fi
danb35 commented 4 years ago

Addressed with the above commit.