From cc2032b5d0920207b17e90c007541038f9fde084 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 9 Jul 2010 12:06:26 +0000 Subject: [PATCH] =?UTF-8?q?Script=20de=20creaci=C3=B3n=20de=20ficheros=20.?= =?UTF-8?q?torrent=20para=20el=20Repositorio=20de=20im=C3=A1genes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://opengnsys.es/svn/trunk@1088 a21b9725-9963-47de-94b9-378ad31fedc9 --- installer/opengnsys_installer.sh | 2 +- installer/opengnsys_update.sh | 2 +- repoman/bin/torrent-creator | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100755 repoman/bin/torrent-creator diff --git a/installer/opengnsys_installer.sh b/installer/opengnsys_installer.sh index 2b369f51..bae7b025 100755 --- a/installer/opengnsys_installer.sh +++ b/installer/opengnsys_installer.sh @@ -31,7 +31,7 @@ INSTALL_TARGET=/opt/opengnsys LOG_FILE=/tmp/opengnsys_installation.log # Array con las dependencias -DEPENDENCIES=( subversion apache2 php5 mysql-server php5-mysql nfs-kernel-server dhcp3-server udpcast bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential libmysqlclient15-dev wget doxygen graphviz bittornado ) +DEPENDENCIES=( subversion apache2 php5 mysql-server php5-mysql nfs-kernel-server dhcp3-server udpcast bittorrent tftp-hpa tftpd-hpa syslinux openbsd-inetd update-inetd build-essential libmysqlclient15-dev wget doxygen graphviz bittornado ctorrent ) # Datos de base de datos diff --git a/installer/opengnsys_update.sh b/installer/opengnsys_update.sh index 077ed944..6ab7f2f8 100755 --- a/installer/opengnsys_update.sh +++ b/installer/opengnsys_update.sh @@ -18,7 +18,7 @@ fi # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). PROGRAMDIR=$(readlink -e $(dirname "$0")) -DEPS="rsync gcc" +DEPS="rsync gcc ctorrent" if [ -d "$PROGRAMDIR/../installer" ]; then USESVN=0 else diff --git a/repoman/bin/torrent-creator b/repoman/bin/torrent-creator new file mode 100755 index 00000000..a9eb6732 --- /dev/null +++ b/repoman/bin/torrent-creator @@ -0,0 +1,49 @@ +#!/bin/bash + +#Version 0.3 Ejecución desde cron cada minuto, +# Trabaja sólo con la primera imagen que tenga asociado un fichero .doTorrent +## echo " * * * * * root /opt/opengnsys/bin/torrent-creator" > /etc/cron.d/torrent-creator.cron + + +# Variables. +PROG=$(basename $0) +OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} +PATH=$PATH:$OPENGNSYS/bin +OGIMG="$OPENGNSYS/images" +source $OPENGNSYS/etc/ogAdmRepo.cfg +TRACKERURL="http://$IPlocal:6969/announce" +LOGFILE="$OPENGNSYS/log/$PROG.log" + +if [ "$(pgrep "$PROG")" != "$$" ]; then + echo "`date` : Proceso ya en ejecución" >> $LOGFILE + exit +fi + +# Directorio de imágenes. +pushd $OGIMG >/dev/null + +# Procesar ficheros de imágenes. +trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15 +for IMG in *.img; do + # Saltar al siguiente si no existe el fichero. + [ -f "$IMG" ] || continue + # Comprobar si ya existe el fichero Torrent para esa imagen. + TORRENT="$IMG.torrent" + if [ -f "$TORRENT" ]; then + FILESIZE="$(ls -l $IMG | awk '{print $5}')" + read -e TORRFILE TORRSIZE <<<"$(ctorrent -x $TORRENT | awk '$1~/<1>/ {print $2,$3}')" + [ "$(basename $IMG)" = "$TORRFILE" -a "[$FILESIZE]" = "$TORRSIZE" ] && continue + fi + # Crear fichero Torrent. + echo "`date` : Inicio creación de fichero $TORRENT" >> $LOGFILE + rm -f "$TORRENT" + nice -8 ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" + if [ -f "$TORRENT" ]; then + echo "`date` : Fin creación de fichero $TORRENT" >> $LOGFILE + else + echo "`date` : ERROR en creación de fichero $TORRENT" >> $LOGFILE + fi +done + +popd >/dev/null +