summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/isodoc/inst
blob: d458c8a2c6258473b4b133cf8152e846f0666cdd (plain)
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
#!/bin/bash

       NAME=isodoc
    DOCTYPE=class
        EXT=cls
    VERSION=`grep " v[0-9.]\+[a-z]\{,1\} $NAME $DOCTYPE" $NAME.dtx |sed 's/.* v\([0-9.]\+[a-z]\{,1\}\) .*/\1/' `
EXECUTABLES=(pdfseparate zip unzip getopt)

function die {
   echo -e "$*"
   exit 1
}

function help {
   cat <<-EOD
	This is inst - install the $NAME LaTeX $DOCTYPE
	Options:
	-h, --help	print this help
	-c, --clean     remove all files created by the installation, except the zip file
	-C, --Clean	remove all files that can be regenerated
	-z, --zip	Create zip for CTAN (developer only)

	Without any options, inst creates $NAME.{$EXT,ins,pdf} and installs these, 
	in the local TeX tree (\$TEXMFLOCAL) or, if that is not writable,
	in the user´s TeX tree (\$TEXMFHOME). Also, a zip file is created for upload to CTAN.
	EOD
   exit
}

function setdir { # create installation directory
   TREE=$(kpsewhich --expand-var '$TEXMFLOCAL')
   test -w $TREE || TREE=$(kpsewhich --expand-var '$TEXMFHOME')
   test "$TREE" = "" && die Could not find value for $TREE
   INSTDIR=${TREE}/tex/latex/$NAME
   SOURCE=$TREE/source/latex/$NAME
   mkdir -p $INSTDIR || die could not create $INSTDIR
   mkdir -p $SOURCE || die could not create $SOURCE
}

function testexecs { # test presence of executables
   for i in ${EXECUTABLES[*]}; do
      type $i &> /dev/null || die executable $i not found
   done
}

function readme { # generate the README file
sed -n '/^%<\*readme>/,/^%<\/readme>/p
	/\\changes{v'$VERSION'}/,/^% }/p' $NAME.dtx  |
sed    's/^%//;s/\\\\$//
	/<.readme>/d
	/^ }/d
	s/ \\changes.*/Changes in version '$VERSION':/
	s/$\\Rightarrow\$/=>/g
	s/\\textbackslash/\\/g
	s/\\text\(sl\|it\){\([^}]\+\)}/\/\2\//g		# \textsl{...} -> /.../
	s/{\([^}]*\)}/\1/g 				# keep last, removes all {...}
       ' >README
}

function clean { # clean but keep what goes in the zip
   rm -f $NAME.{aux,fls,glo,gls,idx,ilg,ind,log,out,toc}
   rm -f examples/*/{$NAME*,*.{pdf,aux,log,out}}
}

function Clean {
   clean
   rm -f $NAME.{$EXT,pdf} README
}

function makeall {
   echo y |tex $NAME.ins >/dev/null
   # install any .ttf files
   mkdir -p ~/.fonts
   find examples -name '*.ttf' -exec cp {} ~/.fonts \;
   fc-cache ~/.fonts

   # compile all examples

   cd examples
   for i in *; do
      # skip dirs that aren't yet added:
      test "$(hg st $i|wc -l)" = "$(ls $i|wc -l)" && continue
      cd $i
      for j in ../../{$NAME.cls,languages/isodoc*.ldf}; do ln -sf $j; done
      read TEX <$i.tex
      if [[ $TEX =~ ^%! ]]; then TEX=${TEX#%!}; else TEX=pdflatex;fi
      $TEX --interaction=batchmode $i >/dev/null || die error compiling $i
      $TEX --interaction=batchmode $i >/dev/null || die error compiling $i
      test -e logoletter.pdf && pdfseparate -l 2 logoletter.pdf logo%d.pdf
      cd ..
   done
   cd ..
   # make $NAME.pdf
   pdflatex --recorder --interaction=batchmode $NAME.dtx >/dev/null ||
      die "`texlog_extract $NAME.log`"
   test -f $NAME.glo && makeindex -q -s gglo.ist -o $NAME.gls $NAME.glo
   test -f $NAME.idx && makeindex -q -s gind.ist -o $NAME.ind $NAME.idx
   pdflatex --interaction=batchmode $NAME.dtx > /dev/null
   pdflatex --interaction=batchmode $NAME.dtx > /dev/null
}

function installall {
   # install and cleanup
   echo installing in $INSTDIR
   mv -f $NAME.{$EXT,pdf} $INSTDIR
   cp -a languages $INSTDIR
   cp -a $NAME.{ins,dtx} $SOURCE
   mktexlsr $TREE 2>/dev/null
   clean
}

function mkzip {
   clean
   readme
   cd ..
   zipfile=$NAME/$NAME-$VERSION.zip
   rm -f $zipfile
   zip -Drq $zipfile $NAME/* -x $NAME/test/*
   cd $NAME
   Clean
}

testexecs
setdir

if ! options=$(getopt -o hcz \
                      -l help,clean,zip -- "$@"); then exit 1; fi
eval set -- "$options"

while [ $# -gt 0 ]; do
   case $1 in
   -c|--clean) Clean; exit;;
   -z|--zip)   makeall; mkzip; exit;;
   -h|--help)  help;;
   (--)        shift; break;;
   (*)         break;;
   esac
   shift
done
test "$1" = "" || die No arguments expected

makeall
installall