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

Revision 2499, 17.2 KB checked in by munepi, 13 years ago (diff)

updated tlpdb2rpmspec.sh.in: improved %%post

  • 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## fix perl path
394for i in source/metapost/expressg/expressg.dtx \\
395         doc/metapost/expressg/n2mpsprl.prl \\
396         doc/latex/songbook/contrib/crd2sb/crd2sb; do
397    [ -f %{build_texmf}-dist/\${i} ] && \\
398        %__sed -i -e "s|^#!/usr/local/bin/perl|#!%{__perl}|" %{build_texmf}-dist/\${i}
399done
400
401## remove asymptote directries, which provides asymptote package
402find %{buildroot} -regex ".*asymptote.*" | xargs %__rm -rf
403# find %{buildroot} -name "Makefile" | xargs %__rm -f
404
405# ## remove xindy
406# find %{buildroot} -regex ".*xindy.*" | xargs %__rm -rf
407
408# ## remove tex4ht
409# find %{buildroot} -regex ".*tex4ht.*" | xargs %__rm -rf
410
411## remove arch dependent binaries
412%__rm -f %{build_texmf}-dist/source/latex/splitindex/splitindex-{OpenBSD,Linux}-i386
413
414## remove unpackaging files
415find %{buildroot} | %__grep -e "\\.\(la\|a\)\$" | xargs %__rm -f
416find %{buildroot} | %__grep -e "\\.\(diff\|patch\)\$" | xargs %__rm -f
417
418## Files list
419find %{buildroot} -type f -or -type l | \\
420    %__sed -e "s|%{buildroot}||g" > filelist.full
421
422find %{buildroot}%{texmf}-dist -type d | \\
423    %__sed -e "s|^%{buildroot}|%dir |" \\
424           -e "s|\$|/|"             >> filelist.full
425
426EOF
427
428## subpackage: %{name}-doc
429if [ $with_docpkg -eq 1 ]; then
430    cat<<EOF
431## subpackages
432grep "/texmf-dist/doc/" filelist.full > filelist.doc
433cat filelist.doc filelist.full | sort | uniq -u > filelist.tmp
434%__mv -f filelist.tmp filelist.full
435
436EOF
437fi
438
439cat<<EOF
440%clean
441%__rm -rf %{buildroot}
442
443%post
444%{exec_texhash}
445
446EOF
447
448## Running updmap
449if [ $with_maplist -eq 1 ]; then
450    cat<<EOF
451[ -f %{texmf}/web2c/updmap.cfg ] || exit 0
452
453updmap_lock=%{texmf}/updmap.lock
454$(echo "$MAPLIST" | while read maptype map; do \
455    cat<<EOT
456%{exec_updmap} --listmaps 2>/dev/null | egrep -q "^#! ${maptype} ${map}" && \\
457    echo -n "    " && \\
458    echo -n "Running updmap: enable ${map} ... " && \\
459    %{exec_updmap} --nomkmap --enable ${maptype} ${map} >/dev/null 2>&1 && \\
460    echo "done." && \\
461    touch \${updmap_lock}
462EOT
463done)
464
465rpm -q --quiet texlive-common || exit 0
466
467[ -f \${updmap_lock} ] && \\
468    echo -n "    " && \\
469    echo -n "Running updmap: recreate map files ... " && \\
470    %{exec_updmap} >/dev/null 2>&1 && \\
471    echo "done." && \\
472    rm -f \${updmap_lock}
473
474EOF
475fi
476
477## Running fmtutil
478if [ $with_inilist -eq 1 ]; then
479    cat<<EOF
480rpm -q --quiet texlive-common || exit 0
481
482echo -n "    "
483echo -n "Running fmtutil ... " && %{exec_fmtutil} && echo "done."
484
485EOF
486fi
487
488cat<<EOF
489exit 0
490
491
492%postun
493if [ "\$1" = 0 ]; then
494    %{exec_texhash}
495
496EOF
497
498## Running updmap
499if [ $with_maplist -eq 1 ]; then
500    cat<<EOF
501    [ -f %{texmf}/web2c/updmap.cfg ] || exit 0
502
503$(echo "$MAPLIST" | while read maptype map; do \
504    cat<<EOT
505    %{exec_updmap} --listmaps 2>/dev/null | egrep -q "^${maptype} ${map}" && \\
506        echo -n "    " && \\
507        echo -n "Running updmap: disable ${map} ... " && \\
508        %{exec_updmap} --nomkmap --disable ${map} >/dev/null 2>&1 && \\
509        echo "done."
510EOT
511done)
512    echo -n "    " && \\
513        echo -n "Running updmap: recreate map files ... " && \\
514        %{exec_updmap} >/dev/null 2>&1 && \\
515        echo "done."
516
517EOF
518fi
519
520cat<<EOF
521fi
522
523exit 0
524
525%files -f filelist.full
526%defattr(-,root,root)
527
528EOF
529## subpackage: %{name}-doc
530if [ $with_docpkg -eq 1 ]; then
531    cat<<EOF
532%files -f filelist.doc doc
533%defattr(-,root,root)
534
535EOF
536fi
537
538cat<<EOF
539%changelog
540* $(LANG=C date +%a) $(LANG=C date +%b) $(date +%d) $(date +%Y) ${RPM_GPG_NAME} ${VERSION}-${RELEASE}
541- generated by $(basename $0) ${VERSION}-${RELEASE}: $(basename $0) $(echo $*)
542- improved %%post
543
544* Fri Oct 01 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-2
545- generated by $(basename $0) 2009-2: $(basename $0) $(echo $*)
546- removed arch dependent binaries (texlive-collection-latexextra)
547- fixed perl path
548- improved updmap process in %%post and %%postun
549
550* Sat Aug 07 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-1
551- generated by $(basename $0) 2009-1: $(basename $0) $(echo $*)
552EOF
553
554    return 0
555}
556
557## mkrpmcollection [--minimal-collections|--standard-collections|--full-collections]
558mkrpmcollection(){
559    local category=$(echo $1 | sed -e "s/--\([a-z]*\)-collections/\1/")
560    local category_pkglist=
561    local i=
562
563    case $category in
564        minimal|standard)
565            category_pkglist=$(grep -e "${category}," $CATEGORYLIST | sed -e "s/${category},//g" | sed -e "s/,$//g")
566            ;;
567        full)
568            category_pkglist=$(Usage | egrep "^collection-")
569            ;;
570        *)
571            echo "E: unknown category: $category"
572            return 1
573            ;;
574    esac
575
576    for i in ${category_pkglist}; do
577        mkrpmspec $i > texlive-${i}-vl.spec
578        if [ $? -eq 1 ]; then
579            echo "texlive-${i}-vl.spec: "
580            cat texlive-${i}-vl.spec
581            rm -f texlive-${i}-vl.spec
582            continue
583        fi
584        rpmbuild -ba texlive-${i}-vl.spec || return 1
585    done
586
587    return 0
588}
589
590setup-tlpdb2rpmspec(){
591    ## load your .vtlpkg.conf
592    if [ -f ${HOME}/.vtlpkg.conf ]; then
593        . ${HOME}/.vtlpkg.conf
594    else
595        echo "E: ${HOME}/.vtlpkg.conf: No such file"
596        return 1
597    fi
598
599    [ -z "$RPM_VENDOR" ] && \
600        echo "E: \$RPM_VENDOR is empty" && exit 1
601    [ -z "$RPM_DISTRIBUTION" ] && \
602        echo "E: \$RPM_DISTRIBUTION is empty" && exit 1
603    [ -z "$RPM_GPG_NAME" ] && \
604        echo "E: \$RPM_GPG_NAME is empty" && exit 1
605    [ -z "$RPM_PACKAGER" ] && \
606        echo "E: \$RPM_PACKAGER is empty" && exit 1
607
608    ## setup configurations
609    VERSION=@@VTLPKG_VERSION@@
610    RELEASE=@@VTLPKG_RELEASE@@
611
612    ## set a tlpdb file for TeX Live, which is a package database file.
613    TLPDB=@@VTLPKG_TLPDB@@
614    TLPDB_MAXLINE=$(wc -l $TLPDB | cut -d" " -f 1)
615
616    ## category of collection-*
617    CATEGORYLIST=@@VTLPKG_CATEGORYLIST@@
618
619    ## set some booleans
620    with_option=0
621}
622
623##############################################################################
624
625setup-tlpdb2rpmspec || exit 1
626
627check-parameter $* || exit 1
628
629case $1 in
630    --name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist)
631        tlpkg4a $1 $2 || exit 1
632        ;;
633    --minimal-collections|--standard-collections|--full-collections)
634        mkrpmcollection $1 || exit 1
635        ;;
636    *)
637        mkrpmspec $1 || exit 1
638        ;;
639esac
640
641exit
642
643### end of file
Note: See TracBrowser for help on using the repository browser.