1 | #!/bin/bash |
---|
2 | |
---|
3 | #/** |
---|
4 | #@file setclientlive |
---|
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 |
---|
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 | |
---|
16 | # Variables y funciones globales. |
---|
17 | PROG="$(basename "$0")" |
---|
18 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
19 | PATH=$PATH:$OPENGNSYS/bin |
---|
20 | SERVERCONF=$OPENGNSYS/etc/ogserver.json |
---|
21 | TFTPDIR=$OPENGNSYS/tftpboot |
---|
22 | LOGFILE=$OPENGNSYS/log/opengnsys.log |
---|
23 | |
---|
24 | source $OPENGNSYS/lib/ogfunctions.sh || exit 1 |
---|
25 | |
---|
26 | # Control básico de errores. |
---|
27 | [ "$*" == "help" ] && help |
---|
28 | [ "$*" == "version" ] && version |
---|
29 | [ $# -eq 2 ] || raiseError usage |
---|
30 | [ "$USER" != "root" ] && raiseError access "Need to be root" |
---|
31 | source_json_config $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" |
---|
32 | |
---|
33 | case "$1" in |
---|
34 | [0-9]*) DIR=$(oglivecli search $1 2>/dev/null) ;; |
---|
35 | "default") DIR="ogLive" ;; |
---|
36 | *) if oglivecli search "$1" &>/dev/null; then DIR="$1"; fi ;; |
---|
37 | esac |
---|
38 | [ "$DIR" ] || raiseError notfound "Cliente ogLive \"$1\", listar ejecutando \"oglivecli list\"" |
---|
39 | [ -e "$TFTPDIR/$DIR" ] || raiseError notfound "Directorio de ogLive \"$DIR\"" |
---|
40 | |
---|
41 | # Sustituir caracteres ' por \' para evitar inyección SQL. |
---|
42 | OGLIVEDIR="${DIR//\'/\\\'}" |
---|
43 | RESOURCE="${2//\'/\\\'}" |
---|
44 | # Actualizar ogLive asignado al aula. |
---|
45 | dbexec "UPDATE aulas SET oglivedir='$OGLIVEDIR' WHERE nombreaula='$RESOURCE';" |
---|
46 | # Actualizar ogLive para todos los clientes y reasignar plantilla PXE. |
---|
47 | listclientmode "$RESOURCE" | awk -F\" '{print $2,$4}' | \ |
---|
48 | while read -r PC BOOTMODE; do |
---|
49 | date +"%b %d %T $PROG: Configurando \"$PC\" con cliente \"$OGLIVEDIR\"" | tee -a $LOGFILE |
---|
50 | dbexec "UPDATE ordenadores SET oglivedir='$OGLIVEDIR' WHERE nombreordenador = '$PC';" |
---|
51 | setclientmode "$BOOTMODE" "$PC" PERM >/dev/null |
---|
52 | done |
---|