#!/usr/bin/perl use File::Copy; use File::Spec::Functions; use File::Path; use warnings; use strict; ### Although the original idea of this script was just to install the ### dictionary, the truth is that it can be handy as a generic ### installation script, given that build.pl is run without ### administrator privileges ### ------------------------------------------------------------------ ### This first section installs the jspell.pc file. my $pkgdestpath = catfile("[% PREFIX %]","lib","pkgconfig"); mkpath($pkgdestpath); $pkgdestpath = catfile($pkgdestpath, "jspell.pc"); copy("jspell.pc",$pkgdestpath); ### ------------------------------------------------------------------ ### This section fetches the hash file for the portuguese dictionary ### from Natura's website and installs it. At the moment it checks for ### LWP::Simple and Archive::Any, so it can perform the installation. ### Later these modules might be in the list of required ones, and thus, ### this script made simpler. eval { require LWP::Simple }; if ($@) { print STDERR "LWP::Simple is not available on your system.\n"; print STDERR "I'll not try to install any dictionary now.\n"; exit; } LWP::Simple->import(); eval { require Archive::Any }; if ($@) { print STDERR "Archive::Any is not available on your system.\n"; print STDERR "I'll not try to install any dictionary now.\n"; exit; } Archive::Any->import(); my $baseurl = 'http://natura.di.uminho.pt/download/sources/Dictionaries/jspell/'; my $dics = [qw|jspell.pt-bin-latest.tar.gz jspell.en-bin-latest.tar.gz|]; for my $dicurl (map { $baseurl.$_ } @$dics) { if (is_success(getstore($dicurl, "dic.tar.gz"))) { my $archive = Archive::Any->new("dic.tar.gz"); my ($dir,@files) = $archive->files; $archive->extract(); my $destpath = catfile("[% PREFIX %]","lib","jspell"); mkpath($destpath); for (@files) { if (m!\.(irr|meta|hash)$!) { $_ =~ s/$dir//; my ($from, $to) = (catfile($dir,$_), catfile($destpath,$_)); print "Installing [$_] as [$to]\n"; copy(catfile($dir,$_),catfile($destpath,$_)); } } unlink "dic.tar.gz"; rmtree($dir,1,1); } else { print STDERR "I can't access the dictionary server this time.\n"; print STDERR "You will need to install dictionaries manually.\n"; } }