Commit 8ee9bc06 authored by firmicus's avatar firmicus
Browse files

initial commit

darcs-hash:20080923125548-df5cb-5a979d2f1fd5b450abc173d112bf00facdb3c5d9.gz
parents
#!/usr/bin/perl
#===============================================================================
#
# FILE: tllocalmgr
#
# USAGE: ./tllocalmgr [-a|-s|-c]
#
# DESCRIPTION:
#
# OPTIONS: --all (-a) : update all new packages
# --skipupdate (-s) : do not download a new version of texlive.tlpdb
# --clean (-c) : remove the old build tree
#
# REQUIREMENTS: perl-libwww
# BUGS: ---
# NOTES: ---
# AUTHOR: Firmicus <firmicus ατ gmx δοτ net>
# VERSION: 0.1
# CREATED: 20/09/08 12:11:47 CEST
# REVISION: ---
# TODO : - ensure that symlinks to scripts under TEXMFLOCAL/scripts replace
# under TEXMFDIST
# - List "execute" lines at the end...
# - Make it behave as a (minimal) Shell.
#
#===============================================================================
use strict;
use lib "/home/francois/.texlive/texmf-var/arch/tlpkg";
# this is a slightly modified version of the perl module distributed with TeXLive:
# we simply activated a few accessors to the $tlpdb object
use TeXLive::TLPDB;
use Getopt::Long; #TODO
my $opts = {};
GetOptions( $opts,
'skipupdate|s',
'all|a',
'clean|c',
'search|s',
'install|i',
'info',
'show'
);
use File::Path;
use LWP::Simple;
# use YAML::Syck; for debugging
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1; #
#my $TEXMFVAR=`kpsewhich -var-value=TEXMFVAR`;
my $CTANBASEURL="http://mirror.ctan.org/systems/texlive/tlnet/2008";
my $TLARCHIVE="$CTANBASEURL/archive";
my $TLPDB="$CTANBASEURL/tlpkg/texlive.tlpdb.lzma";
my $ROOT = "$ENV{HOME}/.texlive/texmf-var/arch";
my $LOCALDB = "$ROOT/tlpkg/texlive.tlpdb.lzma";
my $logfile = "$ROOT/tllocalmgr.log";
open LOG, "> $logfile";
my $retrievedb = $opts->{'updatedb'} || 0 ;
my $updateall = $opts->{'all'} || 0 ;
my $cleantree = $opts->{'clean'} || 0 ;
if ( $cleantree ) {
rmtree("$ROOT/builds") ;
};
my @dbstats = stat($LOCALDB);
#TODO only retrieve if local DB is older than 12 hours
if ($retrievedb) {
my $ageofdb = time - $dbstats[9];
unless ($ageofdb < 3600*12) {
print "Retrieving new TeXLive database from CTAN...\n";
print LOG "* Retrieving new TeXLive database from CTAN...\n";
getstore($TLPDB,$LOCALDB) || die "could not fetch $TLPDB : $!";
system("mv $ROOT/tlpkg/texlive.tlpdb $ROOT/tlpkg/texlive.tlpdb.old");
system("unlzma $ROOT/tlpkg/texlive.tlpdb.lzma");
}
};
print "Parsing ...\n";
my $tlpdb = new TeXLive::TLPDB (root => $ROOT) || die "cannot read $ROOT/tlpkg/texlive.tlpdb";
my @core_colls = qw/ basic basicbin binextra context fontbin genericrecommended fontsrecommended langczechslovak langfrench langgerman langitalian langpolish langportuguese langspanish latex latexrecommended mathextra metapost psutils texinfo xetex / ;
my @core_doc_colls = qw/ documentation-base documentation-bulgarian documentation-chinese
documentation-czechslovak documentation-dutch documentation-english documentation-finnish
documentation-french documentation-german documentation-greek documentation-italian
documentation-japanese documentation-korean documentation-mongolian documentation-polish
documentation-portuguese documentation-russian documentation-slovenian documentation-spanish
documentation-thai documentation-turkish documentation-ukrainian documentation-vietnamese/;
my @other_colls = qw/ bibtexextra fontsextra formatsextra games genericextra htmlxml humanities langcjk langcyrillic langgreek latex3 latexextra music pictures plainextra pstricks publishers science /;
my @langextra_colls = qw/ langafrican langarab langarmenian langcroatian langhebrew langindic langmongolian langtibetan langvietnamese /;
my %tlpackages;
my %tldocpackages;
my @core_additional = qw/ pgf ruhyphen ukrhyph /;
push @{$tlpackages{'core'}}, @core_additional;
push @{$tlpackages{'core-doc'}}, 'pgf';
foreach my $coll (@core_colls) {
foreach my $d ($tlpdb->depends("collection-$coll")) {
# avoid packages without content in texmf-dist:
next if $d =~ /^(a2ping|hyphenex|luatex|pdftex|synctex|texlive\.infra|xindy)$/;
# avoid also bin- collection- and hyphen- packages
push @{$tlpackages{'core'}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
if (($tlpdb->doccontainermd5($d) or $tlpdb->docsize($d))
and $d !~ /^(bin|collection|hyphen)-/) {
push @{$tlpackages{'core-doc'}}, $d ;
}
}
}
foreach my $coll (@core_doc_colls) {
foreach my $d ($tlpdb->depends("collection-$coll")) {
push @{$tlpackages{'core-doc'}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
}
}
foreach my $d ($tlpdb->depends("collection-fontsextra")) {
next if $d =~ /^(aleph|ocherokee|oinuit)$/;
push @{$tlpackages{'fontsextra'}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
if (($tlpdb->doccontainermd5($d) or $tlpdb->docsize($d))
and $d !~ /^(bin|collection|hyphen)-/) {
push @{$tlpackages{'fontsextra-doc'}}, $d ;
}
}
foreach my $coll (@other_colls) {
next if $coll eq 'fontsextra';
foreach my $d ($tlpdb->depends("collection-$coll")) {
next if ($coll =~ /^pictures/ and $d eq 'pgf');
next if ($coll =~ /^langcyrillic/ and ($d eq 'ruhyphen' or $d eq 'ukrhyph'));
push @{$tlpackages{$coll}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
if (($tlpdb->doccontainermd5($d) or $tlpdb->docsize($d))
and $d !~ /^(bin|collection|hyphen)-/) {
push @{$tlpackages{"$coll-doc"}}, $d ;
}
}
}
foreach my $coll (@langextra_colls) {
foreach my $d ($tlpdb->depends("collection-$coll")) {
next if $d =~ /^(omega-devanagari|otibet)$/;
push @{$tlpackages{'langextra'}}, $d unless ($d eq 'ebong' or $d =~ /^(bin|collection|hyphen)-/);
if (($tlpdb->doccontainermd5($d) or $tlpdb->docsize($d))
and $d !~ /^(bin|collection|hyphen)-/) {
push @{$tlpackages{"langextra-doc"}}, $d ;
}
}
}
# add swebib and finbib to bibtexextra
my @bibtexadd = qw /swebib finbib/;
push @{$tlpackages{'bibtexextra'}}, @bibtexadd;
push @{$tlpackages{'bibtexextra-doc'}}, 'swebib';
my %versions ;
foreach my $coll (keys %tlpackages) {
my @tmp;
foreach my $pkg (@{$tlpackages{$coll}}) {
push @tmp, $tlpdb->package_revision($pkg)
};
@tmp = sort {$a <=> $b} @tmp;
$versions{$coll} = pop @tmp
}
my %installed_pkgs;
my %installed_colversions;
my %installed_pkgversions;
my @installed_lists = <installedpkgs/*.pkgs> ;
my @installed_cols;
foreach (@installed_lists) {
my ($col, $ver) = $_ =~ m/^.+\/texlive-(.+)\_(.+)\.pkgs$/;
$installed_colversions{$col} = $ver;
my @tmp = ();
open INST, "<$_";
while (<INST>) {
next if /^\s*$/;
chomp( (my $name, my $ver) = split / /, $_ );
$installed_pkgversions{$name} = $ver;
push @tmp, $name;
};
close INST;
$installed_pkgs{$col} = [ @tmp ];
}
my @updatedpkgs;
my %collectionsbypkg;
print LOG "* List of updated or new packages for each collection:\n";
foreach my $col (sort keys %installed_colversions) {
#my $installedver = `pacman -Q texlive-$col`;
#$installedver =~ s/texlive-$col 2008\.([0-9]+)-.+/$1/;
next unless ( $installed_colversions{$col} < $versions{$col} ) ;
print LOG " - texlive-$col :\n";
print BOLD RED "texlive-$col :\n";
foreach my $pkg (sort @{$tlpackages{$col}}) {
my $newver = $tlpdb->package_revision($pkg);
if ( exists $installed_pkgversions{$pkg} ) {
my $oldver = $installed_pkgversions{$pkg} ;
if ($newver > $oldver) {
print CYAN "\t$pkg has been updated ($oldver => $newver)\n";
print LOG "\t$pkg has been updated ($oldver => $newver)\n";
push @updatedpkgs, $pkg;
$collectionsbypkg{$pkg} = $col;
}
} else {
print CYAN "\t$pkg is new!\n";
print LOG "\t$pkg is new (as of rev $newver)\n";
push @updatedpkgs, $pkg;
$collectionsbypkg{$pkg} = $col;
};
}
}
my $choice;
unless ($updateall) {
print BOLD, BLUE, "Which packages do you want to update locally?\n\t> ", RESET ;
chomp($choice = <STDIN>) ;
} ;
my @toupdate;
if ($updateall or $choice =~ m/all/i) {
@toupdate = @updatedpkgs
} else {
@toupdate = split /\s+/, $choice;
};
exit 0 unless @toupdate;
print LOG "* Preparing to update the following packages:\n";
my $updatestr = join(", ", @toupdate);
print LOG "\t$updatestr\n\n";
#my $TLINSTALL = <<"EOF"
#post_install() {
# echo ">>> texlive: updating the filename database..."
# texconfig-sys rehash
#}
#
#post_upgrade() {
# echo ">>> texlive: updating the filename database..."
# texconfig-sys rehash
#}
#
#post_remove() {
# echo ">>> texlive: updating the filename database..."
# texconfig-sys rehash
#}
#EOF
#;
foreach my $pkg (@toupdate) {
if ( ! defined $tlpdb->package_revision($pkg) ) {
print RED "Warning: $pkg does not exist\n";
print LOG "Warning: $pkg does not exist\n";
next;
};
mkpath( "$ROOT/builds/$pkg", { mode => 0755 });
open PKGBUILD, "> $ROOT/builds/$pkg/PKGBUILD";
my $newver = $tlpdb->package_revision($pkg);
my $col = $collectionsbypkg{$pkg};
my $pkgmd5 = $tlpdb->containermd5($pkg);
print PKGBUILD <<"EOF"
# Generated by tllocalmgr
pkgname=texlive-local-$pkg
pkgver=$newver
pkgrel=1
pkgdesc="TeX Live - local installation of CTAN package $pkg"
license=('GPL')
arch=('i686' 'x86_64')
depends=('texlive-core')
conflicts=('texlive-$col>=2008.$newver')
makedepends=('lzma-utils')
url='http://tug.org/texlive/'
source=('$TLARCHIVE/$pkg.tar.lzma')
md5sums=($pkgmd5)
build() {
cd \$startdir/src
lzma --force -dc $pkg.tar.lzma | tar xf - || return 1
install -m755 -d \$startdir/pkg/usr/local/share || return 1
cd texmf-dist
find . -type d -exec install -d -m755 \$startdir/pkg/usr/local/share/texmf/'{}' \\; || exit 1
find . -type f -exec install -m644 '{}' \$startdir/pkg/usr/local/share/texmf/'{}' \\; || exit 1
}
EOF
;
close PKGBUILD;
print LOG "* Created $ROOT/builds/$pkg/PKGBUILD\n";
# open INSTALL, "> $ROOT/builds/$pkg/texlive.install";
# print INSTALL $TLINSTALL;
# close INSTALL;
print LOG "* Running makepkg -ci on $ROOT/builds/$pkg/PKGBUILD\n";
chdir "$ROOT/builds/$pkg";
system( "makepkg -ci" );
}
print "\n>>> Finished. Don't forget to run 'texhash' to update your file database.\n";
my @execlines;
foreach my $pkg (@toupdate) {
push @execlines, $tlpdb->executes($pkg) if $tlpdb->executes($pkg);
}
if (@execlines) {
print ">>> Also make sure to update /usr/share/texmf-config/web2c/updmap.cfg in\n";
print " case you have installed new fonts or fonts with a different map file.\n";
print " Look at the log file for details.\n";
print LOG "* Lines that can be added to /usr/share/texmf-config/web2c/updmap.cfg if needed:\n";
foreach my $line (@execlines) {
print LOG "\t", $line, "\n"
};
print LOG "(Make sure to run updmap-sys to activate them).\n";
close LOG;
}
__END__
sub action_show {
foreach my $pkg (@ARGV) {
my $tlp = $tlpdb->get_package($pkg);
my $installed = 0; #FIXME
if ($tlp) {
print "Package: ", $tlp->name, "\n";
print "Category: ", $tlp->category, "\n";
print "ShortDesc: ", $tlp->shortdesc, "\n" if ($tlp->shortdesc);
print "LongDesc: ", $tlp->longdesc, "\n" if ($tlp->longdesc);
print "Installed: ", ($installed?"Yes\n":"No\n");
print "\n";
} else {
printf STDERR "Cannot find $pkg\n";
}
}
return;
}
sub action_search {
my $opt_global = 0;
my $opt_file = 0;
Getopt::Long::Configure(qw(no_pass_through));
GetOptions("global" => \$opt_global,
"file" => \$opt_file) or pod2usage(2);
my $r = shift @ARGV;
my $ret = "";
my $tlpdb;
init_local_db();
if ($opt_global) {
$tlmediasrc = TeXLive::TLMedia->new($location);
die($loadmediasrcerror . $location) unless defined($tlmediasrc);
$tlpdb = $tlmediasrc->tlpdb;
} else {
$tlpdb = $localtlpdb;
}
foreach my $pkg ($tlpdb->list_packages) {
if ($opt_file) {
my @ret = grep(m;$r;, $tlpdb->get_package($pkg)->all_files);
if (@ret) {
print "$pkg:\n";
foreach (@ret) {
print "\t$_\n";
}
}
} else {
next if ($pkg =~ m/\./);
my $t = $tlpdb->get_package($pkg)->shortdesc;
$t |= "";
my $lt = $tlpdb->get_package($pkg)->longdesc;
$lt |= "";
if (($pkg =~ m/$r/) || ($t =~ m/$r/) || ($lt =~ m/$r/)) {
$ret .= " $pkg - $t\n";
}
}
}
print "$ret";
return;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment