summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/isodoc/inst
blob: 555af87cbe8bb74076add38c35921871fbaf6f67 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
    dtxname=isodoc
    dtxtype=class
        ext=cls
     delete=$dtxname.$ext
 dtxversion=$(grep " v[0-9.]\+[a-z]\{0,1\} $dtxname $dtxtype" $dtxname.dtx |sed 's/.* v\([0-9.]\+[a-z]\{,1\}\) .*/\1/')
executables=(mk texlog_extract zip getopt pdfseparate pdflatex)

    version=1.00
     myname=$(basename $0)

<<'DOC'
= inst - install isodoc

= Synopsis
inst [options]	

Without any options, inst installs simplot iin the first writable
TEXMFMAIN, TEXMFLOCAL or TEXMFHOME tree.

Options:
-h,--help	print this help and exit
-H,--Help	print full documentation via less and exit
-V,--version	print version and exit


= Description
inst must be run in its own directory (|./inst|) and then does the following:
- generates the documentation for isodoc,
- installs isodoc in one of your TeX trees: TEXMFMAIN, TEXMFLOCAL or TEXMFHOME. 
  The first one writable by you will chosen.
- creates a zip file named |isodoc-x.yy.zip| for upload to CTAN
- cleans up

= Author and copyright
Author	Wybo Dekker
Email	U{wybo@dekkerdocumenten.nl}{wybo@dekkerdocumenten.nl}
License	Released under the U{www.gnu.org/copyleft/gpl.html}{GNU General Public License}
DOC

    die() { echo -e "$myname: $Err$@$Nor" 1>&2; exit 1; }
   help() { sed -n '/^= Synopsis/,/^= /p' $0|sed '1s/.*/Usage:/;/^= /d'; exit; }
helpall() { sed -n '/^<<.DOC.$/,/^DOC$/p' $0|sed -n '1d;$d;p'|less; exit; }
version() { echo $version; exit; }

Nor='\e[0m'    # reset color	]
Err='\e[31;1m' # light red	]

setdir() { # create installation directory
   for i in MAIN LOCAL HOME; do
      tree=$(kpsewhich --expand-var \$TEXMF$i)
      test -w $tree && break
      tree=
   done
   [[ -n $tree ]] || die "Could not find a writable TeX tree"
   insttex=${tree}/tex/latex/$dtxname
   instsrc=$tree/source/latex/$dtxname
   instdoc=$tree/doc/latex/$dtxname
   mkdir -p $insttex || die could not create $insttex
   mkdir -p $instsrc || die could not create $instsrc
   mkdir -p $instdoc || die could not create $instdoc
}

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

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

clean() { # clean but keep what goes in the zip
   rm -f $dtxname.{aux,fls,glo,gls,idx,ilg,ind,log,out,toc}
   rm -f examples/*/{$dtxname*,*.{pdf,aux,log,fls,out}}
   find examples -type l -delete
}

makeall() {
   grep '%<\*install>' $dtxname.dtx >/dev/null && # for self-extracting dtx files
      delete+=" $dtxname.ins" ||
      echo y |tex $dtxname.ins >/dev/null

   # install any .ttf files
   mkdir -p ~/.fonts
   find examples -name '*.ttf' -exec cp {} ~/.fonts \;
   fc-cache ~/.fonts

   readme # create the README file

   # compile all examples
   cd examples
   for i in *; do
      echo compiling $i
      cd $i
      for j in ../../{$dtxname.cls,languages/isodoc*.ldf}; do ln -sf $j; done
      mk --noprint --noview $i && mk -c $i
      test -e logoletter.pdf && pdfseparate -l 2 logoletter.pdf logo%d.pdf
      cd ..
   done
   cd ..
   # make $dtxname.pdf
   echo compiling the manual
   pdflatex --recorder --interaction=batchmode $dtxname.dtx >/dev/null ||
      die "$(texlog_extract $dtxname.log)"
   test -f $dtxname.glo && makeindex -q -s gglo.ist -o $dtxname.gls $dtxname.glo
   test -f $dtxname.idx && makeindex -q -s gind.ist -o $dtxname.ind $dtxname.idx
   pdflatex --interaction=batchmode $dtxname.dtx > /dev/null
   pdflatex --interaction=batchmode $dtxname.dtx > /dev/null
}

installall() {
   # install and cleanup
   echo installing in $tree
   clean

   rm -rf $insttex/* $instsrc/* $instdoc/* # remove old data in the tree
   cp -f $dtxname.$ext languages/iso* $insttex
   cp -a $dtxname.{ins,dtx} $instsrc
   cp -a README inst languages/isodoc-template.ldf $dtxname.pdf examples/* $instdoc
   mktexlsr $tree 2>/dev/null
   rm -f $delete 
   cd ..
   zipfile=$dtxname/$dtxname-$dtxversion.zip
   rm -f $zipfile
   zip -rq $zipfile $dtxname/*
   cd $dtxname
   rm -f $dtxname.pdf README
}

clean=false
options=$(getopt \
   -n $myname \
   -o hHVc \
   -l help,Help,version,clean \
   -- "$@"
) || exit 1
eval set -- "$options"
while [ $# -gt 0 ]; do
   case $1 in
   (-h|--help)	  help;;
   (-H|--Help)	  helpall;;
   (-V|--version) version;;
   (-c|--clean)	  clean=true;shift;;
   (--)		  shift;  break;;
   (*)			  break;;
   esac
done
[[ -z $1 ]] || die No arguments expected

testexecs
setdir
$clean && clean && rm -f $delete $dtxname-*.zip $dtxname.pdf README && exit 0 
makeall
installall