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. |
---|
9 | PROG=$(basename $0) |
---|
10 | [ "$(pgrep "$PROG")" != "$$" ] && exit |
---|
11 | |
---|
12 | # Variables. |
---|
13 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
14 | PATH=$PATH:$OPENGNSYS/bin |
---|
15 | OGIMG="$OPENGNSYS/images" |
---|
16 | REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg" |
---|
17 | DEFAULTFILE=/etc/default/opengnsys |
---|
18 | source $DEFAULTFILE |
---|
19 | source $OPENGNSYS/lib/ogfunctions.sh |
---|
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 |
---|
24 | source $REPOCFG |
---|
25 | TRACKERURL="http://$IPlocal:6969/announce" |
---|
26 | |
---|
27 | # Directorio de imágenes. |
---|
28 | pushd $OGIMG >/dev/null |
---|
29 | |
---|
30 | # Procesar ficheros de imágenes. |
---|
31 | trap 'echolog Proceso interrumpido; exit' 1 2 3 6 9 15 |
---|
32 | for 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 | echolog "Inicio creación de fichero $TORRENT" |
---|
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 | echolog "Running ctorrent -t \"$IMG\" -u $TRACKERURL -s \"$TORRENT\" -c $DATAFULLSUM -l 4194304" |
---|
60 | nice -n ${BTSEEDER_PRIORITY:-0} ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null |
---|
61 | rm -f "$LOCKFILE" |
---|
62 | if [ -f "$TORRENT" ]; then |
---|
63 | echolog "Fin creación de fichero $TORRENT" |
---|
64 | else |
---|
65 | echolog "ERROR en creación de fichero $TORRENT" |
---|
66 | fi |
---|
67 | # Modificación realizada en la corrección temporal de la incidencia #535 |
---|
68 | break |
---|
69 | done |
---|
70 | |
---|
71 | popd >/dev/null |
---|
72 | |
---|