[5d28f39] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #/** |
---|
| 4 | #@file setclientlive |
---|
[81b2ea1] | 5 | #@brief Asignar un cliente de inicio ogLive a un ordenador o a un aula |
---|
| 6 | #@usage setclientlive { DirOGLive | IndiceOGLive } Ambito |
---|
| 7 | #@param DirOGLive subdirectorio del cliente ogLive ("default" para definido por defecto) |
---|
| 8 | #@param IndiceOGLive nº de índice de cliente ogLive (según script "oglivecli") |
---|
| 9 | #@param Ámbito nombre de ordenador o nombre de aula |
---|
[5d28f39] | 10 | #warning No se admiten cambios temporales. |
---|
| 11 | #@version 1.1.0 - Versión inicial basada en script "setclientmode". |
---|
| 12 | #@author Ramón M. Gómez - Univ. Sevilla, junio 2017 |
---|
| 13 | #*/ ## |
---|
| 14 | |
---|
| 15 | |
---|
[81b2ea1] | 16 | # Variables y funciones globales. |
---|
| 17 | PROG="$(basename "$0")" |
---|
[5d28f39] | 18 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
[81b2ea1] | 19 | PATH=$PATH:$OPENGNSYS/bin |
---|
[5d28f39] | 20 | SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg |
---|
| 21 | TFTPDIR=$OPENGNSYS/tftpboot |
---|
[81b2ea1] | 22 | |
---|
| 23 | source $OPENGNSYS/lib/ogfunctions.sh || exit 1 |
---|
[5d28f39] | 24 | |
---|
| 25 | # Control básico de errores. |
---|
[81b2ea1] | 26 | [ "$*" == "help" ] && help |
---|
| 27 | [ "$*" == "version" ] && version |
---|
| 28 | [ $# -eq 2 ] || raiseError usage |
---|
| 29 | [ "$USER" != "root" ] && raiseError access "Need to be root" |
---|
| 30 | source $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" |
---|
| 31 | |
---|
[5d28f39] | 32 | case "$1" in |
---|
[81b2ea1] | 33 | [0-9]*) DIR=$(oglivecli search $1 2>/dev/null) ;; |
---|
| 34 | "default") DIR="ogLive" ;; |
---|
| 35 | *) if oglivecli search "$1" &>/dev/null; then DIR="$1"; fi ;; |
---|
[5d28f39] | 36 | esac |
---|
[81b2ea1] | 37 | [ "$DIR" ] || raiseError notfound "Cliente ogLive \"$1\", listar ejecutando \"oglivecli list\"" |
---|
| 38 | [ -e "$TFTPDIR/$DIR" ] || raiseError notfound "Directorio de ogLive \"$DIR\"" |
---|
[5d28f39] | 39 | |
---|
| 40 | # Sustituir caracteres ' por \' para evitar inyección SQL. |
---|
[81b2ea1] | 41 | OGLIVEDIR="${DIR//\'/\\\'}" |
---|
| 42 | RESOURCE="${2//\'/\\\'}" |
---|
[7c841bd] | 43 | # Actualizar ogLive asignado al aula. |
---|
[81b2ea1] | 44 | dbexec "UPDATE aulas SET oglivedir='$OGLIVEDIR' WHERE nombreaula='$RESOURCE';" |
---|
[5d28f39] | 45 | # Actualizar ogLive para todos los clientes y reasignar plantilla PXE. |
---|
| 46 | listclientmode "$RESOURCE" | awk -F\" '{print $2,$4}' | \ |
---|
[7c841bd] | 47 | while read -r PC BOOTMODE; do |
---|
[c28eefa] | 48 | echolog "Configurando \"$PC\" con cliente \"$OGLIVEDIR\"" |
---|
[81b2ea1] | 49 | dbexec "UPDATE ordenadores SET oglivedir='$OGLIVEDIR' WHERE nombreordenador = '$PC';" |
---|
| 50 | setclientmode "$BOOTMODE" "$PC" PERM >/dev/null |
---|
| 51 | done |
---|