File: postinst

package info (click to toggle)
xmltex 1.9-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 328 kB
  • ctags: 24
  • sloc: xml: 867; sh: 165; makefile: 52
file content (193 lines) | stat: -rw-r--r-- 4,561 bytes parent folder | download
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# postinst script for xmltex
#
# pieces cribbed from xmltex postinst
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

FMTDIR=/etc/texmf/fmt.d
TEXMFDIR=/etc/texmf/texmf.d
TMPLDIR=/usr/share/texmf/tex/xmltex/templates
umask 022

warn ( ) {
   echo $* 1>&2
}

installconf () {
    # mv on disable file or copy template
    while [ $# -gt 0 ]; do
        conffile=$1
        shift
        if [ -f $conffile ] ; then
           :
        elif [ -f $conffile.disable ]; then
            mv $conffile.disable $conffile
        else
            cp $TMPLDIR/`basename $conffile` $conffile
        fi
    done
}

checkconf ( ) {
    # Treat old conffiles
    if [ -f $TEXMFDIR/20xmltex ] ; then
        mv $TEXMFDIR/20xmltex $TEXMFDIR/20xmltex.cnf
    fi

    if [ -f /etc/texmf/xmltex.cfg ] ; then
        mv -f /etc/texmf/xmltex.cfg /etc/texmf/xmltex/xmltex.cfg
    fi

    # copy template files
    installconf $TEXMFDIR/20xmltex.cnf $FMTDIR/40xmltex.cnf
    
}

checkfmt ( ) {
    format=$1
    baseformat=$(basename $1 .efmt)
    if ! kpsewhich $format > /dev/null ; then
        warn "WARNING: $format not found, attempting to reconstruct ..."
        echo "running 'fmtutil --byfmt $baseformat'" >> $MYTMP
        fmtutil --byfmt $baseformat >> $MYTMP
        if kpsewhich $format > /dev/null ; then
            warn "Success"
        else
            warn "*** ERROR: cannot create TeX memory dump $format"
            warn "*** see $MYTMP for details"
            exit 1
        fi
    fi
}

makexmltexfmt ( ) {
    local goterror
    goterror=false

    if ! fmtutil --byfmt xmltex >> $MYTMP
    then
        warn "ERROR: xmltex fmtutil failed" 1>&2
        goterror=true
    fi
    if ! fmtutil --byfmt pdfxmltex >> $MYTMP
    then
        warn "ERROR: pdfxmltex fmtutil failed" 1>&2
        goterror=true
    fi
    if $goterror; then
        return 1
    else
        return 0
    fi
}

xmltexfmtcheck ( ) {
    # check whether it actually worked, since the texconfig program
    # doesn't exit non-zero

    if grep -q '^xmltex[[:space:]]*tex' $FMTDIR/40xmltex.cnf; then
	xml_fmt="xmltex.fmt";
    else
	xml_fmt="xmltex.efmt";
    fi;

    if grep -q '^pdfxmltex[[:space:]]*pdftex' $FMTDIR/40xmltex.cnf; then
	pdf_fmt="pdfxmltex.fmt";
    else
	pdf_fmt="pdfxmltex.efmt";
    fi;


    # file exists test
    local goterror
    goterror=false
    if ! kpsewhich $xml_fmt > /dev/null ; then
        warn "ERROR: XMLTeX memory dump ($xml_fmt) cannot be found"
        goterror=true
    fi
    if ! kpsewhich $pdf_fmt > /dev/null ; then
        warn "ERROR: PDFXMLTeX memory dump ($pdf_fmt) cannot be found"
        goterror=true
    fi

    if $goterror; then
        return -1
    else
        return 0
    fi
}



case "$1" in
    configure)
        checkconf

        update-fmtutil

        update-texmf

	texhash

	MYTMP=$(mktemp /tmp/xmltex-postinst.XXXXXX)
	: >| $MYTMP

	echo -e "Checking for TeX format files  we depend on ... \c"
	checkfmt latex.fmt
	checkfmt pdflatex.fmt
	echo "done."

	echo "Creating xmltex format files..."
	if makexmltexfmt && xmltexfmtcheck; then
            echo "Done."
        else
	    echo "Trying fmtutil --all"
	    fmtutil --all >>$MYTMP
	    if xmltexfmtcheck; then
		echo "   done."
            else
                echo "*** ERROR: can't make xmltex fmt files, bailing "
                echo "*** see $MYTMP for details"
                exit 1
            fi
        fi
	texlinks
	texhash
	;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 0
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0