mercredi 26 septembre 2012

Newsgroups & SABnzbd


Avant-propos :

Il est possible de télécharger des fichiers (légaux ou pas, ce n'est pas le débat ;-)) grâce à différents outils. Nous allons nous intéresser aux newsgroups et à un des lecteurs de news existants sur la toile, SABnzbd.
SABnzbd est un lecteur de groupes de discussion multi-platforme open source. Il a l'avantage de pouvoir être utilisé en tant que service, configurable via une page internet et simplifie le téléchargement de fichiers.
Il est écrit en python, ce qui va nous permettre de comprendre comment installer python et ses modules (internes et externes) sur la raspberry pi et les utiliser.

Pré-requis :

SABnzbd requiert différents paquets avant l'installation de celui-ci :
  • Python (version 2.5.x, 2.6.x, 2.7.x (recommandé)) - Pas encore la version 3.0
  • La librairie python Cheetah (moteur de templates)
  • La librairie python yEnc (encodage/décodage)
  • La librairie python sqlite
  • La librairie python openssl
  • La librairie python CherryPi
  • binaire par2 et unrar

Les différents modules python demandés ne sont, nativement, pas présents sur buildroot, donc il va falloir les installer.


Installation de Python et de ses modules :


Python 2.7


Python est un paquet, nativement, présent dans le menuconfig de buildroot, dans le sous menu "langages interpréteur ...". En le sélectionnant, le menu des modules python apparaît.

# make menuconfig
  Package Selection for the target --->
      Interpreter languages and scripting --->
      [*] python



Librairie python Cheetah


L'archive python-cheetah.tar.gz réunit le dossier (python-cheetah) et les fichiers (Config.in et python-cheetah.mk) permettant l'installation de ce module sur le système de fichiers.

fichier Config.in :

config BR2_PACKAGE_PYTHON_CHEETAH
 bool "python-cheetah"
 depends on BR2_PACKAGE_PYTHON
 help
   Cheetah is an open source template engine and code generation tool.

   http://pypi.python.org/pypi/Cheetah/2.4.4


fichier python-cheetah.mk :

#############################################################
#
# python-cheetah
#
#############################################################

PYTHON_CHEETAH_VERSION = 2.4.4
PYTHON_CHEETAH_SOURCE  = Cheetah-$(PYTHON_CHEETAH_VERSION).tar.gz
PYTHON_CHEETAH_SITE    = http://pypi.python.org/packages/source/C/Cheetah

PYTHON_CHEETAH_DEPENDENCIES = python

define PYTHON_CHEETAH_BUILD_CMDS
 (cd $(@D); $(HOST_DIR)/usr/bin/python setup.py build_py)
  
 (cd $(@D); \
     PYTHONXCPREFIX="$(STAGING_DIR)/usr/" \
            CC="$(TARGET_CC) -pthread" \
     LDSHARED="$(TARGET_CC) -pthread -shared -Wl,-O1,--sort-common,--as-needed" \
     CFLAGS="-fno-strict-aliasing -I$(STAGING_DIR)/usr/include/python2.7 $(CFLAGS)" \
     LDFLAGS="-L$(STAGING_DIR)/lib -L$(STAGING_DIR)/usr/lib $(LDFLAGS)" \
     "$(HOST_DIR)"/usr/bin/python setup.py build_ext \
     --include-dirs="$(STAGING_DIR)"/usr/include \
     --library-dirs="$(STAGING_DIR)"/usr/lib)
endef

define PYTHON_CHEETAH_INSTALL_TARGET_CMDS
 #~ (cd $(@D); $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr)
 (cd $(@D); PYTHONPATH=$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages \
 $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr)
endef

$(eval $(call GENTARGETS))

Contrairement à des modules python dits "pures", Cheetah a une partie (_namemapper.c) de sa librairie codée en C. C'est pourquoi, nous avons besoin du cross-compilateur pour compiler la librairie, avec la définition des différents chemins.

Pour l'installer sous buildroot, nous allons, dans un premier temps, décompresser l'archive dans le dossier package, puis compléter la configuration générale des paquets (Config.in).

# tar xzf python-cheetah.tar.gz -C BUILDROOT_PATH/package
# vim BUILDROOT_PATH/package/Config.in

menu "external python modules"
source "package/python-dpkt/Config.in"
source "package/python-id3/Config.in"
source "package/python-mad/Config.in"
source "package/python-netifaces/Config.in"
source "package/python-pygame/Config.in"
source "package/python-serial/Config.in"
source "package/python-setuptools/Config.in"
source "package/python-cheetah/Config.in"
endmenu

# make

Librairie python OpenSSL, yEnc et Sqlite3


Pour les archives python-openssl.tar.gz, python-sqlite.tar.gz et python-yenc.tar.gz, "même combat" que pour la librairie Cheetah.

# tar xzf python-yenc.tar.gz -C BUILDROOT_PATH/package
# tar xzf python-sqlite.tar.gz -C BUILDROOT_PATH/package
# tar xzf python-openssl.tar.gz -C BUILDROOT_PATH/package
# vim BUILDROOT_PATH/package/Config.in

menu "external python modules"
source "package/python-dpkt/Config.in"
source "package/python-id3/Config.in"
source "package/python-mad/Config.in"
source "package/python-netifaces/Config.in"
source "package/python-pygame/Config.in"
source "package/python-serial/Config.in"
source "package/python-setuptools/Config.in"
source "package/python-cheetah/Config.in"
source "package/python-openssl/Config.in"
source "package/python-sqlite/Config.in"
source "package/python-yenc/Config.in"
endmenu

# make



Librairie CherryPy


La librairie python CherryPy est, quant à elle, entièrement en python, donc une variante simplifiée du makefile pour l'installation de celle-ci sur le système de fichiers.

L'archive python-cherrypy.tar.gz devra être décompressée dans le sous dossier "package" et il faudra modifier le fichier de configuration général.

Fichier Config.in :

config BR2_PACKAGE_PYTHON_CHERRYPY
    bool "python-cherrypy"
    depends on BR2_PACKAGE_PYTHON
    help
      CherryPy allows developers to build web applications in much the same way 
      they would build any other object-oriented Python program. 
      This results in smaller source code developed in less time.

      http://www.cherrypy.org/

Fichier python-cherrypy.mk :

#############################################################
#
# python-cherrypy
#
#############################################################

PYTHON_CHERRYPY_VERSION = 3.2.2
PYTHON_CHERRYPY_SOURCE = CherryPy-$(PYTHON_CHERRYPY_VERSION).tar.gz
PYTHON_CHERRYPY_SITE = http://download.cherrypy.org/cherrypy/$(PYTHON_CHERRYPY_VERSION)

PYTHON_CHERRYPY_DEPENDENCIES = python

define PYTHON_CHERRYPY_BUILD_CMDS
    (cd $(@D); $(HOST_DIR)/usr/bin/python setup.py build)
endef

define PYTHON_CHERRYPY_INSTALL_TARGET_CMDS
    (cd $(@D); PYTHONPATH=$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages \
 $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr)
endef

$(eval $(call GENTARGETS))

Le fichier de configuration général :

# vim BUILDROOT_PATH/package/Config.in

menu "external python modules"
source "package/python-dpkt/Config.in"
source "package/python-id3/Config.in"
source "package/python-mad/Config.in"
source "package/python-netifaces/Config.in"
source "package/python-pygame/Config.in"
source "package/python-serial/Config.in"
source "package/python-setuptools/Config.in"
source "package/python-cheetah/Config.in"
source "package/python-openssl/Config.in"
source "package/python-sqlite/Config.in"
source "package/python-yenc/Config.in"
source "package/python-cherrypy/Config.in"
endmenu

Binaire Par2


Les fichiers "*.par" sont des fichiers de flux de données redondants au cas ou un des fichiers venaient à être perdu ou corrompu. type de fichiers très utilisé dans les newsgroups.

L'archive par2cmdline.tar.gz est, comme les autres paquets, destinée à être ajoutée dans le sous dossier "package" de buildroot, puisque nativement, il n'est pas présent.
Cette archive contient les deux fichiers principaux (Config.in et par2cmdline.mk) et un patch pour une compilation sans accros.

fichier Config.in :

config BR2_PACKAGE_PAR2CMDLINE
 bool "par2cmdline"
 help
   Providing a tool to apply the data-recovery capability concepts of RAID-like systems 
   to the posting & recovery of multi-part archives on Usenet. 

fichier par2cmdline.mk :

#############################################################
#
# par2cmdline
#
#############################################################

PAR2CMDLINE_VERSION = 0.4
PAR2CMDLINE_SOURCE = par2cmdline-$(PAR2CMDLINE_VERSION).tar.gz
PAR2CMDLINE_SITE = http://sourceforge.net/projects/parchive/files/par2cmdline/$(PAR2CMDLINE_VERSION)
PAR2CMDLINE_INSTALL_STAGING = YES

# avoid enable static option in makefile
SHARED_STATIC_LIBS_OPTS = --enable-shared

$(eval $(call AUTOTARGETS))

Patch :

diff -ruN par2cmdline-0.4/reedsolomon.cpp par2cmdline-0.4_modif/reedsolomon.cpp
--- par2cmdline-0.4/reedsolomon.cpp 2003-05-26 20:01:31.000000000 +0200
+++ par2cmdline-0.4_modif/reedsolomon.cpp 2012-09-13 11:37:13.000000000 +0200
@@ -51,7 +51,7 @@
   }
 }
 
-bool ReedSolomon::SetInput(const vector &present)
+template <> bool ReedSolomon::SetInput(const vector &present)
 {
   inputcount = (u32)present.size();
 
@@ -80,7 +80,7 @@
   return true;
 }
 
-bool ReedSolomon::SetInput(u32 count)
+template <> bool ReedSolomon::SetInput(u32 count)
 {
   inputcount = count;
 
@@ -101,7 +101,7 @@
   return true;
 }
 
-bool ReedSolomon::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
+template <> bool ReedSolomon::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
 {
   // Look up the appropriate element in the RS matrix
   Galois8 factor = leftmatrix[outputindex * (datapresent + datamissing) + inputindex];
@@ -189,7 +189,7 @@
 
 // Set which of the source files are present and which are missing
 // and compute the base values to use for the vandermonde matrix.
-bool ReedSolomon::SetInput(const vector &present)
+template <> bool ReedSolomon::SetInput(const vector &present)
 {
   inputcount = (u32)present.size();
 
@@ -233,7 +233,7 @@
 
 // Record that the specified number of source files are all present
 // and compute the base values to use for the vandermonde matrix.
-bool ReedSolomon::SetInput(u32 count)
+template <> bool ReedSolomon::SetInput(u32 count)
 {
   inputcount = count;
 
@@ -267,7 +267,7 @@
   return true;
 }
 
-bool ReedSolomon::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
+template <> bool ReedSolomon::Process(size_t size, u32 inputindex, const void *inputbuffer, u32 outputindex, void *outputbuffer)
 {
   // Look up the appropriate element in the RS matrix

Binaire unrar


Les sources du binaire unrar sont un peu particulières, puisqu'il ne s'agit que d'un simple makefile pour la compilation, l'installation ou la suppression de celui-ci (un peu ce que l'on pourrait trouver dans un projet perso)

Makefile de Unrar :


COMPILE=$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEFINES)
LINK=$(CXX)

WHAT=UNRAR

UNRAR_OBJ=filestr.o recvol.o rs.o scantree.o
LIB_OBJ=filestr.o scantree.o dll.o

OBJECTS=rar.o strlist.o strfn.o pathfn.o savepos.o smallfn.o global.o file.o filefn.o filcreat.o \
 archive.o arcread.o unicode.o system.o isnt.o crypt.o crc.o rawread.o encname.o \
 resource.o match.o timefn.o rdwrfn.o consio.o options.o ulinks.o errhnd.o rarvm.o secpassword.o \
 rijndael.o getbits.o sha1.o extinfo.o extract.o volume.o list.o find.o unpack.o cmddata.o

.cpp.o:
 $(COMPILE) -D$(WHAT) -c $<

all: unrar

install: install-unrar

uninstall: uninstall-unrar

clean:
 @rm -f *.o *.bak *~

unrar: clean $(OBJECTS) $(UNRAR_OBJ)
 @rm -f unrar
 $(LINK) -o unrar $(LDFLAGS) $(OBJECTS) $(UNRAR_OBJ) $(LIBS) 
 $(STRIP) unrar

sfx: WHAT=SFX_MODULE
sfx: clean $(OBJECTS)
 @rm -f default.sfx
 $(LINK) -o default.sfx $(LDFLAGS) $(OBJECTS)
 $(STRIP) default.sfx

lib: WHAT=RARDLL
lib: CXXFLAGS+=$(LIBFLAGS)
lib: clean $(OBJECTS) $(LIB_OBJ)
 @rm -f libunrar.so
 $(LINK) -shared -o libunrar.so $(LDFLAGS) $(OBJECTS) $(LIB_OBJ)

install-unrar:
   install -D unrar $(DESTDIR)/bin/unrar

uninstall-unrar:
   rm -f $(DESTDIR)/bin/unrar

install-lib:
  install libunrar.so $(DESTDIR)/lib

uninstall-lib:
  rm -f $(DESTDIR)/lib/libunrar.so

Le makefile (unrar.mk), fourni avec l'archive unrar.tar.gz a placer dans le sous-dossier "package", va être basé sur l'utilisation de ce makefile.

Fichier unrar.mk :

#############################################################
#
# unrar
#
#############################################################

UNRAR_VERSION = 4.2.4
UNRAR_SOURCE = unrarsrc-$(UNRAR_VERSION).tar.gz
UNRAR_SITE = http://www.rarlab.com/rar
UNRAR_INSTALL_STAGING = YES

define UNRAR_BUILD_CMDS
 $(MAKE) CXX="$(TARGET_CXX)" CXXFLAGS="-O2" DEFINES="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE" STRIP="$(TARGET_STRIP)" --makefile=makefile.unix -C $(@D) all
endef

define UNRAR_INSTALL_STAGING_CMDS
 $(MAKE) DESTDIR="$(STAGING_DIR)/usr" --makefile=makefile.unix -C $(@D) install
endef

define UNRAR_INSTALL_TARGET_CMDS
 $(MAKE) DESTDIR="$(TARGET_DIR)/usr" --makefile=makefile.unix -C $(@D) install
endef

$(eval $(call GENTARGETS))

avec l'appel de macros pour la compilation et l'installation du binaire sur notre système de fichiers.

Installation de SABnzbd

Avec les sources de SABnzbd, il n'y a pas d'installation, à proprement parlé. On peut lancer le binaire depuis n'importe quel dossier de notre système.

Pour cela, on va reconstruire notre système de fichiers avec les nouveaux binaires, et librairies et démarrer la raspberry pi.

Transfert de l'archive de SABnzbd sur la raspberry pi :

# scp SABnzbd-0.7.3-src.tar.gz root@RASPI_IP_ADDR:
# mkdir -p /usr/bin/sabnzbd
# tar xzf SABnzbd-0.7.3-src.tar.gz -C /usr/bin/sabnzbd

Si la décompression de l'archive sur la raspberry pi ne fonctionne pas, c'est qu'il manque quelques paquets de gestions d'archives dans busybox.

Pour l'utilisation, lancer la commande :

# python /usr/bin/sabnzbd/SABnzbd-0.7.3/SABnzbd.py -s -d RASPI_IP_ADDR:8888

L'option "-d" permet d'utiliser le binaire en tant que service (daemon)

Ouvrez votre navigateur favori et entrez l'adresse RASPI_IP_ADDR:8888, vous devriez avoir l'assistant de configuration de SABnzbd.
 

Une fois, la configuration terminée, la fenêtre classique de téléchargement s'ouvre. Vous trouverez sur la toile, un tas de tutoriels pour une configuration plus poussée.

Vous pouvez écrire un script pour le lancement automatique du binaire au démarrage de la carte (cf billet mediatomb).

Amusez-vous bien avec ...

Aucun commentaire:

Enregistrer un commentaire