add media-tv/plex-media-server-1.21.0-r1
[portage-squeep] / media-tv / plex-media-server / plex-media-server-1.21.0-r1.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 PYTHON_COMPAT=( python2_7 )
7 inherit eutils systemd unpacker pax-utils
8
9 MINOR_VERSION="3608-f7262c352"
10 _APPNAME="plexmediaserver"
11 _USERNAME="plex"
12 _SHORTNAME="${_USERNAME}"
13 _FULL_VERSION="${PV}.${MINOR_VERSION}"
14
15 URI="https://downloads.plex.tv/plex-media-server-new"
16
17 DESCRIPTION="A free media library that is intended for use with a plex client"
18 HOMEPAGE="https://www.plex.tv/"
19 SRC_URI="
20 amd64? ( ${URI}/${_FULL_VERSION}/debian/plexmediaserver_${_FULL_VERSION}_amd64.deb )
21 x86? ( ${URI}/${_FULL_VERSION}/debian/plexmediaserver_${_FULL_VERSION}_i386.deb )
22 "
23 SLOT="0"
24 LICENSE="Plex"
25 RESTRICT="bindist strip mirror"
26 KEYWORDS="-* ~amd64 ~x86"
27
28 BDEPEND="dev-util/patchelf"
29
30 RDEPEND="
31 acct-group/plex
32 acct-user/plex
33 net-dns/avahi"
34
35 QA_DESKTOP_FILE="usr/share/applications/plexmediamanager.desktop"
36 QA_PREBUILT="*"
37 QA_MULTILIB_PATHS=(
38 "usr/lib/${_APPNAME}/.*"
39 "usr/lib/${_APPNAME}/Resources/Python/lib/python2.7/.*"
40 )
41
42 BINS_TO_PAX_MARK=(
43 "${ED}/usr/lib/plexmediaserver/Plex Script Host"
44 "${ED}/usr/lib/plexmediaserver/Plex Media Scanner"
45 )
46
47 S="${WORKDIR}"
48 PATCHES=(
49 "${FILESDIR}/plexmediamanager.desktop.new.patch"
50 "${FILESDIR}/plexmediaserver.service.patch"
51 )
52
53 src_unpack() {
54 unpack_deb ${A}
55 }
56
57 src_install() {
58 # Remove Debian apt repo files
59 rm -r "etc/apt" || die
60
61 # Remove Debian specific files
62 rm -r "usr/share/doc" || die
63
64 # Copy main files over to image and preserve permissions so it is portable
65 cp -rp usr/ "${ED}"/ || die
66
67 # Make sure the logging directory is created
68 local logging_dir="/var/log/pms"
69 dodir "${logging_dir}"
70 fowners "${_USERNAME}":"${_USERNAME}" "${logging_dir}"
71 keepdir "${logging_dir}"
72
73 # Create default library folder with correct permissions
74 local default_library_dir="/var/lib/${_APPNAME}"
75 dodir "${default_library_dir}"
76 fowners "${_USERNAME}":"${_USERNAME}" "${default_library_dir}"
77 keepdir "${default_library_dir}"
78
79 # Install the OpenRC init/conf files
80 doinitd "${FILESDIR}/init.d/${PN}"
81 doconfd "${FILESDIR}/conf.d/${PN}"
82
83 # Mask Plex libraries so that revdep-rebuild doesn't try to rebuild them.
84 # Plex has its own precompiled libraries.
85 _mask_plex_libraries_revdep
86
87 # Fix RPATH
88 patchelf --force-rpath --set-rpath '$ORIGIN:$ORIGIN/../../../../../../lib' "${ED}"/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/lib-dynload/_codecs_kr.so || die
89
90 # Install systemd service file
91 systemd_newunit "${ED}"/usr/lib/plexmediaserver/lib/plexmediaserver.service "${PN}.service"
92
93 # Add pax markings to some binaries so that they work on hardened setup
94 for f in "${BINS_TO_PAX_MARK[@]}"; do
95 pax-mark m "${f}"
96 done
97 }
98
99 pkg_postinst() {
100 elog "Plex Media Server is now installed. Please check the configuration"
101 elog "file in /etc/${_SHORTNAME}/${_APPNAME}"
102 elog "to verify the default settings."
103 elog "To start the Plex Server, run 'rc-config start plex-media-server',"
104 elog "you will then be able to access your library at"
105 elog "http://<ip>:32400/web/"
106 }
107
108 # Adds the precompiled plex libraries to the revdep-rebuild's mask list
109 # so it doesn't try to rebuild libraries that can't be rebuilt.
110 _mask_plex_libraries_revdep() {
111 dodir /etc/revdep-rebuild/
112
113 # Bug: 659702. The upstream plex binary installs its precompiled package to /usr/lib.
114 # Due to profile 17.1 splitting /usr/lib and /usr/lib64, we can no longer rely
115 # on the implicit symlink automatically satisfying our revdep requirement when we use $(get_libdir).
116 # Thus we will match upstream's directory automatically. If upstream switches their location,
117 # then so should we.
118 echo "SEARCH_DIRS_MASK=\"${EPREFIX}/usr/lib/plexmediaserver\"" > "${ED}"/etc/revdep-rebuild/80plexmediaserver
119 }