source: repoman/bin/torrent-creator @ 813f617

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 813f617 was 6905716c, checked in by adv <adv@…>, 14 years ago

integracion 1.0 - /bin del repo - tiket:300

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

  • Property mode set to 100755
File size: 1.9 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
7# Comprobar si el proceso ya está en ejecución.
8PROG=$(basename $0)
9[ "$(pgrep "$PROG")" != "$$" ] && exit
10
11# Variables.
12OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
13PATH=$PATH:$OPENGNSYS/bin
14OGIMG="$OPENGNSYS/images"
15REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg"
16LOGFILE="$OPENGNSYS/log/$PROG.log"
17# Error si no está bien configurado el repositorio de imágenes.
18[ -d $OGIMG -a -f $REPOCFG ] || exit 1
19source $REPOCFG
20TRACKERURL="http://$IPlocal:6969/announce"
21
22# Directorio de imágenes.
23pushd $OGIMG >/dev/null
24
25# Procesar ficheros de imágenes.
26trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15
27for IMG in *.{img,pgz}; do
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
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"
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       
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
55done
56       
57popd >/dev/null
58
Note: See TracBrowser for help on using the repository browser.