/usr/lib/AMC/perl/AMC-latex-link.pl is in auto-multiple-choice-common 1.2.1-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #! /usr/bin/perl
#
# Copyright (C) 2011 Alexis Bienvenue <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice. If not, see
# <http://www.gnu.org/licenses/>.
######################################################################
#
# auto-multiple-choice latex-link :
#
# Tests if the style file automultiplechoice.sty is accessible for
# LaTeX. If not, tries to make a link from a location inside texmf
# directories to the installed style file, and calls mktexlsr
#
# auto-multiple-choice latex-link remove :
#
# remove the link.
#
######################################################################
use AMC::Basic;
for my $c (qw/kpsewhich texconfig-sys/) {
if(!commande_accessible($c)) {
print STDERR "ERROR: I don't find the command $c. Perhaps LaTeX is not installed?\n";
exit(1);
}
}
if($> != 0) {
print "WARNING: This command should be called by root!\n";
}
sub get_tex_var {
my ($k)=@_;
my $v='';
open(SYS,"-|","texconfig-sys","conf")
or die "Can't exec texconfig-sys: $!";
for(<SYS>) {
chomp;
$v=$1 if(/^$k=(.*)/);
}
close(SYS);
return($v);
}
my $conf_dir="/etc/AMC";
my $link_file=$conf_dir."/latex-link";
my $link='';
if(-f $link_file) {
open(LK,$link_file);
while(<LK>) {
chomp;
$link=$_;
}
close(LK);
}
my @styles=get_sty();
sub rehash {
print "Calling mktexlsr to refresh LaTeX files list...\n";
open(LSR,"-|","mktexlsr");
while(<LSR>) {
print $_;
}
close(LSR);
@styles=get_sty();
}
if($ARGV[0] =~ /^(remove|rm)$/i) {
if(-l $link) {
print "Removing link $link...\n";
unlink($link);
if(-e $link) {
print "ERROR: Unsuccessful.\n";
exit(2);
} else {
print("Done.\n");
}
} else {
print "No link to remove.\n";
}
exit(0);
}
if(!@styles) {
rehash();
}
if(@styles) {
print "The style file is already accessible:\n";
for(@styles) {
print "$_\n";
}
if(-l $link) {
print "Use 'auto-multiple-choice latex-link remove' to remove the link\n";
}
} else {
my $loc=get_tex_var('TEXMFLOCAL');
if(! -d $loc) {
print STDERR "ERROR: I don't find TEXMFLOCAL ($loc)\n";
exit(2);
}
my $installed='/usr/share/texmf/tex/latex/AMC/automultiplechoice.sty';
if(! -f $installed) {
print STDERR "ERROR: I don't find the installed style file $installed\n";
exit(2);
}
for my $dir (qw:tex tex/latex:) {
if(! -d "$loc/$dir") {
print "Creating directory $loc/$dir...\n";
mkdir("$loc/$dir");
}
}
$link="$loc/tex/latex/automultiplechoice.sty";
print "Creating link to AMC style file...\n";
symlink($installed,$link);
rehash();
if(@styles) {
if(! -d $conf_dir) {
mkdir($conf_dir);
}
print "Saving to configuration...\n";
open(LF,">$link_file")
or die "Unable to write to $link_file: $!";
print LF "$link\n";
close(LF);
print "Done.\n";
} else {
print "ERROR: Unsuccessful.\n";
}
}
|