# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI="8"

inherit git-r3

DESCRIPTION="ShairTunes2 shairport Squeezebox Server Plugin - airplay to Squeezebox clients"
HOMEPAGE="https://github.com/disaster123/shairport2_plugin"
EGIT_REPO_URI="https://github.com/disaster123/shairport2_plugin.git"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

# require dbus use flag on avahi to have the avahi-browse binary built
DEPEND="
	dev-perl/Crypt-OpenSSL-RSA
	dev-perl/IO-Socket-INET6
	dev-perl/Net-SDP
	media-sound/logitechmediaserver-bin
	media-sound/shairport2_helper
	net-dns/avahi[dbus]
	virtual/perl-Digest-MD5
	virtual/perl-MIME-Base64
"

RDEPEND="${DEPEND}"

INSTALL_DIR="/var/lib/logitechmediaserver/Plugins/ShairTunes2"

src_prepare() {
	sed -i -e 's;return \$shairtunes_helper;return "/usr/bin/shairport2_helper";' "Utils.pm"
	eapply_user
}

src_install() {
	insinto ${INSTALL_DIR}
	doins AIRPLAY.pm Plugin.pm Utils.pm install.xml public.xml strings.txt
	fowners logitechmediaserver:logitechmediaserver ${INSTALL_DIR} -R
	dodoc README.md ${FILESDIR}/avahi-daemon.conf.patch
	newbin ${FILESDIR}/airplayservers showairplayservers
}

pkg_postinst() {
	elog "ShairTunes2 has been installed to ${INSTALL_DIR} - now:"
	elog " 1. if it is not already there, add avahi-daemon to the default run level"
	elog " 2. configure and then restart avahi-daemon as described in /usr/share/doc/${P}/"
	elog " 2. restart logitechmediaserver, check /var/log/logitechmediaserver/server.log"
	elog " 3. confirm services are being advertised using avahi-browse (dbus daemon must be running):"
	elog "       avahi-browse -tv _raop._tcp"
	elog " 4. LMS will log connections and launching decoders to /var/log/logitechmediaserver/server.log"
	elog ""
	elog "For verbose debug set: Debug logging via the Web-Interface->Settings>Advanced->Logging->plugin.shairtunes"
	elog "    (or just change defaultLevel to DEBUG in /var/lib/logitechmediaserver/Plugins/ShairTunes2/Plugin.pm)"
	elog ""
	elog "Support thread at: http://forums.slimdevices.com/showthread.php?103783-Announce-ShairTunes2-plugin-Airtunes-on-your-LMS"
}