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

Revision 1918, 16.4 KB checked in by munepi, 14 years ago (diff)

update tlpdb2rpmspec.sh.in: improved updmap process in %%post and %%postun

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