tllocalmgr 23.8 KB
Newer Older
1
#!/usr/bin/perl
firmicus's avatar
firmicus committed
2

3
use warnings;
firmicus's avatar
firmicus committed
4
use strict;
5
use lib "tlpkg"; #FIXME
firmicus's avatar
firmicus committed
6
use TeXLive::TLPDB;
7
use TeXLive::TLPOBJ;
firmicus's avatar
firmicus committed
8

9
use Getopt::Long; 
firmicus's avatar
firmicus committed
10
11
my $opts = {};
GetOptions( $opts,
12
13
14
15
16
17
18
			'skipupdate',
			'forceupdate',
			'localsearch', #TODO
			'location', #TODO ?
			'mirror',
			'nocolor', #TODO
			'help|h'
firmicus's avatar
firmicus committed
19
20
21
22
		);

use File::Path;
use LWP::Simple;
23
use YAML::Syck; ##for debugging
firmicus's avatar
firmicus committed
24
25
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1; # 
26
27
28
29
30
31
32
33
use Term::ShellUI;

die "You can't run this program as root\n" if $ENV{'USER'} eq "root";

die usage(), "\n" if $opts->{'help'};

my $term = new Term::ShellUI( commands => get_commands());
$term->prompt( "tllocalmgr> " );
firmicus's avatar
firmicus committed
34
35
36
37

#my $TEXMFVAR=`kpsewhich -var-value=TEXMFVAR`;
my $CTANBASEURL="http://mirror.ctan.org/systems/texlive/tlnet/2008";
my $ROOT = "$ENV{HOME}/.texlive/texmf-var/arch";
38
39
40
my $LOCALDB = "$ROOT/tlpkg/texlive.tlpdb";
my $LOCALDBLZMA = "$LOCALDB.lzma";
my $INSTALLEDPKGS = "$ROOT/installedpkgs";
firmicus's avatar
firmicus committed
41
42
my $logfile = "$ROOT/tllocalmgr.log";

43
44
45
46
47
my $skipupdate = $opts->{'skipupdate'} || 0 ;
my $forceupdate = $opts->{'forceupdate'} || 0 ;
my $location = $opts->{'location'} || $ROOT ;
my $mirror = $opts->{'mirror'} || $CTANBASEURL ;
my $localsearch = $opts->{'localsearch'} || 0 ;
firmicus's avatar
firmicus committed
48

49
50
my $TLARCHIVE="$mirror/archive";
my $TLPDB="$mirror/tlpkg/texlive.tlpdb.lzma";
firmicus's avatar
firmicus committed
51
52
53
54
55
56
57
58

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
59
		documentation-thai documentation-turkish documentation-ukrainian documentation-vietnamese /;
firmicus's avatar
firmicus committed
60
61
62
63

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 /;

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

########### INITIALIZATION ###########

open LOG, "> $logfile";


my @dbstats = stat($LOCALDB); # to know how old the local db is

# only retrieve if local DB is older than 12 hours
unless ($skipupdate) {
	my $ageofdb = time - $dbstats[9];
	if ($forceupdate || $ageofdb > 3600*12) {
		print "Retrieving new TeXLive database from CTAN...\n";
		print LOG "* Retrieving new TeXLive database from CTAN...\n\t$TLPDB";
		getstore($TLPDB,$LOCALDBLZMA) || die "could not fetch $TLPDB : $!";
		system("mv $ROOT/tlpkg/texlive.tlpdb $ROOT/tlpkg/texlive.tlpdb.old");
		system("unlzma $ROOT/tlpkg/texlive.tlpdb.lzma");
	}
};

print GREEN, BOLD, "Initializing ...", RESET, "\n" ;
my $tlpdb = new TeXLive::TLPDB (root => $ROOT) || die "cannot read $ROOT/tlpkg/texlive.tlpdb";

firmicus's avatar
firmicus committed
87
88
89
90
91
92
93
94
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) {
95
		foreach my $d ($tlpdb->get_package("collection-$coll")->depends) {
firmicus's avatar
firmicus committed
96
97
98
99
			# 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)-/;
100
			if (($tlpdb->get_package($d)->doccontainermd5 or $tlpdb->get_package($d)->docsize) 
firmicus's avatar
firmicus committed
101
102
103
104
105
106
107
					and $d !~ /^(bin|collection|hyphen)-/) {
				push @{$tlpackages{'core-doc'}}, $d ;
			}
		}
} 

foreach my $coll (@core_doc_colls) {
108
		foreach my $d ($tlpdb->get_package("collection-$coll")->depends) {
firmicus's avatar
firmicus committed
109
110
111
112
			push @{$tlpackages{'core-doc'}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
		}
} 

113
foreach my $d ($tlpdb->get_package("collection-fontsextra")->depends) {
firmicus's avatar
firmicus committed
114
115
	next if $d =~ /^(aleph|ocherokee|oinuit)$/;
	push @{$tlpackages{'fontsextra'}}, $d unless $d =~ /^(bin|collection|hyphen)-/;
116
	if (($tlpdb->get_package($d)->doccontainermd5 or $tlpdb->get_package($d)->docsize) 
firmicus's avatar
firmicus committed
117
118
119
120
121
122
123
			and $d !~ /^(bin|collection|hyphen)-/) {
		push @{$tlpackages{'fontsextra-doc'}}, $d ;
	}
}

foreach my $coll (@other_colls) {
	next if $coll eq 'fontsextra';
124
	foreach my $d ($tlpdb->get_package("collection-$coll")->depends) {
firmicus's avatar
firmicus committed
125
126
127
		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)-/;
128
		if (($tlpdb->get_package($d)->doccontainermd5 or $tlpdb->get_package($d)->docsize) 
firmicus's avatar
firmicus committed
129
130
131
132
133
134
135
				and $d !~ /^(bin|collection|hyphen)-/) {
			push @{$tlpackages{"$coll-doc"}}, $d ;
		}
	}
} 

foreach my $coll (@langextra_colls) {
136
	foreach my $d ($tlpdb->get_package("collection-$coll")->depends) {
firmicus's avatar
firmicus committed
137
138
		next if $d =~ /^(omega-devanagari|otibet)$/;
		push @{$tlpackages{'langextra'}}, $d unless ($d eq 'ebong' or $d =~ /^(bin|collection|hyphen)-/);
139
		if (($tlpdb->get_package($d)->doccontainermd5 or $tlpdb->get_package($d)->docsize) 
firmicus's avatar
firmicus committed
140
141
142
143
144
145
146
147
148
149
150
151
152
				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 ;

153
154
155
156
# list of all packages in the database that interest us
# i.e. less than $tlpdb->list_packages !
my @allpackages; 

firmicus's avatar
firmicus committed
157
158
159
foreach my $coll (keys %tlpackages) {
	my @tmp;
	foreach my $pkg (@{$tlpackages{$coll}}) {
160
161
		push @tmp, $tlpdb->package_revision($pkg);
		push @allpackages, $pkg;
firmicus's avatar
firmicus committed
162
163
164
165
166
	};
	@tmp = sort {$a <=> $b} @tmp;
	$versions{$coll} = pop @tmp
}

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
my %installedcol_pkgs; # list of packages in each installed collection
my %installedcol_versions; # version of each installed coll
my %installedpkg_versions; # version of each installed pkg
my %locallyinstalledpkg_versions; # version of each locally installed pkg TODO
my @installed_lists = <$INSTALLEDPKGS/*.pkgs> ;
my @installed_cols; # collections installed

chomp(my @localpacman = `pacman -Qs texlive-local | egrep ^local | cut -d'/' -f2`);

if (@localpacman) {
	foreach (@localpacman) {
		my @tmp = split;
		my $n = $tmp[0];
		$n =~ s/^texlive-local-//;
		my $v = $tmp[1] ;
		$v =~ s/-[0-9]+$//;
		$locallyinstalledpkg_versions{$n} = $v;
	}
}
firmicus's avatar
firmicus committed
186
187
188

foreach (@installed_lists) {
	my ($col, $ver) = $_ =~ m/^.+\/texlive-(.+)\_(.+)\.pkgs$/;
189
	$installedcol_versions{$col} = $ver;
firmicus's avatar
firmicus committed
190
191
192
193
194
	my @tmp = ();
	open INST, "<$_";
	while (<INST>) {
		next if /^\s*$/;
	    chomp( (my $name, my $ver) = split / /, $_ );
195
		$installedpkg_versions{$name} = $ver; 
firmicus's avatar
firmicus committed
196
197
198
		push @tmp, $name;
	};
	close INST;
199
200
201
202
203
204
205
206
207
	$installedcol_pkgs{$col} = [ @tmp ];
}

my %collectionsbypkg; # collection to which belongs each pkg

foreach my $col (keys %tlpackages) {
	foreach my $pkg (@{$tlpackages{$col}}) {
		$collectionsbypkg{$pkg} = $col
	}
firmicus's avatar
firmicus committed
208
209
}

210
211
my %updatedcol_pkgs; # pkgs for which updates are available, by collection
my @updatedpkgs; # pkgs for which updates are available
firmicus's avatar
firmicus committed
212

213
foreach my $col (sort keys %installedcol_versions) {
firmicus's avatar
firmicus committed
214
215
	#my $installedver = `pacman -Q texlive-$col`;
	#$installedver =~ s/texlive-$col 2008\.([0-9]+)-.+/$1/;
216
	next unless ( $installedcol_versions{$col} < $versions{$col} ) ;
firmicus's avatar
firmicus committed
217
218
	foreach my $pkg (sort @{$tlpackages{$col}}) {
		my $newver = $tlpdb->package_revision($pkg);
219
220
		if ( exists $installedpkg_versions{$pkg} ) {
			my $oldver = $installedpkg_versions{$pkg} ;
firmicus's avatar
firmicus committed
221
			if ($newver > $oldver) {
222
				push @{$updatedcol_pkgs{$col}}, $pkg;
firmicus's avatar
firmicus committed
223
224
				push @updatedpkgs, $pkg;
			}
225
226
		} else { # new pkg
			push @{$updatedcol_pkgs{$col}}, $pkg;
firmicus's avatar
firmicus committed
227
228
229
230
231
			push @updatedpkgs, $pkg;
		};
	}
}

232
233
234
my @pkglist;
if ( $localsearch ) {
   @pkglist = keys %installedpkg_versions
firmicus's avatar
firmicus committed
235
} else {
236
   @pkglist = @allpackages
firmicus's avatar
firmicus committed
237
238
};

239
##############################################
firmicus's avatar
firmicus committed
240

241
242
243
244
245
246
247
no strict 'refs';
if (@ARGV) {
	my $cmd = shift @ARGV;
	my $runcmd = "run_$cmd";
	&$runcmd(@ARGV);
	exit 0 unless $cmd eq 'status';
}
firmicus's avatar
firmicus committed
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
print "Welcome to the TeXLive Local Manager shell. Type 'help' for assistance.\n";

########### END OF INITIALIZATION ###########

$term->run();

sub get_commands
{
	return {
		"status" => { desc => "Current status of TeXLive installation",
                      proc => \&run_status }, 
		"install" => { desc => "Locally install new CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_install(@_) } }, 
		"installdoc" => { desc => "Locally install documentation of CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_installdoc(@_) } }, 
		"installsrc" => { desc => "Locally install sources of CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_installsrc(@_) } }, 
		"update" => { desc => "Locally update CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_update(@_) } }, 
		"?" =>		{ alias => "help" },
		"h" =>		{ alias => "help", exclude_from_completion=>1 },
		"help" => 	{ desc => "Print helpful information",
					  args => sub { shift->help_args(undef, @_); },
					  method => sub { shift->help_call(undef, @_); } }, 
		"quit" =>	{ desc => "Quit tllocalmgr",
					  maxargs => 0,
                      method => sub { shift->exit_requested(1); } }, 
		"q" =>		{ alias => "quit" },
		"exit" =>	{ alias => "quit" },
		"clean" =>	{ desc => "Clean local build tree",
					  proc => \&run_clean },
		"info"	=>  { desc => "Print info on CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_info(@_) } },
		"shortinfo"	=>  { desc => "Print a one-liner description of CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_shortinfo(@_) } },
		"listfiles"	=>  { desc => "List all files in CTAN packages",
					  args => \&complete_pkgname ,
					  minargs => 1,
                      proc => sub { run_listfiles(@_) } },
		"search"	=>  { desc => "Search info on CTAN packages",
					  minargs => 1,
                      proc => sub { run_search(@_) } },
		"s" =>		{ alias => "search" },
		"searchfiles" =>  { desc => "Search for files in CTAN packages",
					  minargs => 1,
                      proc => sub { run_searchfiles(@_) } },
		"sf" =>		{ alias => "searchfiles" },
		"texhash" => { desc => "Refresh the TeX file database",
					   maxargs => 0,
					   proc => sub { system('sudo texhash') } }
firmicus's avatar
firmicus committed
311
	};
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
}

sub echo {
	print @_, "\n";
}


sub run_clean {
	print "Are you sure? (y/N) > ";
	chomp(my $choice = <STDIN>) ;
	rmtree("$ROOT/builds") if $choice =~ m/^y/i ;
}

sub run_status {
	print LOG "* List of updated or new packages for each collection:\n";

	foreach my $col (sort keys %updatedcol_pkgs) {
		print LOG " - texlive-$col :\n";
		print BOLD RED "texlive-$col :\n";
		foreach my $pkg (sort @{$updatedcol_pkgs{$col}}) {
			my $newver = $tlpdb->package_revision($pkg);
			if ( $installedpkg_versions{$pkg} ) {
				my $oldver = $installedpkg_versions{$pkg} ;
				if ($newver > $oldver) {
					print GREEN, "\t$pkg", RESET, " has been updated ($oldver => $newver)\n";
					print LOG "\t$pkg has been updated ($oldver => $newver)\n";
				}
			} else {
				print GREEN, "\t$pkg", RESET, " is new!\n";
				print LOG "\t$pkg is new (as of rev $newver)\n";
			};
		}
	}
}

sub run_install {
	##echo 'not implemented'
	foreach (@_) {
		if ( $locallyinstalledpkg_versions{$_} ) {
			echo "This pkg is already installed with texlive-local-$_";
			if ($locallyinstalledpkg_versions{$_} == $tlpdb->package_revision($_)) {
				echo "and it is uptodate"
			} else {
				print "Do you want to update it locally? (Y/n) > " ;
				chomp(my $choice = <STDIN>) ;
				next if $choice =~ m/^n/i;
				makepkg($_);
			}
		}
		elsif ( $installedpkg_versions{$_} ) {
			echo "This pkg is already installed with texlive-$collectionsbypkg{$_}";
			if ($installedpkg_versions{$_} == $tlpdb->package_revision($_)) {
				echo "and it is uptodate"
			} else { 
				#TODO check if it was already locally installed
				print "Do you want to update it locally? (Y/n) > " ;
				chomp(my $choice = <STDIN>) ;
				next if $choice =~ m/^n/i;
				makepkg($_);
			}
		} elsif (! $tlpdb->package_revision($_)) {
			echo "$_ is unknown" ;
			next ;
		} else {
			#TODO check if texlive-local-$_ was already locally installed
			makepkg($_)
		}
   }
}

sub run_installdoc {
	foreach (@_) {
		if ( $locallyinstalledpkg_versions{"$_-doc"} ) {
			echo "This pkg is already installed with texlive-local-$_-doc";
			if ($locallyinstalledpkg_versions{"$_-doc"} == $tlpdb->package_revision($_)) {
				echo "and it is uptodate"
			} else {
				print "Do you want to update it locally? (Y/n) > " ;
				chomp(my $choice = <STDIN>) ;
				next if $choice =~ m/^n/i;
				makepkgdoc($_);
			}
		}
		elsif (! $tlpdb->package_revision($_)) {
			echo "$_ is unknown" ;
			next ;
		} 
		else {
			#TODO check if texlive-local-$_-doc was already locally installed
			makepkgdoc($_)
		}
   }
}

sub run_installsrc {
	echo 'not implemented'
}

sub run_update {
	foreach (@_) {
		if ( $locallyinstalledpkg_versions{$_} ) {
			echo "This pkg is already installed with texlive-local-$_";
			if ($locallyinstalledpkg_versions{$_} == $tlpdb->package_revision($_)) {
				echo "and it is uptodate"
			} else {
				print "Do you want to update it locally? (Y/n) > " ;
				chomp(my $choice = <STDIN>) ;
				next if $choice =~ m/^n/i;
				makepkg($_);
			}
		}
		elsif ( $installedpkg_versions{$_} ) {
			echo "This pkg is already installed with texlive-$collectionsbypkg{$_}";
			if ($installedpkg_versions{$_} == $tlpdb->package_revision($_)) {
				echo "and it is uptodate"
			} else { 
				print "Do you want to update it locally? (Y/n) > " ;
				chomp(my $choice = <STDIN>) ;
				next if $choice =~ m/^n/i;
				makepkg($_);
			}
		} elsif (! $tlpdb->package_revision($_)) {
			echo "$_ is unknown" ;
			next ;
		} else {
			echo "$_ is not installed" ;
			print "Do you want to update it locally? (Y/n) > " ;
			chomp(my $choice = <STDIN>) ;
			next if $choice =~ m/^n/i;
			makepkg($_);
		}
   }
}

sub run_shortinfo {
	foreach (@_) {
		my $pkg = $tlpdb->get_package($_);
		if ($pkg) {
			print BOLD, GREEN, $_, RESET, ": ", $pkg->shortdesc, "\n";
		} else {
			print RED, "$_ is unknown\n\n";
		}
	}
}

sub run_info {
	foreach (@_) {
		my $pkg = $tlpdb->get_package($_);
		if ($pkg) {
			print BOLD, GREEN, $_, RESET, ":\n";
        	print CYAN, "  Category: ", RESET, $pkg->category, "\n";
	        print CYAN, "  ShortDesc: ", RESET, $pkg->shortdesc, "\n" if ($pkg->shortdesc);
    	    print CYAN, "  LongDesc: ", RESET, $pkg->longdesc, "\n" if ($pkg->longdesc);
    	    print CYAN, "  Size: ", RESET, $pkg->containersize, "\n" if ($pkg->containersize);
			print CYAN, "  Collection: ", RESET, "texlive-", $collectionsbypkg{$_}, "\n" if $collectionsbypkg{$_};
        	print CYAN, "  Installed: ", RESET, 
				(exists $installedpkg_versions{$_} ? "Yes\n" : "No\n");
	        print "\n";
		} else {
			print RED, "$_ is unknown\n\n";
		}
	}
}

sub run_listfiles {
	foreach (@_) {
		my $pkg = $tlpdb->get_package($_);
		if ($pkg) {
			my @allfiles = $pkg->all_files;
			print BOLD, GREEN, $_, RESET, ":\n";
			foreach (@allfiles) {
				print "\t", $_, "\n";
			};
	        print "\n";
		} else {
			print RED, "$_ is unknown\n\n";
		}
	}
}

sub run_search {
  my $r = shift;
  my $ret = "";
  my @pkglist;
  if ( $localsearch ) {
	  @pkglist = keys %installedpkg_versions
  } else {
	  @pkglist = $tlpdb->list_packages
  };
  foreach my $pkg (@pkglist) {
      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;
}

sub run_searchfiles {
  my $r = shift ;
  foreach my $pkg (@pkglist) {
      my @ret = grep(m;$r;, $tlpdb->get_package($pkg)->all_files);
      if (@ret) {
        print BOLD GREEN "$pkg:\n";
        foreach (@ret) {
          print "\t$_\n";
        }
      }
    }
}

sub makepkg {
	my @stack = @_;
	
	print LOG "* Preparing to make the following packages:\n";
	print LOG "\t", join(", ", @stack), "\n\n";

	foreach my $pkg (@stack) {
		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->get_package($pkg)->containermd5;
		print PKGBUILD <<"EOF"
firmicus's avatar
firmicus committed
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# 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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
	;
		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";
	#system ( "sed -i '/^$pkg /d' $INSTALLEDPKGS/texlive-local.pkgs" );
	#system ( "echo $pkg $newver >> $INSTALLEDPKGS/texlive-local.pkgs" ); 

	my @execlines;
	foreach my $pkg (@stack) {
		push @execlines, $tlpdb->get_package($pkg)->executes if $tlpdb->get_package($pkg)->executes;
	}

	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;
	}
firmicus's avatar
firmicus committed
599
600
}

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
sub makepkgdoc {
	my @stack = @_;
	
	print LOG "* Preparing to make the following packages:\n";
	print LOG "\t", join(", ", @stack), "\n\n";

	foreach my $pkg (@stack) {
		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-doc", { mode => 0755 });
		open PKGBUILD, "> $ROOT/builds/$pkg-doc/PKGBUILD";
		my $newver = $tlpdb->package_revision($pkg);
		my $pkgmd5 = $tlpdb->get_package($pkg)->doccontainermd5;
		print PKGBUILD <<"EOF"
# Generated by tllocalmgr
pkgname=texlive-local-$pkg-doc
pkgver=$newver
pkgrel=1
pkgdesc="TeX Live - local installation of CTAN package $pkg-doc"
license=('GPL')
arch=('i686' 'x86_64')
depends=('texlive-core')
makedepends=('lzma-utils')
url='http://tug.org/texlive/'
source=('$TLARCHIVE/$pkg.doc.tar.lzma')
md5sums=($pkgmd5)
firmicus's avatar
firmicus committed
630

631
632
633
634
635
636
637
638
639
640
641
build() {
   cd \$startdir/src
   lzma --force -dc $pkg.doc.tar.lzma | tar xf - || return 1
   install -m755 -d \$startdir/pkg/usr/local/share || return 1
   for d in texmf-dist texmf-doc; do
   	   if [ -d \$d ]; then
		 cd \$d
   		 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
       fi
	done
firmicus's avatar
firmicus committed
642
}
643
644
645
646
647
648
649
650
651
652
653
EOF
	;
		close PKGBUILD;
		print LOG "* Created $ROOT/builds/$pkg-doc/PKGBUILD\n";
	#	open INSTALL, "> $ROOT/builds/$pkg/texlive.install";
	#	print INSTALL $TLINSTALL;
	#	close INSTALL;
		print LOG "* Running makepkg -ci on $ROOT/builds/$pkg-doc/PKGBUILD\n";
		chdir "$ROOT/builds/$pkg-doc";
		system( "makepkg -ci" );
	}
firmicus's avatar
firmicus committed
654

655
656
657
	print "\n>>> Finished. Don't forget to run 'texhash' to update your file database.\n";
	#system ( "sed -i '/^$pkg /d' $INSTALLEDPKGS/texlive-local-doc.pkgs" );
	#system ( "echo $pkg $newver >> $INSTALLEDPKGS/texlive-local-doc.pkgs" ); 
firmicus's avatar
firmicus committed
658
659
}

660
sub complete_pkgname {
firmicus's avatar
firmicus committed
661

662
663
	my $self = shift;
	my $cmpl = shift;
firmicus's avatar
firmicus committed
664

665
666
	my $pkg = $cmpl->{args}->[0];
	return [] unless $pkg;
firmicus's avatar
firmicus committed
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
	#$pkg =~ s/^(["'])(.*)\1$/$2/;	# trim surrounding quotes
	my @cset = grep { m/^$pkg.+/i } @pkglist;

	if (@cset) {
		return [ @cset ];
	} else {
		if ($cmpl->{twice}) {
			$self->completemsg("\nNo pkg found for $pkg\n");
		}
	}
	return undef;
}

sub usage {
    qq[ 
Usage: tllocalmgr  
       tllocalmgr [options] [command] [args]

       Running tllocalmgr alone starts the TeXLive local manager shell 
       for Arch Linux. This shell is capable of command-line completion!
       There you can look at the available updates with the command 'status' 
       and you can install individual CTAN packages using 'install' or 'update'
       under \$TEXMFLOCAL. This is done by creating a package texlive-local-<pkg>
       and installing it with pacman. Note that this won’t interfere with your 
       standard texlive installation, but files under \$TEXMFLOCAL will take
       precedence.  
       
       Here are the commands available in the shell:

Commands:       
              status   --   Current status of TeXLive installation
           shortinfo * --   Print a one-liner description of CTAN packages
                info * --   Print info on CTAN packages
              update * --   Locally update CTAN packages
             install * --   Locally install new CTAN packages
          installdoc * --   Locally install documentation of CTAN packages
          installsrc * --   Locally install sources of CTAN packages
           listfiles * --   List all files in CTAN packages
              search * --   Search info on CTAN packages
         searchfiles * --   Search for files in CTAN packages
             texhash   --   Refresh the TeX file database
               clean   --   Clean local build tree
                help   --   Print helpful information
                quit   --   Quit tllocalmgr

        The commands followed by * take one of more package names as arguments.
        Note that these can be completed automatically by pressing TAB.

        You can also run tllocalmgr as a standard command-line program, with
        one of the above commands as argument, then the corresponding task will
        be performed and the program will exit (except when the command is 'status').

        tllocalmgr accepts the following options:

Options:     --help          Shows this help
             --version       #TODO
             --forceupdate   Force updating the TeXLive database
             --skipupdate    Skip updating the TeXLive database
             --localsearch   Search only installed packages
             --location      #TODO?
             --mirror        CTAN mirror to use (default is mirror.ctan.org)
             --nocolor       #TODO
]
firmicus's avatar
firmicus committed
731
}
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

__END__

my $choice;
unless ($updateall) {
	print BOLD, BLUE, "Which packages do you want to update locally?\n\t> ", RESET ;
	chomp($choice = <STDIN>) ;
} ;

exit 0 if $choice =~ m/^(q|quit)$/i;

my @stack;
if ($updateall or $choice =~ m/^(a|all)$/i) {
	@stack = @updatedpkgs
} else {
	@stack = split /\s+/, $choice;
};

exit 0 unless @stack;


#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
#;