source: server/bin/setclientlive @ 240a4dc

918-git-images-111dconfigure-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-instalacion
Last change on this file since 240a4dc was 7c841bd, checked in by ramon <ramongomez@…>, 8 years ago

#768: Adaptar nuevos cambios a scripts listclientlive y setclientlive.

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

  • Property mode set to 100755
File size: 2.4 KB
RevLine 
[5d28f39]1#!/bin/bash
2
3#/**
4#         setclientlive DirOGLive | IndiceOGLive { NombrePC | NombreAula } Modo_trabajo
5#@file    setclientlive
6#@brief   Configura el archivo de arranque de PXE para asignar el cliente ogLive, ya sea a un equipo o a un aula
7#@param   $1 DirOGLive, IndiceOGLive o "default" (según script "oglivecli")
8#@param   $2 Ámbito { NombrePC | NombreAula }
9#warning  No se admiten cambios temporales.
10#@version 1.1.0 - Versión inicial basada en script "setclientmode".
11#@author  Ramón M. Gómez - Univ. Sevilla, junio 2017
12#*/ ##
13
14
15# Variables.
16PROG=$(basename "$0")
17PATH=$PATH:$(dirname $(realpath "$0"))
18OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
19SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg
20TFTPDIR=$OPENGNSYS/tftpboot
21LOGFILE=$OPENGNSYS/log/opengnsys.log
22MYCNF=/tmp/.my.cnf.$$
23
24# Control básico de errores.
25if [ $# -ne 2 ]; then
26        echo "$PROG: Error de ejecución" >&2
27        echo "Formato: $PROG {DIR_OGLIVE|INDICE_OGLIVE|default} {NOMBRE_PC|NOMBRE_AULA}" >&2
28        exit 1
29fi
30if [ ! -r $SERVERCONF ]; then
31        echo "$PROG: Sin acceso a fichero de configuración" >&2
32        exit 2
33fi
34case "$1" in
35        [0-9]*)     DIR=$(oglivecli search $1 2>/dev/null) ;;
36        "default")  DIR="ogLive" ;;
37        *)          if oglivecli search "$1" 2>/dev/null; then DIR="$1"; fi ;;
38esac
39if [ -z "$DIR" ]; then
40        echo "$PROG: ogLive no ecncontrado, listar ejecutando \"oglivecli list\"" >&2
41        exit 1
42fi
43if [ ! -e "$TFTPDIR/$DIR" ]; then
44        echo "$PROG: directorio de ogLive no ecncontrado: \"DIR\"" >&2
45        exit 1
46fi
47
48# Obtener datos de acceso a la Base de datos.
49source $SERVERCONF
50# Sustituir caracteres ' por \' para evitar inyección SQL.
51OGLIVEDIR="${DIR//\'/\'}"
52RESOURCE="${2//\'/\'}"
53# Componer fichero con credenciales de conexión.
54touch $MYCNF
55chmod 600 $MYCNF
56cat << EOT > $MYCNF
57[client]
58user=$USUARIO
59password=$PASSWORD
60EOT
61# Borrar el fichero temporal si termina el proceso.
62trap "rm -f $MYCNF" 0 1 2 3 6 9 15
[7c841bd]63# Actualizar ogLive asignado al aula.
64mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -e \
65                "UPDATE aulas SET oglivedir='$OGLIVEDIR' WHERE nombreaula='$RESOURCE';"
[5d28f39]66# Actualizar ogLive para todos los clientes y reasignar plantilla PXE.
67listclientmode "$RESOURCE" | awk -F\" '{print $2,$4}' | \
[7c841bd]68        while read -r PC BOOTMODE; do
[5d28f39]69                date +"%b %d %T $PROG: Configurando \"$PC\" con cliente \"$OGLIVEDIR\"" | tee -a $LOGFILE
[7c841bd]70                mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -e \
[5d28f39]71                                "UPDATE ordenadores SET oglivedir='$OGLIVEDIR' WHERE nombreordenador='$PC';"
[7c841bd]72                setclientmode "$BOOTMODE" "$PC" PERM >/dev/null
[5d28f39]73        done
Note: See TracBrowser for help on using the repository browser.