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