0698baea4a4e8fae1b80cbb5c4fd0adcf00ace24
[gentoo.git] / app-text / sgml-common / sgml-common-0.6.3-r7.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit prefix sgml-catalog-r1
7
8 DESCRIPTION="Base ISO character entities and utilities for SGML"
9 HOMEPAGE="https://www.iso.org/standard/16387.html"
10 SRC_URI="https://dev.gentoo.org/~floppym/dist/${PN}/${P}-gentoo.tar.gz"
11
12 # install-catalog is GPL
13 LICENSE="FDL-1.1+ GPL-2"
14 SLOT="0"
15 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
16 IUSE=""
17
18 DEPEND=""
19 RDEPEND=""
20
21 PATCHES=( "${FILESDIR}"/${P}-prefix.patch )
22
23 src_prepare() {
24         # We use a hacked version of install-catalog that supports the ROOT
25         # variable, puts quotes around the CATALOG files, and can be prefixed.
26         cp "${FILESDIR}/${P}-install-catalog.in" "${S}/bin/install-catalog.in" \
27                 || die "Copy of install-catalog.in failed"
28
29         default
30         eprefixify bin/install-catalog.in bin/sgmlwhich config/sgml.conf
31 }
32
33 src_install() {
34         default
35
36         # own /etc/sgml/catalog
37         insinto /etc/sgml
38         newins - catalog <<<''
39         newins - sgml-ent.cat <<-EOF
40                 CATALOG "${EPREFIX}/usr/share/sgml/sgml-iso-entities-8879.1986/catalog"
41         EOF
42         newins - sgml-docbook.cat <<-EOF
43                 CATALOG "${EPREFIX}/etc/sgml/sgml-ent.cat"
44         EOF
45 }
46
47 pkg_preinst() {
48         # preserve old files
49         local f
50         for f in /etc/sgml/{catalog,sgml-docbook.cat}; do
51                 if [[ -s ${EROOT}${f} ]]; then
52                         cp "${EROOT}${f}" "${ED}${f}" || die
53                 fi
54         done
55
56         # and back them up in case postrm killed them
57         for f in sgml-ent.cat sgml-docbook.cat; do
58                 cp "${ED}/etc/sgml/${f}" "${T}" || die
59         done
60 }
61
62 pkg_postinst() {
63         # restore backed up files if necessary
64         for f in sgml-ent.cat sgml-docbook.cat; do
65                 if ! cmp -s "${T}/${f}" "${EROOT}/etc/sgml/${f}"; then
66                         cp "${T}/${f}" "${EROOT}"/etc/sgml/ || die
67                 fi
68         done
69
70         # re-append sgml-ent.cat if necessary
71         if ! grep -q -s sgml-ent.cat "${EROOT}/etc/sgml/sgml-docbook.cat"; then
72                 ebegin "Adding sgml-ent.cat to /etc/sgml/sgml-docbook.cat"
73                 cat >> "${EROOT}/etc/sgml/sgml-docbook.cat" <<-EOF
74                         CATALOG "${EPREFIX}/etc/sgml/sgml-ent.cat"
75                 EOF
76                 eend ${?}
77         fi
78
79         sgml-catalog-r1_pkg_postinst
80 }
81
82 pkg_postrm() {
83         if [[ -z ${REPLACED_BY_VERSION} ]]; then
84                 ebegin "Removing sgml-ent.cat from /etc/sgml/sgml-docbook.cat"
85                 sed -i -e '/sgml-ent\.cat/d' \
86                         "${EROOT}"/etc/sgml/sgml-docbook.cat
87                 eend ${?}
88                 if [[ ! -s ${EROOT}/etc/sgml/sgml-docbook.cat ]]; then
89                         rm -f "${EROOT}"/etc/sgml/sgml-docbook.cat
90                 fi
91         fi
92
93         sgml-catalog-r1_pkg_postrm
94 }