source: repoman/bin/torrent-creator @ 2b1ed11

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 2b1ed11 was d6bffcc, checked in by irina <irinagomez@…>, 9 years ago

#678 unidades organizativas separadas: los script deleteimagen y torrent-creator permiten imágenes dentro de subdirectorios de /opt/opengnsys/images

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

  • Property mode set to 100755
File size: 2.4 KB
RevLine 
[cc2032b]1#!/bin/bash
[9ee62ad]2# Genera los ficheros .torrent de las imágenes almacenadas en el repositorio.
[cc2032b]3#Version 0.3   Ejecución desde cron cada minuto,
[9ee62ad]4##  echo "* * * * *   root   /opt/opengnsys/bin/torrent-creator" > /etc/cron.d/torrentcreator
[cc2032b]5
[edac247]6## ver moficifcacione en linea 41 - 46
[cc2032b]7
[9ee62ad]8# Comprobar si el proceso ya está en ejecución.
[cc2032b]9PROG=$(basename $0)
[9ee62ad]10[ "$(pgrep "$PROG")" != "$$" ] && exit
11
12# Variables.
[cc2032b]13OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
14PATH=$PATH:$OPENGNSYS/bin
15OGIMG="$OPENGNSYS/images"
[9ee62ad]16REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg"
[cc2032b]17LOGFILE="$OPENGNSYS/log/$PROG.log"
[9ee62ad]18# Error si no está bien configurado el repositorio de imágenes.
19[ -d $OGIMG -a -f $REPOCFG ] || exit 1
20source $REPOCFG
21TRACKERURL="http://$IPlocal:6969/announce"
[cc2032b]22
23# Directorio de imágenes.
24pushd $OGIMG >/dev/null
25
26# Procesar ficheros de imágenes.
27trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15
[d6bffcc]28for IMG in *.{img,pgz,diff} */*.{img,pgz,diff} ; do
[2b2144f]29        # Saltar al siguiente si la imagen está bloqueada o si no existe el fichero.
[edac247]30        LOCKFILE="$IMG.lock"
31        if [ -f "$LOCKFILE" -o ! -f "$IMG" ]; then
[2b2144f]32                continue
33        fi
[cc2032b]34        # Comprobar si ya existe el fichero Torrent para esa imagen.
[d7f9b50a]35        TORRENT="$IMG.torrent" 
[edac247]36        SUMFILE="$IMG.sum"
[d7f9b50a]37        #MD5 completo de todo el fichero imagen
38        SUMFULLFILE="$IMG.full.sum"
[dfcc55a]39        if [ -f "$TORRENT" -a -f "$SUMFULLFILE" ]; then
[cc2032b]40                FILESIZE="$(ls -l $IMG | awk '{print $5}')"
[89a8208]41                read -e TORRFILE TORRSIZE <<<"$(ctorrent -x $TORRENT 2>/dev/null | awk '$1~/<1>/ {print $2,$3}')"
[cc2032b]42                [ "$(basename $IMG)" = "$TORRFILE" -a "[$FILESIZE]" = "$TORRSIZE" ] && continue
43        fi
[edac247]44        # Bloquear imagen, crear ficheros Torrent y Checksum y desbloquear imagen.
[cc2032b]45        echo "`date` : Inicio creación de fichero $TORRENT" >> $LOGFILE
[edac247]46        touch "$LOCKFILE"
47        trap "rm -f $LOCKFILE" 1 2 3 6 9
[d7f9b50a]48        rm -f "$TORRENT" "$SUMFILE"     
49        # datasum de los ultimos megas del fichero para transferencias unicast y multicast
[12e8e382]50        DATASUM=$(tail -c1M "$IMG" | md5sum -b | cut -f1 -d" ")
[edac247]51        echo $DATASUM > "$SUMFILE"
[d7f9b50a]52        # Datasum completo para transferencias torrent
53        DATAFULLSUM=$(md5sum -b "$IMG"| cut -f1 -d" ")
54        echo $DATAFULLSUM > "$SUMFULLFILE"
55        nice -8 ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null
[edac247]56        rm -f "$LOCKFILE"
[cc2032b]57        if [ -f "$TORRENT"  ]; then
58                echo "`date` : Fin creación de fichero $TORRENT" >> $LOGFILE
59        else
60                echo "`date` : ERROR en creación de fichero $TORRENT" >> $LOGFILE
61        fi
[c43b786]62        # Modificación realizada en la corrección temporal de la incidencia #535
63        break   
[cc2032b]64done
65       
66popd >/dev/null
67
Note: See TracBrowser for help on using the repository browser.