source: server/bin/setclientmode @ 09da038

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 09da038 was fea70bf, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: nuevas funciones ogGetGroupName y ogGetGroupDir; corregir pequeña errata en comando setclientmode (modifica #427 y #444)

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

  • Property mode set to 100755
File size: 2.9 KB
Line 
1#!/bin/bash
2# setclientmode: Configura el archivo de arranque de PXE para los clientes,
3#       ya sea un equipo o un aula, generando enlaces a archivos usados como plantilla.
4# Nota: El archivo PXE por defecto "default" se deja en modo de ejecución "user"
5#       y se eliminan los enlaces para equipos con la plantilla por defecto.
6# Uso:  clienmode NombrePlatilla { NombrePC | NombreAula }
7# Autores: Irina Gomez y Ramon Gomez - Univ. Sevilla, noviembre 2010
8
9
10# Variables.
11PROG=$(basename $0)
12OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
13SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg
14PXEDIR=$OPENGNSYS/tftpboot/menu.lst
15TEMPLATE="$PXEDIR/templates/$1"
16LOGFILE=$OPENGNSYS/log/opengnsys.log
17
18# Control básico de errores.
19if [ $# -ne 2 ]; then
20        echo "$PROG: Error de ejecución"
21        echo "Formato: $PROG Archivo_platilla [NOMBRE_PC|NOMBRE_AULA]"
22        exit 1
23fi
24if [ ! -r $SERVERCONF ]; then
25        echo "$PROG: Sin acceso a fichero de configuración"
26        exit 2
27fi
28if [ ! -e $TEMPLATE ]; then
29        echo "No existe archivo platilla: $TEMPLATE"
30        exit
31fi
32
33# Obtener datos de acceso a la Base de datos.
34source $SERVERCONF
35# Comprobar si se recibe nombre de aula o de equipo.
36IDAULA=$(mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \
37                "SELECT idaula FROM aulas WHERE nombreaula=\"$2\";")
38
39if [ -n "$IDAULA" ]; then
40        # Aula encontrada
41        ETHERNET=$(mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \
42                "SELECT mac FROM ordenadores WHERE idaula=\"$IDAULA\";")
43else
44        # Buscar ordenador
45        ETHERNET=$(mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \
46                "SELECT mac FROM ordenadores WHERE nombreordenador=\"$2\";")
47fi
48if [ -z "$ETHERNET" ]; then
49        date +"%b %d %T $PROG: No existe aula o equipo con el nombre \"$2\"" | tee -a $LOGFILE
50        exit 1
51fi
52
53# Copiar fichero de configuración y actualizar base de datos.
54date +"%b %d %T $PROG: Configurando \"$1\" en \"$2\"" | tee -a $LOGFILE
55NPC=0
56for AUX in $ETHERNET; do
57        date +"%b %d %T $PROG: Detectada ethernet \"$AUX\" en \"$2\"" | tee -a $LOGFILE
58        AUX="01-${AUX:0:2}-${AUX:2:2}-${AUX:4:2}-${AUX:6:2}-${AUX:8:2}-${AUX:10:2}"
59        # Si existe anteriormente lo borra
60        [ -e $PXEDIR/$AUX ] && rm $PXEDIR/$AUX
61        if [ "$1" != "default" ]; then
62                cp -a $TEMPLATE $PXEDIR/$AUX
63                DATOS=$(mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \
64                        "SELECT ordenadores.ip, ':', repositorios.ip, ':',
65                                aulas.router, ':', aulas.netmask, ':',
66                                ordenadores.netiface, ':none group=',
67                                REPLACE (aulas.nombreaula, ' ', '_')
68                                FROM ordenadores
69                                JOIN aulas ON ordenadores.idaula=aulas.idaula
70                                JOIN repositorios ON ordenadores.idrepositorio=repositorios.idrepositorio
71                                WHERE ordenadores.mac=\"$ETHERNET\";")
72                DATOS=$(echo ${DATOS//  /} | tr 'áéíóúñÁÉÍÓÚÑ' 'aeiounAEIOUN')
73                perl -pi -e "s/INFOHOST/$DATOS/g" $PXEDIR/$AUX
74                mysql -u "$USUARIO" -p"$PASSWORD" -D "$CATALOG" -N -e \
75                        "UPDATE ordenadores SET arranque=\"$1\" WHERE mac=\"$ETHERNET\";"
76        fi
77        let NPC=NPC+1
78done
79date +"%b %d %T $PROG: $NPC equipo(s) configurado(s)" | tee -a $LOGFILE
80
Note: See TracBrowser for help on using the repository browser.