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

Revision 1521, 15.7 KB checked in by munepi, 14 years ago (diff)

updated tlpdb2rpmspec.sh.in: added category.list

  • 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                echo "E: unknown option: $1"
54                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 tlpdb2rpmspec.sh ${VERSION}-${RELEASE}:
260## tlpdb2rpmspec.sh collection-basic
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: 1%{?_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} --enable ${maptype} ${map} >/dev/null 2>&1 && \\
448        echo "done."
449EOT
450done)
451
452EOF
453fi
454
455## Running fmtutil
456if [ $with_inilist -eq 1 ]; then
457    cat<<EOF
458echo -n "    "
459echo -n "Running fmtutil ... " && %{exec_fmtutil} && echo "done."
460
461EOF
462fi
463
464cat<<EOF
465exit 0
466
467
468%postun
469if [ "\$1" = 0 ]; then
470    %{exec_texhash}
471
472EOF
473
474## Running updmap
475if [ $with_maplist -eq 1 ]; then
476    cat<<EOF
477    [ -f %{texmf}/web2c/updmap.cfg ] || exit 0
478
479$(echo "$MAPLIST" | while read maptype map; do \
480    cat<<EOT
481    %{exec_updmap} --listmaps 2>/dev/null | egrep -q "^${maptype} ${map}" && \\
482        echo -n "    " && \\
483        echo -n "Running updmap: disable ${map} ... " && \\
484        %{exec_updmap} --disable ${map} >/dev/null 2>&1 && \\
485        echo "done."
486EOT
487done)
488
489EOF
490fi
491
492cat<<EOF
493fi
494
495exit 0
496
497%files -f filelist.full
498%defattr(-,root,root)
499
500EOF
501## subpackage: %{name}-doc
502if [ $with_docpkg -eq 1 ]; then
503    cat<<EOF
504%files -f filelist.doc doc
505%defattr(-,root,root)
506
507EOF
508fi
509
510cat<<EOF
511%changelog
512* $(LANG=C date +%a) $(LANG=C date +%b) $(date +%d) $(date +%Y) ${RPM_GPG_NAME} ${VERSION}-${RELEASE}
513- generated by $(basename $0) ${VERSION}-${RELEASE}: $(basename $0) $(echo $*)
514EOF
515
516    return 0
517}
518
519## mkrpmcollection [--minimal-collections|--standard-collections|--full-collections]
520mkrpmcollection(){
521    local category=$(echo $1 | sed -e "s/--\([a-z]*\)-collections/\1/")
522    local category_pkglist=
523    local i=
524
525    case $category in
526        minimal|standard)
527            category_pkglist=$(grep -e "${category}," $CATEGORYLIST | sed -e "s/${category},//g" | sed -e "s/,$//g")
528            ;;
529        full)
530            category_pkglist=$(Usage | egrep "^collection-")
531            ;;
532        *)
533            echo "E: unknown category: $category"
534            return 1
535            ;;
536    esac
537
538    for i in ${category_pkglist}; do
539        mkrpmspec $i > texlive-${i}-vl.spec
540        rpmbuild -ba texlive-${i}-vl.spec || return 1
541    done
542
543    return 0
544}
545
546setup-tlpdb2rpmspec(){
547    ## load your .vtlpkg.conf
548    if [ -f ${HOME}/.vtlpkg.conf ]; then
549        . ${HOME}/.vtlpkg.conf
550    else
551        echo "E: ${HOME}/.vtlpkg.conf: No such file"
552        return 1
553    fi
554
555    [ -z "$RPM_VENDOR" ] && \
556        echo "E: \$RPM_VENDOR is empty" && exit 1
557    [ -z "$RPM_DISTRIBUTION" ] && \
558        echo "E: \$RPM_DISTRIBUTION is empty" && exit 1
559    [ -z "$RPM_GPG_NAME" ] && \
560        echo "E: \$RPM_GPG_NAME is empty" && exit 1
561    [ -z "$RPM_PACKAGER" ] && \
562        echo "E: \$RPM_PACKAGER is empty" && exit 1
563
564    ## setup configurations
565    VERSION=@@VTLPKG_VERSION@@
566    RELEASE=@@VTLPKG_RELEASE@@
567
568    ## set a tlpdb file for TeX Live, which is a package database file.
569    TLPDB=@@VTLPKG_TLPDB@@
570    TLPDB_MAXLINE=$(wc -l $TLPDB | cut -d" " -f 1)
571
572    ## category of collection-*
573    CATEGORYLIST=@@VTLPKG_CATEGORYLIST@@
574
575    ## set some booleans
576    with_option=0
577}
578
579##############################################################################
580
581setup-tlpdb2rpmspec || exit 1
582
583check-parameter $* || exit 1
584
585case $1 in
586    --name|--category|--revision|--depend|--shortdesc|--longdesc|--execute|--catalogue-ctan|--catalogue-date|--catalogue-license|--catalogue-version|--filelist)
587        tlpkg4a $1 $2 || exit 1
588        ;;
589    --minimal-collections|--standard-collections|--full-collections)
590        mkrpmcollection $1 || exit 1
591        ;;
592    *)
593        mkrpmspec $1 || exit 1
594        ;;
595esac
596
597exit
598
599### end of file
Note: See TracBrowser for help on using the repository browser.