Test Foro de elhacker.net SMF 2.1

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 (bash) [Seleccionar]
#!/bin/bash
# Leo Gutiérrez R. leorocko13@hotmail.com
[ ${UID} != 0 ] && {
echo -e "Se requieren privilegios de Root";
exit 1;
}

MODULE_NAME="Math::BigInt::Random";
URL_MODULE="http://search.cpan.org/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz";
PATH_MODULE="Math-BigInt-Random-0.04.tar.gz";

perl -M${MODULE_NAME} -e 1 2> /dev/null || {
echo -e "\aEl módulo no existe\n¿Desea instalarlo:?";
opciones="Sí No";
select opt in ${opciones}
do
if [ "${opt}" = "Sí" ]
then

wget "${URL_MODULE}";
tar zxvf "${PATH_MODULE}";
cd "${PATH_MODULE%\.tar.gz}" 2> /dev/null || {
echo -e "\aError abriendo directorio ${1%%.*}";
exit 1;
}
perl Makefile.PL
make
make test
make install
exit 0;

elif [ "${opt}" = "No" ]
then

echo -e "\aLa instalación del módulo es necesaria";
exit 1;

fi
done
}


Código (bash) [Seleccionar]
leo@leo-desktop:~/Escritorio$ sudo bash shell.sh
El módulo no existe
¿Desea instalarlo:?
1) Sí
2) No
#? 1
--2011-01-11 17:30:26--  http://search.cpan.org/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz
Resolviendo search.cpan.org... 207.115.101.144, 194.106.223.155
Conectando a search.cpan.org|207.115.101.144|:80... conectado.
Petición HTTP enviada, esperando respuesta... 302 Found
Ubicación: http://www.msg.com.mx/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz [siguiente]
--2011-01-11 17:30:26--  http://www.msg.com.mx/CPAN/authors/id/B/BI/BILLH/Math-BigInt-Random-0.04.tar.gz
Resolviendo www.msg.com.mx... 200.33.54.1
Conectando a www.msg.com.mx|200.33.54.1|:80... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 11569 (11K) [application/x-tar]
Guardando en: «Math-BigInt-Random-0.04.tar.gz»

100%[========================================================================================================================================>] 11,569      --.-K/s   en 0.1s   

2011-01-11 17:30:26 (108 KB/s) - «Math-BigInt-Random-0.04.tar.gz» guardado [11569/11569]

Math-BigInt-Random-0.04/
Math-BigInt-Random-0.04/Changes
Math-BigInt-Random-0.04/lib/
Math-BigInt-Random-0.04/lib/Math/
Math-BigInt-Random-0.04/lib/Math/BigInt/
Math-BigInt-Random-0.04/lib/Math/BigInt/Random.pm
Math-BigInt-Random-0.04/LICENSE
Math-BigInt-Random-0.04/Makefile.PL
Math-BigInt-Random-0.04/MANIFEST
Math-BigInt-Random-0.04/META.yml
Math-BigInt-Random-0.04/README
Math-BigInt-Random-0.04/t/
Math-BigInt-Random-0.04/t/01_test.t
Math-BigInt-Random-0.04/t/02_pod.t
Math-BigInt-Random-0.04/t/03_pod_coverage.t
Math-BigInt-Random-0.04/Todo
Checking if your kit is complete...
Looks good
Writing Makefile for Math::BigInt::Random
cp lib/Math/BigInt/Random.pm blib/lib/Math/BigInt/Random.pm
Manifying blib/man3/Math::BigInt::Random.3
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01_test.t .......... ok     
t/02_pod.t ........... ok   
t/03_pod_coverage.t .. skipped: Test::Pod::Coverage required for testing POD coverage
All tests successful.
Files=3, Tests=15,  3 wallclock secs ( 0.04 usr  0.02 sys +  0.35 cusr  0.08 csys =  0.49 CPU)
Result: PASS
Manifying blib/man3/Math::BigInt::Random.3
Installing /usr/local/lib/perl5/site_perl/5.12.0/Math/BigInt/Random.pm
Installing /usr/local/share/man/man3/Math::BigInt::Random.3
Appending installation info to /usr/local/lib/perl5/5.12.0/i686-linux/perllocal.pod


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