[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 | |
---|
| 6 | |
---|
[9ee62ad] | 7 | # Comprobar si el proceso ya está en ejecución. |
---|
[cc2032b] | 8 | PROG=$(basename $0) |
---|
[9ee62ad] | 9 | [ "$(pgrep "$PROG")" != "$$" ] && exit |
---|
| 10 | |
---|
| 11 | # Variables. |
---|
[cc2032b] | 12 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
| 13 | PATH=$PATH:$OPENGNSYS/bin |
---|
| 14 | OGIMG="$OPENGNSYS/images" |
---|
[9ee62ad] | 15 | REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg" |
---|
[cc2032b] | 16 | LOGFILE="$OPENGNSYS/log/$PROG.log" |
---|
[9ee62ad] | 17 | # Error si no está bien configurado el repositorio de imágenes. |
---|
| 18 | [ -d $OGIMG -a -f $REPOCFG ] || exit 1 |
---|
| 19 | source $REPOCFG |
---|
| 20 | TRACKERURL="http://$IPlocal:6969/announce" |
---|
[cc2032b] | 21 | |
---|
| 22 | # Directorio de imágenes. |
---|
| 23 | pushd $OGIMG >/dev/null |
---|
| 24 | |
---|
| 25 | # Procesar ficheros de imágenes. |
---|
| 26 | trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15 |
---|
[0fbc05e] | 27 | for IMG in *.{img,pgz}; do |
---|
[2b2144f] | 28 | # Saltar al siguiente si la imagen está bloqueada o si no existe el fichero. |
---|
| 29 | if [ -f "$IMG.lock" -o ! -f "$IMG" ]; then |
---|
| 30 | continue |
---|
| 31 | fi |
---|
[cc2032b] | 32 | # Comprobar si ya existe el fichero Torrent para esa imagen. |
---|
| 33 | TORRENT="$IMG.torrent" |
---|
| 34 | if [ -f "$TORRENT" ]; then |
---|
| 35 | FILESIZE="$(ls -l $IMG | awk '{print $5}')" |
---|
| 36 | read -e TORRFILE TORRSIZE <<<"$(ctorrent -x $TORRENT | awk '$1~/<1>/ {print $2,$3}')" |
---|
| 37 | [ "$(basename $IMG)" = "$TORRFILE" -a "[$FILESIZE]" = "$TORRSIZE" ] && continue |
---|
| 38 | fi |
---|
| 39 | # Crear fichero Torrent. |
---|
| 40 | echo "`date` : Inicio creación de fichero $TORRENT" >> $LOGFILE |
---|
| 41 | rm -f "$TORRENT" |
---|
[6905716c] | 42 | ##### ADV v. 1.0 23/02/2011 |
---|
| 43 | rm -f $IMG.sum |
---|
| 44 | DATASUM=`md5sum "$IMG" | cut -f1 -d" "` |
---|
| 45 | echo $DATASUM > $IMG.sum |
---|
| 46 | nice -8 ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATASUM |
---|
| 47 | #### ADV v. 1.0 23/02/2011 |
---|
| 48 | |
---|
[cc2032b] | 49 | nice -8 ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" |
---|
| 50 | if [ -f "$TORRENT" ]; then |
---|
| 51 | echo "`date` : Fin creación de fichero $TORRENT" >> $LOGFILE |
---|
| 52 | else |
---|
| 53 | echo "`date` : ERROR en creación de fichero $TORRENT" >> $LOGFILE |
---|
| 54 | fi |
---|
| 55 | done |
---|
| 56 | |
---|
| 57 | popd >/dev/null |
---|
| 58 | |
---|