source: server/bin/installoglive @ 2f9cd767

918-git-images-111dID-1020_logrotateBugID-1037_Mostrar.TipoDisco.WebID-1038_Muestra.el.numero.de.ordenadoresID-1039_Asignar_Disco.Particion.Imagen.AccesoRemotoID-824_Iniciar.Sistema.Restauradoblank-panelconfigfiledebian-pkgdevel-ogadmserver-for-masterdisk-imagemainmaster-1037opengnsys-1.1.1dprepjlinkqndtestwebconsole3
Last change on this file since 2f9cd767 was fcac41e, checked in by ramon <ramongomez@…>, 7 years ago

#766 #754: Adaptar cambios de revisiones r5060, r5114 y r5116 en versión 1.1.0

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

  • Property mode set to 100755
File size: 4.0 KB
Line 
1#!/bin/bash
2# installoglive - instala cliente ogLive.
3# Nota: Si no se especifica fichero local, el usuario debe elegir
4#       el número del ogLive que desea descargar e instalar.
5# Uso:  installoglive [fichero]
6# Autor:   Ramón M. Gómez - ETSII Univ. Sevilla
7# Fecha:   2015-01-26
8# Versión: 1.1 - Posibilidad para instalar fichero ogLive local.
9# Autor:   Ramón M. Gómez - ETSII Univ. Sevilla
10# Fecha:   2015-11-06
11# Versión: 1.1.0a - Adaptar la versión de Rsync de cliente y servidor.
12# Autor:   Ramón M. Gómez - ETSII Univ. Sevilla
13# Fecha:   2015-12-16
14
15
16# Control de acceso.
17PROG=$(basename $0)
18if [ "$USER" != "root" ]; then
19        echo "$PROG: Need to be root." >&2
20        exit 1
21fi
22
23# Constantes.
24DOWNLOADURL="http://opengnsys.es/downloads"
25OPENGNSYS=/opt/opengnsys
26OGCLIENTDIR=/opt/opengnsys/tftpboot/ogclient
27OGINITRD=$OGCLIENTDIR/oginitrd.img
28OGVMLINUZ=$OGCLIENTDIR/ogvmlinuz
29OGSQFS=$OGCLIENTDIR/ogclient.sqfs
30
31if [ -n "$1" ]; then
32        # Si se recibe un parámetro, utilizar fichero ogLive local.
33        TARGETFILE="$1"
34        OGLIVEFILE=$(basename $TARGETFILE)
35else
36        # Sin parámetros, listar todos los ficheros ogLive descargables.
37        OGLIVE=( $(wget $DOWNLOADURL -O - 2>/dev/null|grep ogLive.*iso) )
38        NISOS=${#OGLIVE[@]}
39        echo "Descargas disponibles (+- = instalado):"
40        for i in $(seq 1 $NISOS); do
41                [ -e $OPENGNSYS/lib/${OGLIVE[i-1]} ] && OGLIVE[i-1]="+-${OGLIVE[i-1]}"
42        done
43        select opt in ${OGLIVE[@]}; do
44                [ -n "$opt" ] && OGLIVEFILE=${opt/+-/} && break
45        done
46
47        # Tamaño del fichero a descargar.
48        SOURCELENGTH=$(LANG=C wget --spider $DOWNLOADURL/$OGLIVEFILE 2>&1 | awk '/Length:/ {print $2}')
49        [ -n "$SOURCELENGTH" ] || exit
50
51        # Descarga de ogLive.
52        TARGETFILE=$OPENGNSYS/lib/$OGLIVEFILE
53        wget $DOWNLOADURL/$OGLIVEFILE -O $TARGETFILE || exit
54fi
55
56# Error si no existe el fichero ogLive o no es una imagen ISO.
57if [ ! -f $TARGETFILE ]; then
58        echo "$PROG: File not found." >&2
59        exit 2
60fi
61if [ -z "$(file -b $TARGETFILE | grep "ISO.*ogClient")" ]; then
62        echo "$PROG: File is not an OpenGnsys Client ISO image." >&2
63        exit 2
64fi
65
66# Obtener la clave actual de acceso a Samba para restaurarla tras la descarga.
67if [ -f $OGINITRD ]; then
68        SAMBAPASS=$(gzip -dc $OGINITRD | \
69        cpio -i --to-stdout scripts/ogfunctions 2>&1 | \
70                        grep "^[        ].*OPTIONS=" | \
71                        sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')
72fi
73
74# Hacer copia de seguridad del ogLive actual.
75rm -fr ${OGCLIENTDIR}.old
76mv -f $OGCLIENTDIR ${OGCLIENTDIR}.old
77
78# Montar la imagen ISO del ogclient, actualizar ficheros y desmontar.
79TMPDIR=/tmp/${OGLIVEFILE%.iso}
80mkdir -p $TMPDIR
81mount -o loop,ro $TARGETFILE $TMPDIR
82cp -va $TMPDIR/ogclient $OGCLIENTDIR
83#rsync -irlt $TMPDIR/ogclient $OPENGNSYS/tftpboot
84umount $TMPDIR
85
86# Recuperar la clave de acceso a Samba o solicitar una nueva clave.
87if [ -n "$SAMBAPASS" ]; then
88        echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | $OPENGNSYS/bin/setsmbpass
89else
90        $OPENGNSYS/bin/setsmbpass
91fi
92
93# Establecer los permisos.
94find -L $OGCLIENTDIR -type d -exec chmod 755 {} \;
95find -L $OGCLIENTDIR -type f -exec chmod 644 {} \;
96chown -R :opengnsys $OGCLIENTDIR
97
98# Ofrecer md5 del kernel y vmlinuz para ogupdateinitrd en cache
99cp -av $OGCLIENTDIR/{ogvmlinuz,oginitrd.img}* $OPENGNSYS/tftpboot
100
101# Montar SquashFS para comprobar versión de Rsync.
102mount -o loop,ro $OGCLIENTDIR/ogclient.sqfs $TMPDIR
103# Si versión Rsync de servidor > cliente, enlazar a fichero compilado.
104RSYNCSERV=$(rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
105RSYNCCLNT=$(chroot $TMPDIR /usr/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
106if [ -z "$RSYNCSERV" -o ${RSYNCSERV:-0} -gt ${RSYNCCLNT:-1} ]; then
107        [ -e $OPENGNSYS/client/bin/rsync-$RSYNCSERV ] && mv -f $OPENGNSYS/client/bin/rsync-$RSYNCSERV $OPENGNSYS/client/bin/rsync
108else
109        # Si no, renombrar fichero compilado con nº de protocolo.
110        [ -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}')
111fi
112# Desmontar SquashFS.
113umount $TMPDIR
114rmdir $TMPDIR
115# Versión del ogLive instalado.
116echo "${OGLIVEFILE%.*}" > $INSTALL_TARGET/doc/veroglive.txt
Note: See TracBrowser for help on using the repository browser.