#!/bin/bash # This program is Licensed under GPL 3.0 or higher # Author: Angel Berlanas Vicente # THE CHOSEN ONE METHOD usage(){ echo "Usage: ${0} ETHERNET" >&2 exit 1 } die(){ echo ERROR: $@ exit 1 } # LIBFILES for LIB_FILE in "/usr/share/lliurex-express/lliurex-express-common.sh" "/usr/share/lliurex/lliurex-srv-common/server-netfuncs.sh" ; do [ -r "$LIB_FILE" ] || exit 1 . $LIB_FILE done # Test if DNS_EXTRA_NS and DNS_EXTRA_DOMAINS [ -x /usr/sbin/llxcfg-showvars ] || { echo "Not llxcfg-showvars present in system..."; exit 1; } LIST_OF_VALUES_FROM_RUNTIME="DNS_EXTRA_NS DNS_EXTRA_DOMAINS SRV_NIC LLXCFG_IFACE" eval $(/usr/sbin/llxcfg-showvars $LIST_OF_VALUES_FROM_RUNTIME) # GETTEXT Values TEXTDOMAIN="lliurex-express-server" export TEXTDOMAIN [ -z "$LANG" ] || LANGUAGE="${LANG}:${LANGUAGE}" # Messages MSG_TITLE_TEXT="$(gettext "Edit the fields you need")" MSG_TITLE_WINDOW="$(gettext "LliureX Server Express")" MSG_IP="$(gettext "IP")" MSG_MASK="$(gettext "Mask")" MSG_GATEWAY="$(gettext "Gateway")" MSG_EXTRANS="$(gettext "Extra Nameserver")" MSG_EXTRADOMAIN="$(gettext "Extra Domain")" MSG_DHCP=$(gettext "DHCP") MSG_QUESTION_DHCP="$(gettext "Do you want set automatically or manually the IP details (IP, Netmask, Gateway)?")" MSG_OK_DHCP_LABEL="$(gettext "Automatic (by default)")" MSG_CANCEL_DHCP_LABEL="$(gettext "Manual")" # Some Default Values DEFAULT_ETH="eth0" DEFAULT_ICON_FOR_ZENITY="/usr/share/icons/Human/scalable/categories/redhat-internet.svg" DEFAULT_WIDTH="500" STATUS_OF_THE_ART="" ETH_STATUS="" LIST_OF_ETHS_TEXT="" # The Main Program show_ip_question_set_automatically(){ rc=0 # Show Message IS_EXTERNAL_DHCP_LIVING_UNDER_DHCP=$(zenity --width="$DEFAULT_WIDTH" --question --text="$MSG_QUESTION_DHCP" --ok-label="$MSG_OK_DHCP_LABEL" --cancel-label="$MSG_CANCEL_DHCP_LABEL") rc=$? # DHCP or MANUAL .... that's the question if [ $rc -eq 0 ] ; then ETH_STATUS="AUTO" else ETH_STATUS="MANUAL" fi } replenish_values(){ BASE_LIST="$IP $MASK $EXTRANS $EXTRADOMAIN" LIST_OF_ETHS_TEXT="$BASE_LIST" } show_zenity(){ rc=0 STATUS_OF_THE_ART=$(zenity --width="$DEFAULT_WIDTH" --list --editable --column=" $MSG_IP " --column=" $MSG_MASK " --column=" $MSG_EXTRANS " --column=" $MSG_EXTRADOMAIN " $LIST_OF_ETHS_TEXT --print-column="ALL" --text="$MSG_TITLE_TEXT" --title="$MSG_TITLE_WINDOW" --window-icon="$DEFAULT_ICON_FOR_ZENITY" ) || rc=$? if [ $rc -eq 0 -a -z "$STATUS_OF_THE_ART" ] ; then STATUS_OF_THE_ART="$IP|$MASK|$EXTRANS|$EXTRADOMAIN" fi return 0 } # Some usefull tests! IFACE=$1 # Is empty? { [ "$IFACE" ] && is_ethernet_card "$IFACE" ; }|| usage # Is a ethernet card? #is_ethernet_card "$IFACE" || usage # Ok, I'm glad i, continue please... # Replenish Values IP=$(get_current_ip "$IFACE") MASK=$(get_current_netmask "$IFACE") EXTRANS=$DNS_EXTRA_NS EXTRADOMAIN=$DNS_EXTRA_DOMAINS shift 1 while [ $# -ge 1 ] ; do case $1 in -ip) [ -z "$2" ] IP="$2" shift 2 ;; -mask) [ -z "$2" ] MASK="$2" shift 2 ;; -ns) [ -z "$2" ] EXTRANS="$2" shift 2 ;; -domain) [ -z "$2" ] EXTRADOMAIN="$2" shift 2 ;; *) usage ;; esac done show_ip_question_set_automatically if [ "$ETH_STATUS" = "AUTO" ] ; then fix_interfaces "$IFACE" llxcfg-nm --force erradicate llxcfg-nm --force replenish # Workaround to disable the Evil NetworkManager Forever and ever. LIVING_UNDER_CASPER="$(llxcfg-bootvar boot)" if [ "$LIVING_UNDER_CASPER" = "casper" ]; then for p in nm-system-settings NetworkManager ; do killall "$p" || true done fi llxcfg-nm update exit 0 fi replenish_values show_zenity if [ -z "$STATUS_OF_THE_ART" ] ; then echo "nothing to do" exit 0 else NEW_IP="$(echo $STATUS_OF_THE_ART|cut -d "|" -f1)" NEW_MASK="$(echo $STATUS_OF_THE_ART|cut -d "|" -f2)" NEW_EXTRANS="$(echo $STATUS_OF_THE_ART|cut -d "|" -f3)" NEW_EXTRADOMAIN="$(echo $STATUS_OF_THE_ART|cut -d "|" -f4)" # Some aditional checkers if [ "$NEW_IP" != "$(get_current_ip "$IFACE")" -o "$NEW_MASK" != "$(get_current_netmask "$IFACE")" ];then lliurex-net is_valid_ip "$NEW_IP" "$NEW_MASK" || exit 1 fi if [ -z "$NEW_EXTRANS" ] ; then llxcfg-setvars DNS_EXTRA_NS="$NEW_EXTRANS" fi if [ -z "$NEW_EXTRADOMAIN" ] ; then llxcfg-setvars DNS_EXTRA_DOMAINS="$NEW_EXTRADOMAIN" fi # Finally fix the /etc/network/interfaces set_interfaces "$IFACE" "$NEW_IP" "$NEW_MASK" llxcfg-nm --force erradicate llxcfg-nm --force replenish # Workaround to disable the Evil NetworkManager Forever and ever. LIVING_UNDER_CASPER="$(llxcfg-bootvar boot)" if [ "$LIVING_UNDER_CASPER" = "casper" ]; then for p in nm-system-settings NetworkManager ; do killall "$p" || true done fi llxcfg-nm update fi exit 0