#!/bin/bash

function internalfetch {
echo "Enter an internal interface's IP address."
read INT_IP
if [ ${INT_IP} == . ]; then return 1; else
INTERNAL_IP="${INTERNAL_IP} ${INT_IP}"
echo
echo "Enter that internal interface's netmask."
read INT_NETMASK
INTERNAL_NETMASK="${INTERNAL_NETMASK} ${INT_NETMASK}"
return 0; fi
}

echo "# /etc/ipmasq.conf" > /tmp/ipmasq.conf
echo "#" >> /tmp/ipmasq.conf
echo "# Config file for IP Masquerade for Debian systems" >> /tmp/ipmasq.conf
echo >> /tmp/ipmasq.conf

echo "What is the IP address of your external interface?"
read EXTERNAL_IP
echo
echo "# EXTERNAL_IP: IP address of the external interface" >> /tmp/ipmasq.conf
echo "EXTERNAL_IP=${EXTERNAL_IP}" >> /tmp/ipmasq.conf
echo >> /tmp/ipmasq.conf

echo "What is the netmask of your external interface?"
read EXTERNAL_NETMASK
echo
echo "# EXTERNAL_NETMASK: netmask of the external interface" >> /tmp/ipmasq.conf
echo "EXTERNAL_NETMASK=${EXTERNAL_NETMASK}" >> /tmp/ipmasq.conf
echo >> /tmp/ipmasq.conf

echo "Please specify the internal interfaces to be masqueraded. Enter a '.' to finish."
while internalfetch; do echo; done

echo "# INTERNAL_IP: IP addresses of the internal interfaces" >> /tmp/ipmasq.conf
echo INTERNAL_IP=\(${INTERNAL_IP} \) >> /tmp/ipmasq.conf
echo >> /tmp/ipmasq.conf

echo "# INTERNAL_NETMASK: netmasks of internal interfaces" >> /tmp/ipmasq.conf
echo INTERNAL_NETMASK=\(${INTERNAL_NETMASK} \) >> /tmp/ipmasq.conf

mv /tmp/ipmasq.conf /etc/ipmasq.conf

