add media-tv/plex-media-server
[portage-squeep] / media-tv / plex-media-server / plex-media-server-1.18.6.2348.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit eutils systemd unpacker pax-utils
7
8 COMMIT="fd90a1389"
9
10 _APPNAME="plexmediaserver"
11 _USERNAME="plex"
12 _SHORTNAME="${_USERNAME}"
13 _FULL_VERSION="${PV}-${COMMIT}"
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="http://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
24 SLOT="0"
25 LICENSE="Plex"
26 RESTRICT="mirror bindist strip"
27 KEYWORDS="-* amd64 x86"
28
29 IUSE="pax_kernel avahi"
30
31 DEPEND="
32 pax_kernel? ( sys-apps/fix-gnustack )
33 dev-util/patchelf"
34
35 RDEPEND="
36 acct-user/plex
37 acct-group/plex
38 avahi? ( net-dns/avahi )"
39
40 QA_DESKTOP_FILE="usr/share/applications/plexmediamanager.desktop"
41 QA_PREBUILT="*"
42 QA_MULTILIB_PATHS=(
43 "usr/lib/${_APPNAME}/.*"
44 "usr/lib/${_APPNAME}/Resources/Python/lib/python2.7/.*"
45 )
46
47 EXECSTACKED_BINS=( )
48
49 BINS_TO_PAX_MARK=(
50 "${ED%/}/usr/lib/plexmediaserver/Plex Script Host"
51 "${ED%/}/usr/lib/plexmediaserver/Plex Media Scanner"
52 )
53 BINS_TO_PAX_CREATE_FLAGS=( "${ED%/}/usr/lib/plexmediaserver/Resources/Python/bin/python" )
54
55 S="${WORKDIR}"
56 PATCHES=(
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"
60 )
61
62 src_unpack() {
63 unpack_deb ${A}
64 }
65
66 src_install() {
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#/}"
74 fi
75 sed -e "s#${CONFIG_VANILLA}#${CONFIG_PATH}/${_APPNAME}#g" -i "${S}"/usr/sbin/start_pms || die
76
77 # Remove Debian specific files
78 rm -rf "usr/share/doc" || die
79
80 # Copy main files over to image and preserve permissions so it is portable
81 cp -rp usr/ "${ED%/}/" || die
82
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}"
88
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}"
94
95 # Install the OpenRC init/conf files depending on avahi.
96 if use avahi; then
97 doinitd "${FILESDIR}/init.d/${PN}"
98 else
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}"
103 doinitd "${S}/${PN}"
104 fi
105
106 doconfd "${FILESDIR}/conf.d/${PN}"
107
108 # Disabling due to Bug 644694
109 #_handle_multilib
110
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
114
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}"
119
120 # Fix RPATH
121 patchelf --force-rpath --set-rpath '$ORIGIN:$ORIGIN/../../../../../../lib' "${ED%/}"/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/lib-dynload/_codecs_kr.so || die
122
123 # Add PaX marking for hardened systems
124 if use pax_kernel; then
125 _remove_execstack_markings
126 _add_pax_markings
127 _add_pax_flags
128 fi
129 }
130
131 pkg_postinst() {
132 einfo ""
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/"
135 einfo ""
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."
138
139 }
140
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.
145
146 # Finds out where the library directory is for this system
147 # and handles ldflags as to not break library dependencies
148 # during rebuilds.
149 _handle_multilib() {
150 # Prevent revdep-rebuild, @preserved-rebuild breakage
151 cat > "${T}"/66plex <<-EOF || die
152 LDPATH="${EPREFIX}/usr/$(get_libdir)/plexmediaserver"
153 EOF
154
155 doenvd "${T}"/66plex
156 }
157
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
163 }
164
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
171 done
172 }
173
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
177 pax-mark m "${f}"
178 done
179 }
180
181 # Create default PaX markings on virtualenvironment's pythin
182 _add_pax_flags() {
183 for f in "${BINS_TO_PAX_CREATE_FLAGS[@]}"; do
184 pax-mark c "${F}"
185 done
186 }