source: repoman/bin/torrent-creator

qndtest
Last change on this file was 07518803, checked in by Ramón M. Gómez <ramongomez@…>, 5 years ago

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

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/bin/bash
2# Genera los ficheros .torrent de las imágenes almacenadas en el repositorio.
3#Version 0.3   Ejecución desde cron cada minuto,
4##  echo "* * * * *   root   /opt/opengnsys/bin/torrent-creator" > /etc/cron.d/torrentcreator
5
6## ver moficifcacione en linea 41 - 46
7
8# Comprobar si el proceso ya está en ejecución.
9PROG=$(basename $0)
10[ "$(pgrep "$PROG")" != "$$" ] && exit
11
12# Variables.
13OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
14PATH=$PATH:$OPENGNSYS/bin
15OGIMG="$OPENGNSYS/images"
16REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg"
17LOGFILE="$OPENGNSYS/log/$PROG.log"
18DEFAULTFILE=/etc/default/opengnsys
19source $DEFAULTFILE
20# No hacer nada si no está definido como repositorio.
21[ "$RUN_OGADMREPO" == "yes" ] || exit 0
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"
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
32for IMG in *.{img,pgz,diff,dsk} */*.{img,pgz,diff,dsk} ; do
33        # Saltar al siguiente si la imagen está bloqueada o si no existe el fichero.
34        LOCKFILE="$IMG.lock"
35        if [ -f "$LOCKFILE" -o ! -f "$IMG" ]; then
36                continue
37        fi
38        # Comprobar si ya existe el fichero Torrent para esa imagen.
39        TORRENT="$IMG.torrent" 
40        SUMFILE="$IMG.sum"
41        #MD5 completo de todo el fichero imagen
42        SUMFULLFILE="$IMG.full.sum"
43        if [ -f "$TORRENT" -a -f "$SUMFULLFILE" ]; then
44                FILESIZE="$(ls -l $IMG | awk '{print $5}')"
45                read -e TORRFILE TORRSIZE <<<"$(ctorrent -x $TORRENT 2>/dev/null | awk '$1~/<1>/ {print $2,$3}')"
46                [ "$(basename $IMG)" = "$TORRFILE" -a "[$FILESIZE]" = "$TORRSIZE" ] && continue
47        fi
48        # Bloquear imagen, crear ficheros Torrent y Checksum y desbloquear imagen.
49        echo "`date` : Inicio creación de fichero $TORRENT" >> $LOGFILE
50        touch "$LOCKFILE"
51        trap "rm -f $LOCKFILE" 1 2 3 6 9
52        rm -f "$TORRENT" "$SUMFILE"     
53        # datasum de los ultimos megas del fichero para transferencias unicast y multicast
54        DATASUM=$(tail -c1M "$IMG" | md5sum -b | cut -f1 -d" ")
55        echo $DATASUM > "$SUMFILE"
56        # Datasum completo para transferencias torrent
57        DATAFULLSUM=$(md5sum -b "$IMG"| cut -f1 -d" ")
58        echo $DATAFULLSUM > "$SUMFULLFILE"
59        nice -n ${BTSEEDER_PRIORITY:-0} ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null
60        rm -f "$LOCKFILE"
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
66        # Modificación realizada en la corrección temporal de la incidencia #535
67        break   
68done
69
70popd >/dev/null
71
Note: See TracBrowser for help on using the repository browser.