source: projects/texlive-vtlpkg/trunk/tlpdb2rpmspec.sh.in @ 1499

Revision 1499, 16.1 KB checked in by munepi, 14 years ago (diff)

updated tlpdb2rpmspec.sh.in: updated %post, %postun

  • Property svn:executable set to *
RevLine 
[1476]1#!/bin/bash
2# tlpdb2rpmspec
3#
4# Copyright 2010 Munehiro Yamamoto <munepi@vinelinux.org>
5# This file is licensed under the GNU General Public License version 2
6# or any later version.
7
8Usage(){
9    cat<<EOF
10Usage:  $(basename $0) [option] [pkgname]
11
12This script generates a rpm spec file for CTAN and collection-* packages of TeX Live.
13
14Options:
15        --name:                 return [pkgname]
16        --category:             return the category of [pkgname]
17        --revision:             return the revision of [pkgname]
18        --depend:               return dependencies of [pkgname]
19        --shortdesc:            return the short description of [pkgname]
20        --longdesc:             return the description of [pkgname]
21        --execute:              return post processe of [pkgname]
22        --catalogue-ctan:       return the locate of [pkgname]
23        --catalogue-date:       return the last update of [pkgname]
24        --catalogue-license:    return the license of [pkgname]
25        --catalogue-version:    return the version of [pkgname]
26        --filelist:             return the filelist of [pkgname]
27        --help:                 show this help
28
29Supoort collections-* packages:
30$(egrep "^name collection-" $TLPDB | sed -e "s,name ,,g")
31EOF
32}
33
34check-parameter(){
35    [ -z "$*" ] && Usage && return 1
36
37    while [ ! -z "$*" ]; do
38        case $1 in
[1496]39            --name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist|--minimal-collections|--standard-collections|--full-collections)
[1476]40                [ $with_option -eq 1 ] && \
41                    echo "E: you only give one option" && return 1
42                with_option=1
43                ;;
44            --help)
45                Usage
46                return 1
47                ;;
48            --*)
49                echo "E: unknown option: $1"
50                return 1
51                ;;
52        esac
53        shift
54    done
55
56    return 0
57}
58
59
60## tlpkg4a [--name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist] [pkgname]
61tlpkg4a(){
62    [ $# -eq 2 ] || return 1
63    local opt=$1
64    local pkg=$2
65    local fieldname=$(echo $opt | sed -e "s,--,,")
66
67    ## check param
68    case $opt in
69        --name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist)
70            ;;
71        *)
72            echo "E: unknown option: $opt"
73            exit 1
74            ;;
75    esac
76
77    ## get the head line of $pkg record
78    pkg_LINE=$(egrep -n "^name $pkg$" $TLPDB | cut -d":" -f 1)
79
80    ## read tlpdb
[1496]81    is_pkg=0
[1476]82    tail -n $(( $TLPDB_MAXLINE - $pkg_LINE + 1 )) $TLPDB | \
83        while read field; do
84            ## find the record of $pkg
[1496]85            echo "$field" | egrep -q "^name $pkg" && is_pkg=1
86            [ $is_pkg -eq 0 ] && continue
[1476]87           
88            ## return the values of its field name
89            if [ "$opt" = "--filelist" ]; then
90            ## NOTE: we only need texmf-dist directories
91                echo "$field" | egrep "^texmf-dist" | \
92                    sed -e "s, details=.*,," -e "s, language=.*,,"
93            else
94                echo "$field" | egrep "^${fieldname} " | sed -e "s,${fieldname} ,,"
95            fi
96           
97            ## end of the record of $pkg
98            echo "$field" | egrep -q "^[[:blank:]]*$" && break
99        done
100   
101    return 0
102}
103
104## tlpkg2speclicense [pkgname]
105tlpkg2speclicense(){
106    [ $# -eq 1 ] || return 1
107    local pkg=$1
108
109    case $(tlpkg4a --catalogue-license $pkg) in
110        gpl3) echo "GPLv3+";;
111        gpl2) echo "GPLv2+";;
112        gpl) echo "GPL+";;
113        lppl|lppl1.2|lppl1.3) echo "LPPL";;
114        other-free) echo "Freely redistributable without restriction";;
115        pd) echo "Public Domain";;
116        noinfo) echo "No Info";;
117        lgpl) echo "LGPLv2+";;
118        gfsl) echo "LPPL";;
119        bsd) echo "BSD";;
120        knuth) echo "Knuth";;
121        unknown) echo "Unknown";;
122        gfl) echo "LPPL";;
123        artistic2) echo "Artistic 2.0";;
124        fdl) echo "GFDL";;
125        collection) echo "Public Domain";;
126        artistic) echo "Artistic";;
127        other) echo "Other";;
128        ofl) echo "OFSFLD";;
129        apache2) echo "ASL 2.0";;
130        nosource) echo "No Source";;
131        nosell) echo "No Sell";;
132        nocommercial) echo "Non-commercial";;
133        *) return 1;;
134    esac
135    return 0
136}
137
138## tlpkg2manifest [pkgname]
139tlpkg2manifest(){
140    [ $# -eq 1 ] || return 1
141    local pkg=$1
142    local pkgdeps="$(tlpkg4a --depend $pkg)"
143
144    tlpkg4a --filelist $pkg || return 1
145
[1496]146    ## if $pkg is not collection-*, only return the filelist of $pkg
147    echo $pkg | egrep -q "^collection-" || return 0
148
[1476]149    ##!! we need pure filelist of $pkg; remove collection-*
150    pkgdeps=$(echo $pkgdeps | sed -e "s,collection-[-A-Za-z0-9]*,,g")
151
152    [ -z "$pkgdeps" ] && return 0
153    for i in $pkgdeps; do
154        tlpkg4a --filelist $i || return 1
155    done
156
157    return 0
158}
159
160## tlpkg2maplist [pkgname]
161tlpkg2maplist(){
162    [ $# -eq 1 ] || return 1
163    local pkg=$1
164    local pkgdeps="$(tlpkg4a --depend $pkg)"
165
166    tlpkg4a --execute $pkg | grep -e "Map" | sed -e "s,^add,,g"
167
168    ##!! we need pure filelist of $pkg; remove collection-*
169    pkgdeps=$(echo $pkgdeps | sed -e "s,collection-[-A-Za-z0-9]*,,g")
170
171    [ -z "$pkgdeps" ] && return 0
172    for i in $pkgdeps; do
173        tlpkg4a --execute $i | grep -e "Map" | sed -e "s,^add,,g"
174    done
175
176    return 0
177}
178
[1496]179## tlpkg2inilist [pkgname]
180tlpkg2inilist(){
181    [ $# -eq 1 ] || return 1
182    local pkg=$1
183    local pkgdeps="$(tlpkg4a --depend $pkg)"
[1476]184
[1496]185    ## search AddFormat, AddHypen
186    tlpkg4a --execute $pkg | grep -e "Add"
187
188    ##!! we need pure filelist of $pkg; remove collection-*
189    pkgdeps=$(echo $pkgdeps | sed -e "s,collection-[-A-Za-z0-9]*,,g")
190
191    [ -z "$pkgdeps" ] && return 0
192    for i in $pkgdeps; do
193        tlpkg4a --execute $i | grep -e "Add"
194    done
195
196    return 0
197}
198
[1476]199## mkrpmspec [pkgname]
200mkrpmspec(){
201    [ $# -eq 1 ] || return 1
202    local pkg=$1
203
204    RPM_SUMMARY="TeX Live: $(tlpkg4a --shortdesc $pkg)"
205
206    ## Requires tag for texlive
207    RPM_REQUIRES=$(for i in $(tlpkg4a --depend $pkg | egrep "^collection-" | egrep -v "^collection-documentation"); do echo "Requires: texlive-$i = %{version}"; done)
208    ## collection-langgerman and collection-langcyrillic
209    ## need to complete fmtutil-sys on texlive + texlive-common
210    [ "$pkg" = "collection-basic" ] &&
211    RPM_REQUIRES="${RPM_REQUIRES}
212Requires: texlive-collection-langgerman = %{version}
213Requires: texlive-collection-langcyrillic = %{version}"
214
215    ## License tag
216    RPM_LICENSE="$(tlpkg2speclicense $pkg),"
217    for i in $(tlpkg4a --depend $pkg | egrep -v "^collection-"); do
218        tmp=$(tlpkg2speclicense $i)
219        echo "$RPM_LICENSE" | grep -q "${tmp},"
220        [ $? -eq 1 ] && RPM_LICENSE="${RPM_LICENSE} ${tmp},"
221    done
222    RPM_LICENSE=$(echo "$RPM_LICENSE" | sed -e "s/,$//" | sed -e "s/^, //")
223    [ -z "$RPM_LICENSE" ] && RPM_LICENSE=distributable
224
[1499]225    PKG_SHORTDESC=$(tlpkg4a --shortdesc $pkg)
226    PKG_LONGDESC=$(tlpkg4a --longdesc $pkg)
227
228    PKG_CTANPKGSLIST=$(for i in $(tlpkg4a --depend $pkg); do \
229        if [ -z "$(echo "$i" | grep "collection-")" ]; then \
230            echo -n "$i: "; \
231            tmp=$(tlpkg4a --shortdesc $i); \
232            [ -z "${tmp}" ] && echo || echo "$tmp"; \
233        fi
234        done)
235
236    PKG_MANIFEST=$(tlpkg2manifest $pkg)
237
[1476]238    with_docpkg=0
239    [ -z "$(echo $pkg | grep "collection-documentation")" ] && \
[1499]240        [ ! -z "$(echo "${PKG_MANIFEST}" | grep texmf-dist/doc/)" ] && \
[1476]241        with_docpkg=1
242
[1496]243    with_maplist=0
244    MAPLIST="$(tlpkg2maplist $pkg)"
245    [ ! -z "$MAPLIST" ] && with_maplist=1
246    ##echo $with_maplist && echo "$MAPLIST" && exit
247
248    with_inilist=0
249    INILIST="$(tlpkg2inilist $pkg)"
250    [ ! -z "$INILIST" ] && with_inilist=1
251    ##echo $with_inilist && echo "$INILIST" && exit
252
[1476]253cat<<EOF
254## -*- coding: utf-8-unix -*-
255## NOTE: This spec file is generated by tlpdb2rpmspec.sh ${VERSION}-${RELEASE}:
256## tlpdb2rpmspec.sh collection-basic
257
258%bcond_with firstbuild
259
260%define tex_destdir     %{_datadir}
261%define texmf           %{tex_destdir}/texmf
262%define texlive_src     %{tex_destdir}/texlive-sources
263%define build_tex_destdir       %{buildroot}%{tex_destdir}
264%define build_texmf     %{buildroot}%{texmf}
265
266%define exec_mktexlsr  [ -x %{_bindir}/texconfig-sys ] && PATH=%{_bindir}:\$PATH %{_bindir}/texconfig-sys rehash
267%define exec_texhash  [ -x %{_bindir}/texhash ] && PATH=%{_bindir}:\$PATH %{_bindir}/texhash
268%define exec_updmap   [ -x %{_bindir}/updmap-sys ] && PATH=%{_bindir}:\$PATH %{_bindir}/updmap-sys --nostop
269%define exec_fmtutil  [ -x %{_bindir}/fmtutil-sys ] && PATH=%{_bindir}:\$PATH %{_bindir}/fmtutil-sys --all >/dev/null 2>&1
270%define exec_upddeffont    [ -x %{_sbindir}/update-defaultfont ] && %{_sbindir}/update-defaultfont 2> /dev/null
271%define vartexfonts %{_var}/lib/texmf
272
273%define __find_provides %{nil}
274%define __find_requires %{nil}
275%define __perl_provides %{nil}
276%define __perl_requires %{nil}
277
278Autoreq: 0
279
280Summary: ${RPM_SUMMARY}
[1499]281Summary(ja): ${RPM_SUMMARY}
[1476]282Name: texlive-$pkg
283Version: ${VERSION}
284Release: 1%{?_dist_release}
285License: ${RPM_LICENSE}
286Group: Applications/Publishing
287URL:http://www.tug.org/texlive/
288
289Requires: texlive = %{version}
290$RPM_REQUIRES
291
292Requires(post):         texlive = %{version}
293Requires(postun):       texlive = %{version}
294BuildRequires:          texlive-sources = %{version}
295
296BuildArch:      noarch
297Buildroot:      %{_tmppath}/%{name}-%{version}-root
298
299Vendor:         ${RPM_VENDOR}
300Distribution:   ${RPM_DISTRIBUTION}
301Packager:       ${RPM_PACKAGER}
302
303%description
304The TeX Live software distribution offers a complete TeX system for a
305variety of Unix, Macintosh, Windows and other platforms. It
306encompasses programs for editing, typesetting, previewing and printing
307of TeX documents in many different languages, and a large collection
308of TeX macros and font libraries.
309
310The distribution includes extensive general documentation about TeX,
311as well as the documentation for the included software packages.
312
[1499]313This package is a collection of ${PKG_SHORTDESC}:
314${PKG_LONGDESC}
[1476]315
316This package contains the following CTAN packages:
[1499]317${PKG_CTANPKGSLIST}
[1476]318
[1499]319%description -l ja
320TeX Live ソフトウェアディストリビューションは、
321さまざまな Unix, Macintosh, Windows、および
322他のプラットホームに対して完全な TeX システムを提供します。
323多くの異なった言語を含む TeX ドキュメントの
324編集、組版、閲覧、印刷するためのプログラム、
325そして、TeX マクロやフォントライブラリの大きなコレクションを
326同梱しています。
327
328このディストリビューションは
329同梱しているソフトウェアパッケージのためのドキュメントばかりでなく、
330TeX に関するたくさんの一般的なドキュメントを含んでいます。
331
332このパッケージは以下のようなパッケージ集です。
333${PKG_SHORTDESC}:
334${PKG_LONGDESC}
335
336このパッケージは以下の CTAN パッケージを含んでいます:
337${PKG_CTANPKGSLIST}
338
[1476]339EOF
340
341## subpackage: %{name}-doc
342if [ $with_docpkg -eq 1 ]; then
343    cat<<EOF
344%package doc
345Summary: TeX Live: Documentation files of %{name}
346Group: Applications/Publishing
347Requires: %{name} = %{version}-%{release}
348
349%description doc
350This package contains documentation files of %{name}.
351
352EOF
353fi
354
355cat<<EOF
356%prep
357
358%build
359
360%install
361[ -n "%{buildroot}" -a "%{buildroot}" != / ] && %__rm -rf %{buildroot}
362
363PREF=%{buildroot}%{tex_destdir}
364
365manifest=(
[1499]366${PKG_MANIFEST}
[1476]367)
368
369%__mkdir_p \${PREF}/texmf-dist
370for i in "\${manifest[@]}"; do
371    %__install -D %{texlive_src}/\$i \${PREF}/\$i
372done
373
374## info
375%__rm -f %{buildroot}%{_infodir}/dir
376%__gzip -9nf %{buildroot}%{_infodir}/*info* ||:
377
378## man
379## man t1* files are provided by t1utils
380for i in t1ascii t1asm t1binary t1disasm t1mac t1unmac; do
381    %__rm %{buildroot}%{_mandir}/man*/\${i}.* ||:
382done
383
384## man some files are provided by psutils
385for i in epsffit extractres fixdlsrps fixfmps fixmacps fixpsditps fixpspps fixscribeps fixtpps fixwfwps fixwpps fixwwps getafm includeres psbook psmerge psnup psresize psselect pstops; do
386    %__rm %{buildroot}%{_mandir}/man*/\${i}.* ||:
387done
388
389## remove asymptote directries, which provides asymptote package
390find %{buildroot} -regex ".*asymptote.*" | xargs %__rm -rf
391# find %{buildroot} -name "Makefile" | xargs %__rm -f
392
393# ## remove xindy
394# find %{buildroot} -regex ".*xindy.*" | xargs %__rm -rf
395
396# ## remove tex4ht
397# find %{buildroot} -regex ".*tex4ht.*" | xargs %__rm -rf
398
399## remove unpackaging files
400find %{buildroot} | %__grep -e "\\.\(la\|a\)\$" | xargs %__rm -f
401find %{buildroot} | %__grep -e "\\.\(diff\|patch\)\$" | xargs %__rm -f
402
403## Files list
404find %{buildroot} -type f -or -type l | \\
405    %__sed -e "s|%{buildroot}||g" > filelist.full
406
407find %{buildroot}%{texmf}-dist -type d | \\
408    %__sed -e "s|^%{buildroot}|%dir |" \\
409           -e "s|\$|/|"             >> filelist.full
410
411EOF
412
413## subpackage: %{name}-doc
414if [ $with_docpkg -eq 1 ]; then
415    cat<<EOF
416## subpackages
417grep "/texmf-dist/doc/" filelist.full > filelist.doc
418cat filelist.doc filelist.full | sort | uniq -u > filelist.tmp
419%__mv -f filelist.tmp filelist.full
420
421EOF
422fi
423
424cat<<EOF
425%clean
426%__rm -rf %{buildroot}
427
428%post
429%{exec_texhash}
[1496]430
431EOF
432
433## Running updmap
434if [ $with_maplist -eq 1 ]; then
435    cat<<EOF
[1498]436[ -f %{texmf}/web2c/updmap.cfg ] || exit 0
437
[1496]438$(echo "$MAPLIST" | while read maptype map; do \
439    cat<<EOT
[1499]440    %{exec_updmap} --listmaps 2>/dev/null | egrep -q "^#! ${maptype} ${map}" && \\
441        echo -n "    " && \\
442        echo -n "Running updmap: enable ${map} ... " && \\
443        %{exec_updmap} --enable ${maptype} ${map} >/dev/null 2>&1 && \\
444        echo "done."
[1496]445EOT
446done)
447
448EOF
[1476]449fi
450
[1496]451## Running fmtutil
452if [ $with_inilist -eq 1 ]; then
453    cat<<EOF
454echo -n "    "
455echo -n "Running fmtutil ... " && %{exec_fmtutil} && echo "done."
456
457EOF
[1476]458fi
459
[1496]460cat<<EOF
[1476]461exit 0
462
463
464%postun
465if [ "\$1" = 0 ]; then
466    %{exec_texhash}
[1496]467
468EOF
469
470## Running updmap
471if [ $with_maplist -eq 1 ]; then
472    cat<<EOF
[1498]473    [ -f %{texmf}/web2c/updmap.cfg ] || exit 0
474
[1496]475$(echo "$MAPLIST" | while read maptype map; do \
476    cat<<EOT
[1499]477    %{exec_updmap} --listmaps 2>/dev/null | egrep -q "^${maptype} ${map}" && \\
478        echo -n "    " && \\
479        echo -n "Running updmap: disable ${map} ... " && \\
[1496]480        %{exec_updmap} --disable ${map} >/dev/null 2>&1 && \\
481        echo "done."
482EOT
483done)
484
485EOF
[1476]486fi
487
[1496]488cat<<EOF
489fi
490
[1476]491exit 0
492
493%files -f filelist.full
494%defattr(-,root,root)
495
496EOF
497## subpackage: %{name}-doc
498if [ $with_docpkg -eq 1 ]; then
499    cat<<EOF
500%files -f filelist.doc doc
501%defattr(-,root,root)
502
503EOF
504fi
505
506cat<<EOF
507%changelog
508* $(LANG=C date +%a) $(LANG=C date +%b) $(date +%d) $(date +%Y) ${RPM_GPG_NAME} ${VERSION}-${RELEASE}
509- generated by $(basename $0) ${VERSION}-${RELEASE}: $(basename $0) $(echo $*)
510EOF
511
512    return 0
513}
514
515setup-tlpdb2rpmspec(){
516    ## load your .vtlpkg.conf
517    if [ -f ${HOME}/.vtlpkg.conf ]; then
518        . ${HOME}/.vtlpkg.conf
519    else
520        echo "E: ${HOME}/.vtlpkg.conf: No such file"
521        return 1
522    fi
523
524    [ -z "$RPM_VENDOR" ] && \
525        echo "E: \$RPM_VENDOR is empty" && exit 1
526    [ -z "$RPM_DISTRIBUTION" ] && \
527        echo "E: \$RPM_DISTRIBUTION is empty" && exit 1
528    [ -z "$RPM_GPG_NAME" ] && \
529        echo "E: \$RPM_GPG_NAME is empty" && exit 1
530    [ -z "$RPM_PACKAGER" ] && \
531        echo "E: \$RPM_PACKAGER is empty" && exit 1
532
533    ## setup configurations
534    VERSION=@@VTLPKG_VERSION@@
535    RELEASE=@@VTLPKG_RELEASE@@
536
537    ## set a tlpdb file for TeX Live, which is a package database file.
538    TLPDB=@@VTLPKG_TLPDB@@
539    TLPDB_MAXLINE=$(wc -l $TLPDB | cut -d" " -f 1)
540
541    ## set some booleans
542    with_option=0
543}
544
545##############################################################################
546
547setup-tlpdb2rpmspec || exit 1
548
549check-parameter $* || exit 1
550
551case $1 in
552    --name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist)
553        tlpkg4a $1 $2 || exit 1
554        ;;
555    --minimal-collections)
556        [ ! -f /etc/vine-release ] && echo "E: support Vine Linux only" && exit 1
557        ## minimal installation needs to build texlive (secondbuild)
558        for i in collection-langgerman \
559                 collection-langcyrillic \
560                 collection-xetex \
561                 collection-latexrecommended \
562                 collection-latex \
563                 collection-fontsrecommended \
564                 collection-basic; do
565            $0 $i > texlive-${i}-vl.spec
566            rpmbuild -ba texlive-${i}-vl.spec || exit 1
567        done
568        ;;
569    --standard-collections)
570        [ ! -f /etc/vine-release ] && echo "E: support Vine Linux only" && exit 1
[1477]571        for i in collection-context \
[1476]572            collection-latexextra \
573            collection-luatex \
574            collection-pictures \
575            collection-genericrecommended \
576            collection-pstricks \
577            collection-documentation-english; do
578            $0 $i > texlive-${i}-vl.spec
579            rpmbuild -ba texlive-${i}-vl.spec || exit 1
580        done
581        ;;
582    --full-collections)
583        [ ! -f /etc/vine-release ] && echo "E: support Vine Linux only" && exit 1
[1496]584        for i in $($0 | egrep "^collection-"); do
[1476]585            $0 $i > texlive-${i}-vl.spec
586            rpmbuild -ba texlive-${i}-vl.spec || exit 1
587        done
588        ;;
589    *)
590        mkrpmspec $1 || exit 1
591        ;;
592esac
593
594exit
595
596### end of file
Note: See TracBrowser for help on using the repository browser.