[914d834] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Scirpt para la actualizacion de datos en la cache. |
---|
| 4 | # Versión: 0.9.1, 2008/03/17, - integracion eac |
---|
| 5 | # Versión: 0.9.2, 2010/07/27, - integracion opengnsys |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | #1 REPO |
---|
| 10 | #2 nombre del fichero con su extension, tipo /imagen1.img o /ubuntu.iso |
---|
| 11 | #3 Protocolo TORRENT | MULTICAST | UNICAST |
---|
| 12 | #4 opciones protocolo |
---|
| 13 | #5 opciones de update cache |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | PROG="$(basename $0)" |
---|
| 17 | if [ $# -lt 4 ]; then |
---|
| 18 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE" |
---|
| 19 | exit $? |
---|
| 20 | fi |
---|
| 21 | |
---|
| 22 | REPOSITORIO=$1 |
---|
| 23 | PROTOCOLO=$3 |
---|
| 24 | OPTPROTOCOLO=$4 |
---|
| 25 | echo $REPOSITORIO $PROTOCOLO $OPTPROTOCOLO |
---|
| 26 | # Si el repositorio local CACHE no existe salimos. |
---|
| 27 | if ! $(ogFindCache >/dev/null); then |
---|
| 28 | ogRaiseError $OG_ERR_NOTFOUND "CACHE" |
---|
| 29 | exit $? |
---|
| 30 | fi |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`) |
---|
| 34 | FILESIZE=$(ls -sk $(ogGetPath $1 $2) | cut -f1 -d" ") |
---|
| 35 | |
---|
| 36 | if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] |
---|
| 37 | then |
---|
| 38 | echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE" |
---|
| 39 | exit 1 |
---|
| 40 | fi |
---|
| 41 | |
---|
| 42 | ogUpdateCacheIsNecesary $1 $2 || exit 0 |
---|
| 43 | |
---|
| 44 | ogMountCache |
---|
| 45 | |
---|
| 46 | ## Si no existe, crear subdirectorio para el fichero en la cache. |
---|
| 47 | IMGDIR=$(ogGetParentPath "$1" "/$2") |
---|
| 48 | if [ $? != 0 ]; then |
---|
| 49 | echo "[5] Crear subdirectorio del fichero \"$2 $(dirname "$2")." |
---|
| 50 | ogMakeDir "CACHE" $(dirname "/$2") |
---|
| 51 | IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $? |
---|
| 52 | fi |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | echo "ogCopyFile $1 $2.torrent absolute $OGCAC$OGIMG" |
---|
| 56 | ogCopyFile $1 $2.torrent $OGCAC$OGIMG |
---|
| 57 | #TODO: comprobar que el tracker definido en el fichero es correcto. |
---|
| 58 | case "$PROTOCOLO" in |
---|
| 59 | torrent | TORRENT ) |
---|
| 60 | #[ -z $OPTPROTOCOLO ] && OPTPROTOCOL=leecher:10 |
---|
| 61 | echo "ogTorrentStart CACHE $2.torrent $4" |
---|
| 62 | ogTorrentStart CACHE $2.torrent $4 |
---|
| 63 | ;; |
---|
| 64 | multicast | MULTICAST ) |
---|
| 65 | echo "determinando puerto principal y auxiliar." |
---|
| 66 | PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":") |
---|
| 67 | let PORTAUX=$PORT+1 |
---|
| 68 | echo "comprobando que el servidor está activo" |
---|
| 69 | if (nmap -n -sU -p $PORTAUX $repo | grep open) |
---|
| 70 | then |
---|
| 71 | ogMcastReceiverFile $PORT CACHE $2 |
---|
| 72 | else |
---|
| 73 | echo "solicita la apertura: hose $repo 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"" |
---|
| 74 | hose $repo 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO" |
---|
| 75 | #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2" |
---|
| 76 | sleep 30 |
---|
| 77 | ogMcastReceiverFile $PORT CACHE $2 |
---|
| 78 | fi |
---|
| 79 | ;; |
---|
| 80 | unicast | UNICAST ) |
---|
| 81 | echo "unicast" |
---|
| 82 | ;; |
---|
| 83 | esac |
---|
| 84 | |
---|
| 85 | if ogUpdateCacheIsNecesary $1 $2 |
---|
| 86 | then |
---|
| 87 | echo "algo ha fallado" |
---|
| 88 | exit 1 |
---|
| 89 | else |
---|
| 90 | echo "updateCache ok" |
---|
| 91 | exit 0 |
---|
| 92 | fi |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | # |
---|