app-backup/backuppc: un-remove systemd service file in v3.3.1.
[gentoo.git] / app-backup / backuppc / backuppc-3.3.1-r1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit depend.apache eutils user systemd
8
9 MY_P="BackupPC-${PV}"
10
11 DESCRIPTION="High-performance backups to a server's disk"
12 HOMEPAGE="http://backuppc.sourceforge.net/"
13 SRC_URI="mirror://sourceforge/${PN}/${MY_P}.tar.gz"
14
15 LICENSE="GPL-2"
16 KEYWORDS="~amd64 ~x86"
17
18 IUSE="rss samba"
19
20 # The CGI modules are handled in $RDEPEND.
21 APACHE_MODULES="apache2_modules_alias," # RedirectMatch
22 APACHE_MODULES+="apache2_modules_authn_core," # AuthType
23 APACHE_MODULES+="apache2_modules_authz_core," # Require
24 APACHE_MODULES+="apache2_modules_authz_host," # Require host
25 APACHE_MODULES+="apache2_modules_authz_user" # Require valid-user
26
27 DEPEND="dev-lang/perl
28         app-admin/apache-tools
29         app-admin/makepasswd"
30
31 # Older versions of mod_perl think they're compatibile with apache-2.4,
32 # so we require the new one explicitly.
33 RDEPEND="${DEPEND}
34         virtual/perl-IO-Compress
35         dev-perl/Archive-Zip
36         dev-perl/libwww-perl
37         app-arch/tar
38         app-arch/par2cmdline
39         app-arch/gzip
40         app-arch/bzip2
41         virtual/mta
42         >=www-apache/mod_perl-2.0.9
43         www-apache/mpm_itk
44         || ( >=www-servers/apache-2.4[${APACHE_MODULES},apache2_modules_cgi]
45                  >=www-servers/apache-2.4[${APACHE_MODULES},apache2_modules_cgid]
46                  >=www-servers/apache-2.4[${APACHE_MODULES},apache2_modules_fcgid] )
47         net-misc/rsync
48         dev-perl/File-RsyncP
49         rss? ( dev-perl/XML-RSS )
50         samba? ( net-fs/samba )"
51
52 need_apache2_4
53
54 SLOT="0"
55
56 S="${WORKDIR}/${MY_P}"
57
58 CGIDIR="/usr/lib/backuppc/htdocs"
59 CONFDIR="/etc/BackupPC"
60 DATADIR="/var/lib/backuppc"
61 DOCDIR="/usr/share/doc/${PF}"
62 LOGDIR="/var/log/BackupPC"
63
64 pkg_setup() {
65         enewgroup backuppc
66         enewuser backuppc -1 /bin/bash /var/lib/backuppc backuppc
67 }
68
69 src_prepare() {
70         epatch "${FILESDIR}/3.3.0/01-fix-configure.pl.patch"
71         epatch "${FILESDIR}/3.3.0/02-fix-config.pl-formatting.patch"
72         epatch "${FILESDIR}/3.3.0/03-reasonable-config.pl-defaults.patch"
73
74         epatch "${FILESDIR}/3.2.0/04-add-docdir-marker.patch"
75         epatch "${FILESDIR}/3.2.0/05-nicelevel.patch"
76
77         # Fix docs location using the marker that we've patched in.
78         sed -i "s+__DOCDIR__+${DOCDIR}+" "lib/BackupPC/CGI/View.pm" \
79                 || die "failed to sed the documentation location"
80 }
81
82 src_install() {
83         local myconf
84         myconf=""
85         if use samba ; then
86                 myconf="--bin-path smbclient=$(type -p smbclient)"
87                 myconf="${myconf} --bin-path nmblookup=$(type -p nmblookup)"
88         fi
89
90         /usr/bin/env perl ./configure.pl \
91                 --batch \
92                 --bin-path perl=$(type -p perl) \
93                 --bin-path tar=$(type -p tar) \
94                 --bin-path rsync=$(type -p rsync) \
95                 --bin-path ping=$(type -p ping) \
96                 --bin-path df=$(type -p df) \
97                 --bin-path ssh=$(type -p ssh) \
98                 --bin-path sendmail=$(type -p sendmail) \
99                 --bin-path hostname=$(type -p hostname) \
100                 --bin-path gzip=$(type -p gzip) \
101                 --bin-path bzip2=$(type -p bzip2) \
102                 --config-dir "${CONFDIR}" \
103                 --install-dir /usr \
104                 --data-dir "${DATADIR}" \
105                 --hostname 127.0.0.1 \
106                 --uid-ignore \
107                 --dest-dir "${D%/}" \
108                 --html-dir "${CGIDIR}"/image \
109                 --html-dir-url /image \
110                 --cgi-dir "${CGIDIR}" \
111                 --fhs \
112                 ${myconf} || die "failed the configure.pl script"
113
114         ebegin "Installing documentation"
115
116         pod2man \
117                 -errors=none \
118                 --section=8 \
119                 --center="BackupPC manual" \
120                 "${S}"/doc/BackupPC.pod backuppc.8 \
121                 || die "failed to generate man page"
122
123         doman backuppc.8
124
125         # Place the documentation in the correct location
126         dodoc "${D}/usr/doc/BackupPC.html"
127         dodoc "${D}/usr/doc/BackupPC.pod"
128         rm -rf "${D}/usr/doc" || die
129
130         eend 0
131
132         # Setup directories
133         dodir "${CONFDIR}/pc"
134
135         keepdir "${CONFDIR}"
136         keepdir "${CONFDIR}/pc"
137         keepdir "${DATADIR}"/{trash,pool,pc,cpool}
138         keepdir "${LOGDIR}"
139
140         ebegin "Setting up init.d/conf.d/systemd scripts"
141         newinitd "${S}"/init.d/gentoo-backuppc backuppc
142         newconfd "${S}"/init.d/gentoo-backuppc.conf backuppc
143         systemd_dounit "${FILESDIR}/${PN}.service"
144
145         insinto "${APACHE_MODULES_CONFDIR}"
146         doins "${FILESDIR}"/99_backuppc.conf
147
148         # Make sure that the ownership is correct
149         chown -R backuppc:backuppc "${D}${CONFDIR}" || die
150         chown -R backuppc:backuppc "${D}${DATADIR}" || die
151         chown -R backuppc:backuppc "${D}${LOGDIR}"  || die
152 }
153
154 pkg_postinst() {
155         elog "Installation finished, you may now start using BackupPC."
156         elog
157         elog "- Read the documentation in /usr/share/doc/${PF}/BackupPC.html"
158         elog "  Please pay special attention to the security section."
159         elog
160         elog "- You can launch backuppc by running:"
161         elog
162         elog "    # /etc/init.d/backuppc start"
163         elog
164         elog "- To enable the GUI, first edit ${ROOT}etc/conf.d/apache2 and add,"
165         elog
166         elog "    \"-D BACKUPPC -D PERL -D MPM_ITK\""
167         elog
168         elog "  to the APACHE2_OPTS line."
169         elog
170         elog "  Then you must edit ${ROOT}etc/apache2/modules.d/00_mpm_itk.conf"
171         elog "  and adjust the values of LimitUIDRange/LimitGIDRange to include"
172         elog "  the UID and GID of the backuppc user."
173         elog
174         elog "  Finally, start apache:"
175         elog
176         elog "    # /etc/init.d/apache2 start"
177         elog
178         elog "  The web interface should now be running on,"
179         elog
180         elog "    http://127.0.0.1:8080/"
181         elog
182
183         # Generate a new password if there's no auth file
184         if [[ ! -f "${CONFDIR}/users.htpasswd" ]]; then
185                 adminuser="backuppc"
186                 adminpass=$( makepasswd --chars=12 )
187                 htpasswd -bc "${CONFDIR}/users.htpasswd" $adminuser $adminpass
188
189                 elog ""
190                 elog "- Created admin user $adminuser with password $adminpass"
191                 elog "  To add new users, run: "
192                 elog ""
193                 elog "  # htpasswd ${CONFDIR}/users.htpasswd newUser"
194         fi
195 }