source: repoman/bin/torrent-creator @ 915580e

configure-oglivelgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 915580e was 07518803, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#881: Add personalization variable for torrents creation priority to default processes file.

  • Property mode set to 100755
File size: 2.6 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"
[07518803]18DEFAULTFILE=/etc/default/opengnsys
19source $DEFAULTFILE
20# No hacer nada si no está definido como repositorio.
21[ "$RUN_OGADMREPO" == "yes" ] || exit 0
[9ee62ad]22# Error si no está bien configurado el repositorio de imágenes.
23[ -d $OGIMG -a -f $REPOCFG ] || exit 1
24source $REPOCFG
25TRACKERURL="http://$IPlocal:6969/announce"
[cc2032b]26
27# Directorio de imágenes.
28pushd $OGIMG >/dev/null
29
30# Procesar ficheros de imágenes.
31trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15
[01aef8db]32for IMG in *.{img,pgz,diff,dsk} */*.{img,pgz,diff,dsk} ; do
[2b2144f]33        # Saltar al siguiente si la imagen está bloqueada o si no existe el fichero.
[edac247]34        LOCKFILE="$IMG.lock"
35        if [ -f "$LOCKFILE" -o ! -f "$IMG" ]; then
[2b2144f]36                continue
37        fi
[cc2032b]38        # Comprobar si ya existe el fichero Torrent para esa imagen.
[d7f9b50a]39        TORRENT="$IMG.torrent" 
[edac247]40        SUMFILE="$IMG.sum"
[d7f9b50a]41        #MD5 completo de todo el fichero imagen
42        SUMFULLFILE="$IMG.full.sum"
[dfcc55a]43        if [ -f "$TORRENT" -a -f "$SUMFULLFILE" ]; then
[cc2032b]44                FILESIZE="$(ls -l $IMG | awk '{print $5}')"
[89a8208]45                read -e TORRFILE TORRSIZE <<<"$(ctorrent -x $TORRENT 2>/dev/null | awk '$1~/<1>/ {print $2,$3}')"
[cc2032b]46                [ "$(basename $IMG)" = "$TORRFILE" -a "[$FILESIZE]" = "$TORRSIZE" ] && continue
47        fi
[edac247]48        # Bloquear imagen, crear ficheros Torrent y Checksum y desbloquear imagen.
[cc2032b]49        echo "`date` : Inicio creación de fichero $TORRENT" >> $LOGFILE
[edac247]50        touch "$LOCKFILE"
51        trap "rm -f $LOCKFILE" 1 2 3 6 9
[d7f9b50a]52        rm -f "$TORRENT" "$SUMFILE"     
53        # datasum de los ultimos megas del fichero para transferencias unicast y multicast
[12e8e382]54        DATASUM=$(tail -c1M "$IMG" | md5sum -b | cut -f1 -d" ")
[edac247]55        echo $DATASUM > "$SUMFILE"
[d7f9b50a]56        # Datasum completo para transferencias torrent
57        DATAFULLSUM=$(md5sum -b "$IMG"| cut -f1 -d" ")
58        echo $DATAFULLSUM > "$SUMFULLFILE"
[07518803]59        nice -n ${BTSEEDER_PRIORITY:-0} ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null
[edac247]60        rm -f "$LOCKFILE"
[cc2032b]61        if [ -f "$TORRENT"  ]; then
62                echo "`date` : Fin creación de fichero $TORRENT" >> $LOGFILE
63        else
64                echo "`date` : ERROR en creación de fichero $TORRENT" >> $LOGFILE
65        fi
[c43b786]66        # Modificación realizada en la corrección temporal de la incidencia #535
67        break   
[cc2032b]68done
[01aef8db]69
[cc2032b]70popd >/dev/null
71
Note: See TracBrowser for help on using the repository browser.