source: server/bin/setserveraddr @ 69052958

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 69052958 was e0314d93, checked in by ramon <ramongomez@…>, 9 years ago

#730 #739: Cambios aplicados:

  • Corregir errata en setserveraddr para tratar el fichero DHCP adecuado y establecer router por defecto si no existe.
  • Eliminar cambios temporales en Vagrantfile que corregían problemas de setserveraddr.
  • Actualizar lista de tickets resueltos.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4824 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 4.4 KB
RevLine 
[c8fd992]1#!/bin/bash
2# setserveraddr: modifica los ficheros de configuración para asignar los valores
3#       de la interfaz de red solicitada.
4# Nota: se enlazan los ficheros a los predefinidos detectados para la interfaz.
5# Uso:  setserveraddr iface
6# Autor: Ramon Gomez - Univ. Sevilla
7# Fecha: 2011-01-25
[8f70b5b]8# Versión: 1.0.5 - Regenerar ficheros de configuración.
9# Autor: Ramon Gomez - Univ. Sevilla
10# Fecha: 2014-06-06
[c8fd992]11
12
[632bd45]13# Variables globales.
[c8fd992]14PROG="$(basename $0)"
[632bd45]15
16# Comprobar parámetros.
[c8fd992]17if [ $# -ne 1 ]; then
[8f70b5b]18        echo "$PROG: Incorrect operand. Format: $PROG interface" >&2
[c8fd992]19        exit 1
20fi
21if [ "$USER" != "root" ]; then
22        echo "$PROG: Need to be root." >&2
23        exit 1
24fi
25
[8f70b5b]26# Aviso informando de que los clientes iniciados pueden quedarse colgados.
27read -p "WARNING: initiated clients can hang. Continue? (y/n): " ANSWER
28if [ "${ANSWER^^}" != "Y" ]; then
29        echo "Operation canceled."
30        exit 0
31fi
32
[c8fd992]33# Detectar la interfaz de red.
34DEVICES=$(ip -o link show up|awk -F: '$2!~/lo/ {print $2}')
[8f70b5b]35for DEV in $DEVICES; do
36        # Si se encuentra la interfaz de red, obtener su dirección IP.
37        [ "$DEV" == "$1" ] && SERVERIP=$(ip -o addr show dev $DEV | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
[c8fd992]38done
39
[8f70b5b]40# Comprobar si se ha detectado dirección IP.
41if [ -n "$SERVERIP" ]; then
42        # Ficheros temporales.
43        tmpfile=$(mktemp /tmp/og.XXXXX)
44        MYCNF=$(mktemp /tmp/.my.cnf.XXXXX)
45        trap "rm -f $tmpfile $MYCNF" 1 2 3 6 9 15
46
[c8fd992]47        # Comprobar si hay que modificar la configuración de DHCP.
48        CHANGE=0
[8f70b5b]49        for f in /etc/{dhcp,hcp3}/dhcpd.conf; do
50                if [ -f $f ]; then
51                        # Cambiar el parámetro "next-server" de DHCP.
52                        file="${f/./-$1.}"
[e0314d93]53                        sed -e "s/next-server.*/next-server $SERVERIP;/" \
54                            -e "s/option routers ;/option routers ${SERVERIP%.*}.1;/" $file >$tmpfile
[8f70b5b]55                        # Copiar el fichero y enlazarlo si hay cambios.
[67d0d8c]56                        if [ ! $f -ef $file ] || ! diff -q $tmpfile $file &>/dev/null; then
[8f70b5b]57                                mv $tmpfile $file
58                                chmod 644 $file
59                                ln -f $file $f
60                                CHANGE=1
61                        fi
[c8fd992]62                fi
63        done
64        # Si ha cambiado la configuración, reiniciar DHCP.
65        if [ $CHANGE == 1 ]; then
66                for f in /etc/init.d/{isc-dhcp-server,dhcp3-server,dhcpd}; do
67                        [ -x $f ] && $f restart
68                done
69        else
[2cbfd3f]70                echo "DHCP configuration has not changed."
[c8fd992]71        fi
[8f70b5b]72
73        # Guardar la IP anterior del repositorio.
[c8fd992]74        OPENGNSYS=/opt/opengnsys
[8f70b5b]75        source $OPENGNSYS/etc/ogAdmRepo.cfg
76        OLDSERVERIP=$IPlocal
77
78        # Comprobar si hay que modificar la configuración de OpenGnsys.
[c8fd992]79        CHANGE=0
[8f70b5b]80        # Procesar los ficheros de configuración de OpenGnSys.
81        for f in $OPENGNSYS/{etc/{ogAdmServer,ogAdmRepo,ogAdmAgent}.cfg,www/controlacceso.php,client/etc/ogAdmClient.cfg}; do
82                # Error si no existe algún fichero de configuración.
83                if [ ! -f $f ]; then
[c8fd992]84                        echo "$PROG: File $file does not exist." >&2
85                        exit 2
86                fi
[8f70b5b]87                # Cambiar la IP del servidor:
88                # - variables  ServidorAdm  e  IPlocal,
89                # - servidor o IP en URLs excepto si contienen "localhost".
90                sed -e "s,ServidorAdm=.*,ServidorAdm=$SERVERIP," \
91                    -e "s,IPlocal=.*,IPlocal=$SERVERIP," \
[4079733]92                    -e '/localhost/!s,https\?://[^/]*/\(.*\),https://'$SERVERIP'/\1,' $f >$tmpfile
[8f70b5b]93                file="${f/./-$1.}"
[2cbfd3f]94                # Si se usa otro interfaz o cambian los datos de red; ...
95                if [ ! $f -ef $file ] || ! diff -q $tmpfile $file &>/dev/null; then
96                        # Copiar el fichero y enlazarlo.
97                        cp $tmpfile $file
[8f70b5b]98                        ln -f $file $f
[c8fd992]99                        CHANGE=1
100                fi
101        done
[8f70b5b]102
[c8fd992]103        # Si ha cambiado la configuración, reiniciar OpenGnSys y actualizar la BD.
104        if [ $CHANGE == 1 ]; then
105                /etc/init.d/opengnsys restart
106                source $OPENGNSYS/etc/ogAdmServer.cfg
[69fc529]107                # Componer fichero con credenciales de conexión. 
108                cat << EOT > $MYCNF
109[client]
110user=$USUARIO
111password=$PASSWORD
112EOT
[8f70b5b]113                # Actualizar IP del servidor en la BD.
114                mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \
115                         "UPDATE entornos
116                             SET ipserveradm='$SERVERIP'
117                           WHERE identorno=1"
118
119                # Actualizar IP del repositorio en la BD.
[9d380ec]120                mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \
[8f70b5b]121                         "UPDATE repositorios
122                             SET ip='$SERVERIP'
123                           WHERE ip='$OLDSERVERIP'"
124
125                # Mostrar instrucciones a realizar tras la ejecución.
126                cat << EOT
127Default server interface set to: $1 ($SERVERIP)
128
129Manual tasks:
130Check DHCP configuration file and restart service, if needed.
131Log-in as Web Console organization user.
132 - Check URLs in all menus.
133 - Run Advanced Netboot in all rooms.
134
135EOT
[c8fd992]136        else
[8f70b5b]137                # Mensaje indicando que no se han cambiado datos.
[2cbfd3f]138                echo "Default interface has not changed: $1"
[c8fd992]139        fi
140else
[8f70b5b]141        # Error: interfaz de red no encontrado.
142        echo "$PROG: Network device not found. Format: $PROG interface" >&2
[c8fd992]143        exit 1
144fi
145
[2cbfd3f]146# Eliminar ficheros temporales.
147rm -f $tmpfile $MYCNF
148
Note: See TracBrowser for help on using the repository browser.