#!/bin/bash # ------- # File: cap-net # Description: LliureX-cap dns and network configuration # Configures a network alias for each cap node # NB: This program works ONLY for the capname defined # in the CAP_NET_CAPNAME llxcfg variable, so the # server network configuration program must "synchronize" # this variable with the school's main capname ("CODIGO_CENTRO'?) # In addition, CAP_NET_HOST_IFACE must be defined locally in each host # # Authors: Luis Antonio 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 # -------- # do some tests [ "$CAP_VAR_CFG_DIR" ] || exit 0 [ "$CAP_FQDN" ] || exit 0 [ "$CAPNAME" ] || exit 0 [ "$CAP_HOST_ID" ] || exit 0 GLOBAL_CFG_FILE="$CAP_VAR_CFG_DIR/vars.net" GLOBAL_VARS_FILE="$CAP_VAR_CFG_DIR/dns.vars" # HOST_CFG_FILE="$CAP_VAR_CFG_DIR/$CAP_FQDN.ip.net" # read variables from global_file [ ! -r "$GLOBAL_CFG_FILE" ] || read CAP_NET_ADDRESS CAP_NET_MASK CAP_NET_DOMAIN CAP_NET_ALIAS < "$GLOBAL_CFG_FILE" eval "$(llxcfg-showvars CAP_NET_CAPNAME CAP_ZERO_CAPNAME)" [ "$CAP_NET_CAPNAME" ] || CAP_NET_CAPNAME="$CAP_ZERO_CAPNAME" [ "$CAP_NET_CAPNAME" -a "$CAP_NET_CAPNAME" = "$CAPNAME" ] || exit 0 # funcs net_write_vars(){ llxcfg-systemvars add CAP_NET_HOST_IP="$CAP_NET_HOST_IP" CAP_NET_HOST_MASK="$CAP_NET_MASK" CAP_NET_HOST_ALIAS="$CAP_NET_ALIAS" CAP_NET_ADDRESS="$CAP_NET_ADDRESS" CAP_NET_CAPNAME="$CAP_NET_CAPNAME" CAP_NET_MASK="$CAP_NET_MASK" CAP_NET_DOMAIN="$CAP_NET_DOMAIN" } # net_write_conf(){ # echo "$CAP_NET_HOST_IP node-$CAP_HOST_ID.$CAPNAME.$CAP_NET_DOMAIN" | llxcfg-install "-" "$HOST_CFG_FILE" # } net_write_global(){ echo "$CAP_NET_ADDRESS $CAP_NET_MASK $CAP_NET_DOMAIN $CAP_NET_ALIAS" | llxcfg-install "-" "$GLOBAL_CFG_FILE" echo CAP_NET_ADDRESS=$CAP_NET_ADDRESS > "$GLOBAL_VARS_FILE" echo CAP_NET_CAPNAME=$CAP_NET_CAPNAME >> "$GLOBAL_VARS_FILE" echo CAP_NET_MASK=$CAP_NET_MASK >> "$GLOBAL_VARS_FILE" echo CAP_NET_DOMAIN=$CAP_NET_DOMAIN >> "$GLOBAL_VARS_FILE" } net_test_vars(){ [ "$CAP_NET_ADDRESS" ] || return 1 [ "$CAP_NET_MASK" ] || return 1 [ "$CAP_NET_ALIAS" ] || return 1 [ "$CAP_NET_DOMAIN" ] || return 1 return 0 } net_generate_ip(){ # TODO: may be this trivial algorithm is not sufficient ... echo "${CAP_NET_ADDRESS%.*}.$CAP_HOST_ID" } case "$1" in create|join|reconfigure|request) if [ "$1" = "create" ] ; then # read "once" CAP_NET variables eval "$(llxcfg-showvars CAP_NET_ALIAS CAP_NET_ADDRESS CAP_NET_MASK CAP_NET_DOMAIN)" net_test_vars || exit 0 # and write global net_write_global else net_test_vars || exit 0 fi # generate address CAP_NET_HOST_IP="$(net_generate_ip)" # write local net_write_vars # set the alias llxcfg-cap add-alias # net_write_conf llxcfg-dnsd update ;; post-disconnect) llxcfg-systemvars del "CAP_NET_HOST_IP" "CAP_NET_HOST_MASK" llxcfg-cap remove-alias eth1 ;; esac exit 0