1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils systemd unpacker pax-utils
10 _APPNAME="plexmediaserver"
12 _SHORTNAME="${_USERNAME}"
13 _FULL_VERSION="${PV}-${COMMIT}"
15 URI="https://downloads.plex.tv/plex-media-server-new"
17 DESCRIPTION="A free media library that is intended for use with a plex client."
18 HOMEPAGE="http://www.plex.tv/"
20 amd64? ( ${URI}/${_FULL_VERSION}/debian/plexmediaserver_${_FULL_VERSION}_amd64.deb )
21 x86? ( ${URI}/${_FULL_VERSION}/debian/plexmediaserver_${_FULL_VERSION}_i386.deb )
26 RESTRICT="mirror bindist strip"
27 KEYWORDS="-* amd64 x86"
29 IUSE="pax_kernel avahi"
32 pax_kernel? ( sys-apps/fix-gnustack )
38 avahi? ( net-dns/avahi )"
40 QA_DESKTOP_FILE="usr/share/applications/plexmediamanager.desktop"
43 "usr/lib/${_APPNAME}/.*"
44 "usr/lib/${_APPNAME}/Resources/Python/lib/python2.7/.*"
50 "${ED%/}/usr/lib/plexmediaserver/Plex Script Host"
51 "${ED%/}/usr/lib/plexmediaserver/Plex Media Scanner"
53 BINS_TO_PAX_CREATE_FLAGS=( "${ED%/}/usr/lib/plexmediaserver/Resources/Python/bin/python" )
57 "${FILESDIR}/plexmediamanager.desktop.new.patch"
58 "${FILESDIR}/add_gentoo_profile_as_platform_version.patch"
59 "${FILESDIR}/20200129_add_gentoo_profile_as_platform_version.patch"
67 # Move the config to the correct place
68 local CONFIG_VANILLA="/etc/default/plexmediaserver"
69 local CONFIG_PATH="/etc/${_SHORTNAME}"
70 dodir "${CONFIG_PATH}"
71 insinto "${CONFIG_PATH}"
72 if [[ -d "${S}/${CONFIG_VANILLA#/}" ]]; then
73 doins "${CONFIG_VANILLA#/}"
75 sed -e "s#${CONFIG_VANILLA}#${CONFIG_PATH}/${_APPNAME}#g" -i "${S}"/usr/sbin/start_pms || die
77 # Remove Debian specific files
78 rm -rf "usr/share/doc" || die
80 # Copy main files over to image and preserve permissions so it is portable
81 cp -rp usr/ "${ED%/}/" || die
83 # Make sure the logging directory is created
84 local LOGGING_DIR="/var/log/pms"
85 dodir "${LOGGING_DIR}"
86 chown "${_USERNAME}":"${_USERNAME}" "${ED%/}/${LOGGING_DIR}" || die
87 keepdir "${LOGGING_DIR}"
89 # Create default library folder with correct permissions
90 local DEFAULT_LIBRARY_DIR="/var/lib/${_APPNAME}"
91 dodir "${DEFAULT_LIBRARY_DIR}"
92 chown "${_USERNAME}":"${_USERNAME}" "${ED%/}/${DEFAULT_LIBRARY_DIR}" || die
93 keepdir "${DEFAULT_LIBRARY_DIR}"
95 # Install the OpenRC init/conf files depending on avahi.
97 doinitd "${FILESDIR}/init.d/${PN}"
99 cp "${FILESDIR}/init.d/${PN}" "${S}/${PN}";
100 sed -e '/depend/ s/^#*/#/' -i "${S}/${PN}"
101 sed -e '/need/ s/^#*/#/' -i "${S}/${PN}"
102 sed -e '1,/^}/s/^}/#}/' -i "${S}/${PN}"
106 doconfd "${FILESDIR}/conf.d/${PN}"
108 # Disabling due to Bug 644694
111 # Mask Plex libraries so that revdep-rebuild doesn't try to rebuild them.
112 # Plex has its own precompiled libraries.
113 _mask_plex_libraries_revdep
115 # Install systemd service file
116 local UNIT_NAME="${PN}.service"
117 local UNIT="${S}/usr/lib/plexmediaserver/lib/plexmediaserver.service"
118 systemd_newunit "${UNIT}" "${UNIT_NAME}"
121 patchelf --force-rpath --set-rpath '$ORIGIN:$ORIGIN/../../../../../../lib' "${ED%/}"/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/lib-dynload/_codecs_kr.so || die
123 # Add PaX marking for hardened systems
124 if use pax_kernel; then
125 _remove_execstack_markings
133 elog "Plex Media Server is now installed. Please check the configuration file in /etc/${_SHORTNAME}/${_APPNAME} to verify the default settings."
134 elog "To start the Plex Server, run 'rc-config start plex-media-server', you will then be able to access your library at http://<ip>:32400/web/"
136 einfo "The fkmclane/overlay/${CATEGORY}-${PN} will not be supported and updated in the next future. Please migrate to comio/plex-overlay or"
137 einfo "another overlay if you prefer in order to have future updates."
141 # Disabling the follow function due to Bug 644694.
142 # We shouldn't register plex libraries in global
143 # library path since this will cause other packages
144 # on the system to break.
146 # Finds out where the library directory is for this system
147 # and handles ldflags as to not break library dependencies
150 # Prevent revdep-rebuild, @preserved-rebuild breakage
151 cat > "${T}"/66plex <<-EOF || die
152 LDPATH="${EPREFIX}/usr/$(get_libdir)/plexmediaserver"
158 # Adds the precompiled plex libraries to the revdep-rebuild's mask list
159 # so it doesn't try to rebuild libraries that can't be rebuilt.
160 _mask_plex_libraries_revdep() {
161 dodir /etc/revdep-rebuild/
162 echo "SEARCH_DIRS_MASK=\"${EPREFIX}/usr/$(get_libdir)/plexmediaserver\"" > "${ED%/}"/etc/revdep-rebuild/80plexmediaserver
165 # Remove execstack flags from some libraries/executables
166 # so that it works in hardened setups.
167 _remove_execstack_markings() {
168 for f in "${EXECSTACKED_BINS[@]}"; do
169 # Unquoting 'f' so that expansion works.
170 fix-gnustack -f ${f} > /dev/null
174 # Add pax markings to some binaries so that they work on hardened setup.
175 _add_pax_markings() {
176 for f in "${BINS_TO_PAX_MARK[@]}"; do
181 # Create default PaX markings on virtualenvironment's pythin
183 for f in "${BINS_TO_PAX_CREATE_FLAGS[@]}"; do