#!/bin/bash # installoglive - instala cliente ogLive. # Nota: Si no se especifica fichero local, el usuario debe elegir # el número del ogLive que desea descargar e instalar. # Uso: installoglive [fichero] # Autor: Ramón M. Gómez - ETSII Univ. Sevilla # Fecha: 2015-01-26 # Versión: 1.1 - Posibilidad para instalar fichero ogLive local. # Autor: Ramón M. Gómez - ETSII Univ. Sevilla # Fecha: 2015-11-06 # Versión: 1.1.0a - Adaptar la versión de Rsync de cliente y servidor. # Autor: Ramón M. Gómez - ETSII Univ. Sevilla # Fecha: 2015-12-16 # Control de acceso. PROG=$(basename $0) if [ "$USER" != "root" ]; then echo "$PROG: Need to be root." >&2 exit 1 fi # Constantes. DOWNLOADURL="http://opengnsys.es/downloads" OPENGNSYS=/opt/opengnsys OGCLIENTDIR=/opt/opengnsys/tftpboot/ogclient OGINITRD=$OGCLIENTDIR/oginitrd.img OGVMLINUZ=$OGCLIENTDIR/ogvmlinuz OGSQFS=$OGCLIENTDIR/ogclient.sqfs if [ -n "$1" ]; then # Si se recibe un parámetro, utilizar fichero ogLive local. TARGETFILE="$1" OGLIVEFILE=$(basename $TARGETFILE) else # Sin parámetros, listar todos los ficheros ogLive descargables. OGLIVE=( $(wget $DOWNLOADURL -O - 2>/dev/null|grep ogLive.*iso) ) NISOS=${#OGLIVE[@]} echo "Descargas disponibles (+- = instalado):" for i in $(seq 1 $NISOS); do [ -e $OPENGNSYS/lib/${OGLIVE[i-1]} ] && OGLIVE[i-1]="+-${OGLIVE[i-1]}" done select opt in ${OGLIVE[@]}; do [ -n "$opt" ] && OGLIVEFILE=${opt/+-/} && break done # Tamaño del fichero a descargar. SOURCELENGTH=$(LANG=C wget --spider $DOWNLOADURL/$OGLIVEFILE 2>&1 | awk '/Length:/ {print $2}') [ -n "$SOURCELENGTH" ] || exit # Descarga de ogLive. TARGETFILE=$OPENGNSYS/lib/$OGLIVEFILE wget $DOWNLOADURL/$OGLIVEFILE -O $TARGETFILE || exit fi # Error si no existe el fichero ogLive o no es una imagen ISO. if [ ! -f $TARGETFILE ]; then echo "$PROG: File not found." >&2 exit 2 fi if [ -z "$(file -b $TARGETFILE | grep "ISO.*ogClient")" ]; then echo "$PROG: File is not an OpenGnsys Client ISO image." >&2 exit 2 fi # Obtener la clave actual de acceso a Samba para restaurarla tras la descarga. if [ -f $OGINITRD ]; then SAMBAPASS=$(gzip -dc $OGINITRD | \ cpio -i --to-stdout scripts/ogfunctions 2>&1 | \ grep "^[ ].*OPTIONS=" | \ sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/') fi # Hacer copia de seguridad del ogLive actual. rm -fr ${OGCLIENTDIR}.old mv -f $OGCLIENTDIR ${OGCLIENTDIR}.old # Montar la imagen ISO del ogclient, actualizar ficheros y desmontar. TMPDIR=/tmp/${OGLIVEFILE%.iso} mkdir -p $TMPDIR mount -o loop,ro $TARGETFILE $TMPDIR cp -va $TMPDIR/ogclient $OGCLIENTDIR #rsync -irlt $TMPDIR/ogclient $OPENGNSYS/tftpboot umount $TMPDIR # Recuperar la clave de acceso a Samba o solicitar una nueva clave. if [ -n "$SAMBAPASS" ]; then echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | $OPENGNSYS/bin/setsmbpass else $OPENGNSYS/bin/setsmbpass fi # Establecer los permisos. find -L $OGCLIENTDIR -type d -exec chmod 755 {} \; find -L $OGCLIENTDIR -type f -exec chmod 644 {} \; chown -R :opengnsys $OGCLIENTDIR # Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache cp -av $OGCLIENTDIR/{ogvmlinuz,oginitrd.img}* $OPENGNSYS/tftpboot # Montar SquashFS para comprobar versión de Rsync. mount -o loop,ro $OGCLIENTDIR/ogclient.sqfs $TMPDIR # Si versión Rsync de servidor > cliente, enlazar a fichero compilado. RSYNCSERV=$(rsync --version 2>/dev/null | awk '/protocol/ {print $6}') RSYNCCLNT=$(chroot $TMPDIR /usr/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}') if [ -z "$RSYNCSERV" -o ${RSYNCSERV:-0} -gt ${RSYNCCLNT:-1} ]; then [ -e $OPENGNSYS/client/bin/rsync-$RSYNCSERV ] && mv -f $OPENGNSYS/client/bin/rsync-$RSYNCSERV $OPENGNSYS/client/bin/rsync else # Si no, renombrar fichero compilado con nº de protocolo. [ -e $OPENGNSYS/client/bin/rsync ] && mv -f $OPENGNSYS/client/bin/rsync $OPENGNSYS/client/bin/rsync-$($OPENGNSYS/client/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}') fi # Desmontar SquashFS. umount $TMPDIR rmdir $TMPDIR