53 lines
2.1 KiB
Bash
53 lines
2.1 KiB
Bash
#!/bin/bash
|
|
|
|
#/**
|
|
#@file setclientlive
|
|
#@brief Asignar un cliente de inicio ogLive a un ordenador o a un aula
|
|
#@usage setclientlive { DirOGLive | IndiceOGLive } Ambito
|
|
#@param DirOGLive subdirectorio del cliente ogLive ("default" para definido por defecto)
|
|
#@param IndiceOGLive nº de índice de cliente ogLive (según script "oglivecli")
|
|
#@param Ámbito nombre de ordenador o nombre de aula
|
|
#warning No se admiten cambios temporales.
|
|
#@version 1.1.0 - Versión inicial basada en script "setclientmode".
|
|
#@author Ramón M. Gómez - Univ. Sevilla, junio 2017
|
|
#*/ ##
|
|
|
|
|
|
# Variables y funciones globales.
|
|
PROG="$(basename "$0")"
|
|
OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
|
|
PATH=$PATH:$OPENGNSYS/bin
|
|
SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg
|
|
TFTPDIR=$OPENGNSYS/tftpboot
|
|
LOGFILE=$OPENGNSYS/log/opengnsys.log
|
|
|
|
source $OPENGNSYS/lib/ogfunctions.sh || exit 1
|
|
|
|
# Control básico de errores.
|
|
[ "$*" == "help" ] && help
|
|
[ "$*" == "version" ] && version
|
|
[ $# -eq 2 ] || raiseError usage
|
|
[ "$USER" != "root" ] && raiseError access "Need to be root"
|
|
source $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración"
|
|
|
|
case "$1" in
|
|
[0-9]*) DIR=$(oglivecli search $1 2>/dev/null) ;;
|
|
"default") DIR="ogLive" ;;
|
|
*) if oglivecli search "$1" &>/dev/null; then DIR="$1"; fi ;;
|
|
esac
|
|
[ "$DIR" ] || raiseError notfound "Cliente ogLive \"$1\", listar ejecutando \"oglivecli list\""
|
|
[ -e "$TFTPDIR/$DIR" ] || raiseError notfound "Directorio de ogLive \"$DIR\""
|
|
|
|
# Sustituir caracteres ' por \' para evitar inyección SQL.
|
|
OGLIVEDIR="${DIR//\'/\\\'}"
|
|
RESOURCE="${2//\'/\\\'}"
|
|
# Actualizar ogLive asignado al aula.
|
|
dbexec "UPDATE aulas SET oglivedir='$OGLIVEDIR' WHERE nombreaula='$RESOURCE';"
|
|
# Actualizar ogLive para todos los clientes y reasignar plantilla PXE.
|
|
listclientmode "$RESOURCE" | awk -F\" '{print $2,$4}' | \
|
|
while read -r PC BOOTMODE; do
|
|
date +"%b %d %T $PROG: Configurando \"$PC\" con cliente \"$OGLIVEDIR\"" | tee -a $LOGFILE
|
|
dbexec "UPDATE ordenadores SET oglivedir='$OGLIVEDIR' WHERE nombreordenador = '$PC';"
|
|
setclientmode "$BOOTMODE" "$PC" PERM >/dev/null
|
|
done
|