Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: leogtz en 12 Enero 2011, 01:39 am



Título: [BASH] Script instalación de módulos Perl
Publicado por: leogtz en 12 Enero 2011, 01:39 am
Hola, acabo de hacer este script para la instalación de módulos en Perl.

El script checa si el módulo está instalado, sino lo está pregunta si se quiere instalar dicho módulo, si sí se quiere instalar, descarga el módulo desde CPAN y lo instala normalmente.


Código
  1. #!/bin/bash
  2. # Leo Gutiérrez R. leorocko13@hotmail.com
  3. [ ${UID} != 0 ] && {
  4. echo -e "Se requieren privilegios de Root";
  5. exit 1;
  6. }
  7.  
  8. MODULE_NAME="Math::BigInt::Random";
  9. URL_MODULE="http://search.cpan.org/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz";
  10. PATH_MODULE="Math-BigInt-Random-0.04.tar.gz";
  11.  
  12. perl -M${MODULE_NAME} -e 1 2> /dev/null || {
  13. echo -e "\aEl módulo no existe\n¿Desea instalarlo:?";
  14. opciones="Sí No";
  15. select opt in ${opciones}
  16. do
  17. if [ "${opt}" = "Sí" ]
  18. then
  19.  
  20. wget "${URL_MODULE}";
  21. tar zxvf "${PATH_MODULE}";
  22. cd "${PATH_MODULE%\.tar.gz}" 2> /dev/null || {
  23. echo -e "\aError abriendo directorio ${1%%.*}";
  24. exit 1;
  25. }
  26. perl Makefile.PL
  27. make
  28. make test
  29. make install
  30. exit 0;
  31.  
  32. elif [ "${opt}" = "No" ]
  33. then
  34.  
  35. echo -e "\aLa instalación del módulo es necesaria";
  36. exit 1;
  37.  
  38. fi
  39. done
  40. }
  41.  

Código
  1. leo@leo-desktop:~/Escritorio$ sudo bash shell.sh
  2. El módulo no existe
  3. ¿Desea instalarlo:?
  4. 1)
  5. 2) No
  6. #? 1
  7. --2011-01-11 17:30:26--  http://search.cpan.org/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz
  8. Resolviendo search.cpan.org... 207.115.101.144, 194.106.223.155
  9. Conectando a search.cpan.org|207.115.101.144|:80... conectado.
  10. Petición HTTP enviada, esperando respuesta... 302 Found
  11. Ubicación: http://www.msg.com.mx/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz [siguiente]
  12. --2011-01-11 17:30:26--  http://www.msg.com.mx/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz
  13. Resolviendo www.msg.com.mx... 200.33.54.1
  14. Conectando a www.msg.com.mx|200.33.54.1|:80... conectado.
  15. Petición HTTP enviada, esperando respuesta... 200 OK
  16. Longitud: 11569 (11K) [application/x-tar]
  17. Guardando en: «Math-BigInt-Random-0.04.tar.gz»
  18.  
  19. 100%[========================================================================================================================================>] 11,569      --.-K/s   en 0.1s    
  20.  
  21. 2011-01-11 17:30:26 (108 KB/s) - «Math-BigInt-Random-0.04.tar.gz» guardado [11569/11569]
  22.  
  23. Math-BigInt-Random-0.04/
  24. Math-BigInt-Random-0.04/Changes
  25. Math-BigInt-Random-0.04/lib/
  26. Math-BigInt-Random-0.04/lib/Math/
  27. Math-BigInt-Random-0.04/lib/Math/BigInt/
  28. Math-BigInt-Random-0.04/lib/Math/BigInt/Random.pm
  29. Math-BigInt-Random-0.04/LICENSE
  30. Math-BigInt-Random-0.04/Makefile.PL
  31. Math-BigInt-Random-0.04/MANIFEST
  32. Math-BigInt-Random-0.04/META.yml
  33. Math-BigInt-Random-0.04/README
  34. Math-BigInt-Random-0.04/t/
  35. Math-BigInt-Random-0.04/t/01_test.t
  36. Math-BigInt-Random-0.04/t/02_pod.t
  37. Math-BigInt-Random-0.04/t/03_pod_coverage.t
  38. Math-BigInt-Random-0.04/Todo
  39. Checking if your kit is complete...
  40. Looks good
  41. Writing Makefile for Math::BigInt::Random
  42. cp lib/Math/BigInt/Random.pm blib/lib/Math/BigInt/Random.pm
  43. Manifying blib/man3/Math::BigInt::Random.3
  44. PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
  45. t/01_test.t .......... ok    
  46. t/02_pod.t ........... ok  
  47. t/03_pod_coverage.t .. skipped: Test::Pod::Coverage required for testing POD coverage
  48. All tests successful.
  49. Files=3, Tests=15,  3 wallclock secs ( 0.04 usr  0.02 sys +  0.35 cusr  0.08 csys =  0.49 CPU)
  50. Result: PASS
  51. Manifying blib/man3/Math::BigInt::Random.3
  52. Installing /usr/local/lib/perl5/site_perl/5.12.0/Math/BigInt/Random.pm
  53. Installing /usr/local/share/man/man3/Math::BigInt::Random.3
  54. Appending installation info to /usr/local/lib/perl5/5.12.0/i686-linux/perllocal.pod
  55.  

Incluso podríamos trabajar con un archivo externo en donde se pongan los módulos a instalar.


Título: Re: [BASH] Script instalación de módulos Perl
Publicado por: m1kh41l en 14 Enero 2011, 04:35 am
muy bien