summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ctable/inst
blob: 9754480f51768c8a5e73bb95c9e8d9af4047d170 (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
#!/bin/bash
    dtxname=ctable
    dtxtype=package
        ext=sty
     delete=($dtxname.$ext README.tex doc/\*.tex)
 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 ctable

= Synopsis
inst [options]	

Without any options, inst installs ctable in 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 ctable in one of your TeX trees: TEXMFMAIN, TEXMFLOCAL or TEXMFHOME. 
  The first one writable by you will chosen.
- creates a zip file named |ctable-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/\\\\$//
	/ Author:/i\
Version:| '$dtxversion'
	/<.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
}

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 doc -name '*.ttf' -exec cp {} ~/.fonts \;
   fc-cache ~/.fonts

   readme # create the README file

   # compile all examples
   cd doc
   ln -sf ../$dtxname.sty || exit 1 # use the version to be installed
   for i in [0-9][0-9]?; do 
      if [ ! -f $i.pdf -o ! -f s$i.pdf ]; then
         ./doit || exit 1
         break
      fi
   done
   cd ..
  
   mk --noprint --noview $dtxname.dtx && mk -c $dtxname.dtx # make $dtxname.pdf
}

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

   rm -rf $insttex/* $instsrc/* $instdoc/*
   find doc \( -type l -o -name '*.pdf' \) -delete
   cp -f $dtxname.$ext $insttex
   cp -a $dtxname.{ins,dtx} $instsrc
   cp -a README inst $dtxname.pdf $instdoc
   mktexlsr $tree 2>/dev/null
   for i in ${delete[@]}; do rm -f $i; done 
   cd ..
   zipfile=$dtxname/$dtxname-$dtxversion.zip
   rm -f $zipfile
   zip -rq $zipfile $dtxname/* -x $dtxname/test\*
   cd $dtxname
}

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

testexecs
setdir
makeall
installall