diff options
author | ramon <ramongomez@us.es> | 2012-01-25 13:13:34 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2012-01-25 13:13:34 +0000 |
commit | c8fd9921b18beba5ac6da50ed46f51adcc1c1393 (patch) | |
tree | db6988f9b36c96410f985c6be7e7f4b2d55035c2 /server/bin/setserveraddr | |
parent | e4b157262d5815df40a9c8b06974d137a7f634aa (diff) |
Versión 1.0.3, #410: Nuevo comando {{{setserveraddr}}}, que automatiza el cambio de configuración por defecto del Server para otra interfaz de red.
git-svn-id: https://opengnsys.es/svn/branches/version1.0@2463 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'server/bin/setserveraddr')
-rwxr-xr-x | server/bin/setserveraddr | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/server/bin/setserveraddr b/server/bin/setserveraddr new file mode 100755 index 00000000..44da0c7b --- /dev/null +++ b/server/bin/setserveraddr @@ -0,0 +1,75 @@ +#!/bin/bash +# setserveraddr: modifica los ficheros de configuración para asignar los valores +# de la interfaz de red solicitada. +# Nota: se enlazan los ficheros a los predefinidos detectados para la interfaz. +# Uso: setserveraddr iface +# Autor: Ramon Gomez - Univ. Sevilla +# Fecha: 2011-01-25 + + +# Comprobar parámetros. +PROG="$(basename $0)" +if [ $# -ne 1 ]; then + echo "$PROG: Incorrect operand. Format: $PROG device" >&2 + exit 1 +fi +if [ "$USER" != "root" ]; then + echo "$PROG: Need to be root." >&2 + exit 1 +fi + +# Detectar la interfaz de red. +DEVICES=$(ip -o link show up|awk -F: '$2!~/lo/ {print $2}') +FOUND=0 +for dev in $DEVICES; do + [ "$dev" == "$1" ] && FOUND=1; +done + +if [ $FOUND == 1 ]; then + # Comprobar si hay que modificar la configuración de DHCP. + CHANGE=0 + for f in /etc/{dhcp,dhcp3}/dhcpd.conf; do + file="${f/./-$1.}" + if [ -f $file -a ! $f -ef $file ]; then + ln -f $file $f + CHANGE=1 + fi + done + # Si ha cambiado la configuración, reiniciar DHCP. + if [ $CHANGE == 1 ]; then + for f in /etc/init.d/{isc-dhcp-server,dhcp3-server,dhcpd}; do + [ -x $f ] && $f restart + done + else + echo "Don't change the DHCP configuration." + fi + # Comprobar si hay que modificar la configuración de OpenGnsys. + OPENGNSYS=/opt/opengnsys + CHANGE=0 + for f in etc/{ogAdmServer,ogAdmRepo,ogAdmAgent}.cfg www/controlacceso.php client/etc/ogAdmClient.cfg; do + file="$OPENGNSYS/${f/./-$1.}" + if [ ! -f $file ]; then + echo "$PROG: File $file does not exist." >&2 + exit 2 + fi + cfg=$OPENGNSYS/$f + if [ ! $cfg -ef $file ]; then + ln -f $file $cfg + CHANGE=1 + fi + done + # Si ha cambiado la configuración, reiniciar OpenGnSys y actualizar la BD. + if [ $CHANGE == 1 ]; then + /etc/init.d/opengnsys restart + source $OPENGNSYS/etc/ogAdmServer.cfg + mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \ + "UPDATE entornos SET ipserveradm='$ServidorAdm' WHERE identorno=1" + echo "Default server interface set to: $1 ($ServidorAdm)" + else + echo "Don't change the default interface: $1" + fi +else + echo "$PROG: Network device not found. Format: $PROG device" >&2 + exit 1 +fi + |