#!/bin/bash # ------- # File: lliurex-srv-vars # Description: Updates and changes default values for # LliureX server variables # # 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 # -------- set -e usage(){ echo -e "Usage: $(basename $0) set-default [SRV_NUMBER]\n\ $(basename $0) update\n\ $(basename $0) simulate-vars SRV_NUMBER" exit 1 } show_ancient_values(){ # uffffffff . /usr/sbin/llxcfg-vars.sh llxcfg_vars_show "$(llxcfg_vars_files |grep "^/usr/")" "$@" } update_vars(){ SIMULATE="" if [ "$1" ] ; then SIMULATE="Y" SRV_HOST_ID="$1" else eval "$(llxcfg-showvars "SRV_HOST_ID")" fi if echo "$SRV_HOST_ID" |grep -q "^[[:digit:]]\+$" && [ $SRV_HOST_ID -gt 0 ] && [ $SRV_HOST_ID -le 254 ] ; then if [ "$SRV_HOST_ID" = "254" ] ; then # server SRV_HOST_ID=254 DEFAULT_SRV_DOMAIN=centro DEFAULT_SRV_IP=10.1.0.254 DEFAULT_SRV_MASK=255.255.248.0 LDAP_SRV_MODE="MASTER" else DEFAULT_SRV_DOMAIN="aula${SRV_HOST_ID}.centro" DEFAULT_SRV_IP=10.2.$SRV_HOST_ID.254 DEFAULT_SRV_MASK=255.255.255.0 LDAP_SRV_MODE="SLAVE" fi if [ -z "$SIMULATE" ] ; then # llxcfg-systemvars del SRV_DOMAIN llxcfg-systemvars add SRV_DOMAIN="$DEFAULT_SRV_DOMAIN" DEFAULT_SRV_DOMAIN="$DEFAULT_SRV_DOMAIN" DEFAULT_SRV_IP="$DEFAULT_SRV_IP" DEFAULT_SRV_MASK="$DEFAULT_SRV_MASK" SRV_HOST_ID="$SRV_HOST_ID" fi else if [ "$SIMULATE" ] ; then eval "$(show_ancient_values DEFAULT_SRV_IP DEFAULT_SRV_MASK DEFAULT_SRV_DOMAIN LDAP_SRV_MODE)" else llxcfg-systemvars del DEFAULT_SRV_DOMAIN DEFAULT_SRV_IP DEFAULT_SRV_MASK SRV_HOST_ID SRV_DOMAIN fi fi # libreria LIB_FILE="/usr/share/lliurex/lliurex-srv-common/lliurex-netfuncs.sh" if [ "$SIMULATE" ] ; then SRV_HOST_ID="" eval "$(llxcfg-showvars "SRV_HOST_ID")" if [ "$SRV_HOST_ID" ] && [ "$SRV_HOST_ID" = "$NEW_SRV_HOST_ID" ] ; then # assume is already configured DEFAULT_SRV_DOMAIN="$(lliurex-net get_srv_domain)" DEFAULT_SRV_MASK="$(lliurex-net get_srv_mask)" DEFAULT_SRV_IP="$(lliurex-net get_srv_ip)" fi echo "SRV_DOMAIN='$DEFAULT_SRV_DOMAIN'" echo "SRV_MASK='$DEFAULT_SRV_MASK'" echo "SRV_IP='$DEFAULT_SRV_IP'" echo "LDAP_SRV_MODE='$LDAP_SRV_MODE'" exit 0 fi [ -e "$LIB_FILE" ] || exit 1 . $LIB_FILE llxcfg-systemvars add "SRV_IP=`get_srv_ip`" \ "SRV_MASK=`get_srv_mask`" \ "SRV_BITMASK=`get_srv_bitmask`" \ "SRV_BCAST=`get_srv_bcast`" \ "SRV_NETWORK=`get_srv_network`" \ "SRV_MAC=`get_srv_mac`" \ "SRV_NIC=`get_srv_nic`" \ "SRV_DOMAIN=`get_srv_domain`" \ "HOSTNAME_STRING=server.`get_srv_domain`" \ "SRV_REVERSE_DOMAIN=`get_srv_reverse_domain`" \ "SRV_FQDN=`get_srv_name`.`get_srv_domain`" } # main [ "$1" ] || usage case "$1" in update) # create vars update_vars ;; set-default) shift SRV_NUMBER="$1" if [ -z "$SRV_NUMBER" ] ; then llxcfg-systemvars del SRV_HOST_ID else llxcfg-systemvars add SRV_HOST_ID="$SRV_NUMBER" fi update_vars ;; simulate-vars) shift [ "$1" ] || usage NEW_SRV_HOST_ID="$1" update_vars "$1" ;; *) usage ;; esac exit