#!/bin/bash # ------- # File: lliurex-srv-netfix # Description: Server /etc/network/interfaces configuration tool # Author: Luis Garcia Gisbert # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- #################### # DEFAULT VALUES # #################### NEW_IP="" NEW_NETMASK="" NEW_GATEWAY="" NEW_NAMESERVER="" NEW_EXTRADOMAIN="" EXTERNAL="" INTERNAL="" ##################### # BASIC FUNCTIONS # ##################### usage(){ echo "lliurex-srv-netfix ETH [--internal|--external] -ip|-netmask|-gateway|-extra-ns|-extra-domain" exit 1 } die(){ echo "ERROR $1" exit 1 } ############### # FUNCTIONS # ############### do_basic_fix(){ llxcfg-setvars "SRV_NIC=$1" &>/dev/null fix_interfaces "$1" } set_ip_netmask(){ echo "" } is_valid_gw(){ # If in the future this script fails, check the output format of the ipcalc. IP_NET=$(ipcalc_value Network "$NEW_IP" "$NEW_NETMASK" ) GW_NET=$(ipcalc_value Network "$NEW_GATEWAY" "$NEW_NETMASK" ) if [ "$IP_NET" = "$GW_NET" ] ;then return 0 fi return 1 } # # MAIN # [ "$1" ] || usage LIB_FILE="/usr/share/lliurex/lliurex-srv-common/server-netfuncs.sh" [ -r "$LIB_FILE" ] || die "$LIB_FILE not found" source $LIB_FILE [ $(id -u) -eq 0 ] || die "You mas be root, my friend" # The first parameter is Ethernet? ETH="$1" shift # If no more parameters than ETH is passed # we make a basic configuration of ETH if [ -z "$1" ] ; then do_basic_fix "$ETH" exit 0 fi is_ethernet_card "$ETH" || die "The first parameter must be a Ethernet Device" # Now we must decide if ETH is Internal or External if [ "$1" = "--external" ] ; then EXTERNAL="True" elif [ "$1" = "--internal" ] ; then INTERNAL="True" else die "The Device must be internal or external" fi shift # The others parameters while [ $# -ge 1 ] ; do case $1 in dhcp) DHCP="True" shift ;; -ip) [ -z "$2" ] && usage NEW_IP=$2 shift 2 ;; -netmask)[ -z "$2" ] && usage NEW_NETMASK=$2 shift 2 ;; -gateway) [ -z "$2" ] && usage NEW_GATEWAY=$2 shift 2 ;; -extra-ns) [ -z "$2" ] && usage NEW_NAMESERVER=$2 shift 2 ;; -extra-domain) [ -z "$2" ] && usage NEW_EXTRADOMAIN=$2 shift 2 ;; *) usage ;; esac done # If the ETHERNET is the Internal Device: if [ "$INTERNAL" = "True" ] ; then # Is a Valid IP/NETMASK? check_ipcalc_arg "$NEW_IP" "$NEW_NETMASK" || die "Please give me a IP NETMASK" # Yes, now We must assign it set_interfaces $ETH $NEW_IP $NEW_NETMASK fi if [ "$EXTERNAL" = "True" ] ; then if [ "$DHCP" = "True" ] ; then set_interfaces $ETH dhcp # Is a Valid IP/NETMASK? else if check_ipcalc_arg "$NEW_IP" "$NEW_NETMASK" ; then [ -z "$NEW_GATEWAY" ] || is_valid_gw || die "Gateway not valid, please check it" # Yes, now We must assign it set_interfaces $ETH $NEW_IP $NEW_NETMASK $NEW_GATEWAY else die "Please give me a IP/NETMASK or Check DHCP Option" fi fi fi if [ ! -z "$NEW_EXTRADOMAIN" ] ; then llxcfg-setvars DNS_EXTRA_DOMAINS="$NEW_EXTRADOMAIN" fi if [ ! -z "$NEW_NAMESERVER" ] ; then llxcfg-setvars DNS_EXTRA_NS="$NEW_NAMESERVER" fi