Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lms: new port in audio #25755

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions audio/lms/Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup boost 1.0
PortGroup cmake 1.1
PortGroup github 1.0
PortGroup legacysupport 1.1

# O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10
legacysupport.redirect_bins lms lms-metadata lms-recommendation

boost.version 1.81

github.setup epoupon lms 3.56.0 v
revision 0

categories audio multimedia www
license GPL-3
maintainers {@barracuda156 gmail.com:vital.had} openmaintainer

description Lightweight Music Server
long_description LMS is a self-hosted music streaming software: \
access your music collection from anywhere using a web interface.
homepage https://lms-demo.poupon.dev
checksums rmd160 b34a7a3178852785bfa62205882fb29624906371 \
sha256 0270838187528de88e61d0da5d4a68614a6b66140752090f930071f01935557f \
size 440559
github.tarball_from archive

depends_build-append \
path:bin/pkg-config:pkgconfig

depends_lib-append port:ffmpeg \
port:libarchive \
port:libconfig-hr \
port:stb \
port:taglib \
port:wt

# https://github.com/epoupon/lms/issues/514
patchfiles-append 777c36005bdcdc09e1813a84f3f2c0acc0b47fac.patch

# https://github.com/epoupon/lms/pull/524
patchfiles-append 0001-CMakeLists-do-not-use-Linux-ldflag-on-macOS.patch

# https://github.com/epoupon/lms/issues/525
patchfiles-append 0002-Fix-lms.conf-path.patch

post-patch {
reinplace "s|@PREFIX@|${prefix}|g" \
${worksrcpath}/src/lms/main.cpp \
${worksrcpath}/src/tools/cover/LmsCover.cpp \
${worksrcpath}/src/tools/db-generator/LmsDbGenerator.cpp \
${worksrcpath}/src/tools/recommendation/LmsRecommendation.cpp
}

configure.args-append \
-DBUILD_BENCHMARKS=OFF \
-DENABLE_TESTS=OFF

# https://github.com/epoupon/lms/issues/526
compiler.blacklist-append \
macports-clang-18

compiler.cxx_standard 2020

post-destroot {
xinstall -d ${destroot}${prefix}/etc/${name}
xinstall -d ${destroot}${prefix}/var/${name}
reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${prefix}/share/lms/lms.conf
}

post-activate {
if {![file exists ${prefix}/etc/lms.conf]} {
copy ${prefix}/share/lms/lms.conf ${prefix}/etc/lms.conf
}
}

notes "
You may want to edit config settings in ${prefix}/etc/lms.conf
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From c4653f6237a87c22ff04b8e45d9568ebc6125ad3 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Sat, 14 Sep 2024 11:30:24 +0800
Subject: [PATCH] CMakeLists: do not use Linux ldflag on macOS

---
CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git CMakeLists.txt CMakeLists.txt
index 0d0b311f..6cb75ea9 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -6,7 +6,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules/)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
-if (UNIX)
+if (UNIX AND NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
endif ()

113 changes: 113 additions & 0 deletions audio/lms/files/0002-Fix-lms.conf-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
From ecf3b2ac7ff058d5a33a498b194fa65af427f2bf Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Sat, 14 Sep 2024 14:02:57 +0800
Subject: [PATCH] Fix lms.conf path

---
src/lms/main.cpp | 2 +-
src/tools/cover/LmsCover.cpp | 2 +-
src/tools/db-generator/LmsDbGenerator.cpp | 2 +-
src/tools/recommendation/LmsRecommendation.cpp | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)

diff --git src/lms/main.cpp src/lms/main.cpp
index 63cb1309..7e231261 100644
--- src/lms/main.cpp
+++ src/lms/main.cpp
@@ -211,7 +211,7 @@ namespace lms

int main(int argc, char* argv[])
{
- std::filesystem::path configFilePath{ "/etc/lms.conf" };
+ std::filesystem::path configFilePath{ "/opt/local/etc/lms.conf" };
int res{ EXIT_FAILURE };

assert(argc > 0);
diff --git src/tools/cover/LmsCover.cpp src/tools/cover/LmsCover.cpp
index ce5f5320..fb44d219 100644
--- src/tools/cover/LmsCover.cpp
+++ src/tools/cover/LmsCover.cpp
@@ -66,7 +66,7 @@ int main(int argc, char* argv[])
core::Service<core::logging::ILogger> logger{ std::make_unique<core::logging::StreamLogger>(std::cout) };

po::options_description desc{ "Allowed options" };
- desc.add_options()("help,h", "print usage message")("conf,c", po::value<std::string>()->default_value("/etc/lms.conf"), "LMS config file")("default-cover,d", po::value<std::string>(), "Default cover path")("tracks,t", "dump covers for tracks")("size,s", po::value<unsigned>()->default_value(512), "Requested cover size")("quality,q", po::value<unsigned>()->default_value(75), "JPEG quality (1-100)");
+ desc.add_options()("help,h", "print usage message")("conf,c", po::value<std::string>()->default_value("/opt/local/etc/lms.conf"), "LMS config file")("default-cover,d", po::value<std::string>(), "Default cover path")("tracks,t", "dump covers for tracks")("size,s", po::value<unsigned>()->default_value(512), "Requested cover size")("quality,q", po::value<unsigned>()->default_value(75), "JPEG quality (1-100)");

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
diff --git src/tools/db-generator/LmsDbGenerator.cpp src/tools/db-generator/LmsDbGenerator.cpp
index e41882ed..fe1a06a9 100644
--- src/tools/db-generator/LmsDbGenerator.cpp
+++ src/tools/db-generator/LmsDbGenerator.cpp
@@ -177,7 +177,7 @@ int main(int argc, char* argv[])
const GeneratorParameters defaultParams;

program_options::options_description options{ "Options" };
- options.add_options()("conf,c", program_options::value<std::string>()->default_value("/etc/lms.conf"), "lms config file")("media-library-count", program_options::value<unsigned>()->default_value(defaultParams.mediaLibraryCount), "Number of media libraries to use")("release-count-per-batch", program_options::value<unsigned>()->default_value(defaultParams.releaseCountPerBatch), "Number of releases to generate before committing transaction")("release-count", program_options::value<unsigned>()->default_value(defaultParams.releaseCount), "Number of releases to generate")("track-count-per-release", program_options::value<unsigned>()->default_value(defaultParams.trackCountPerRelease), "Number of tracks per release")("compilation-ratio", program_options::value<float>()->default_value(defaultParams.compilationRatio), "Compilation ratio (compilation means all tracks have a different artist)")("track-path", program_options::value<std::string>()->required(), "Path of a valid track file, that will be used for all generated tracks")("genre-count", program_options::value<unsigned>()->default_value(defaultParams.genreCount), "Number of genres to generate")("genre-count-per-track", program_options::value<unsigned>()->default_value(defaultParams.genreCountPerTrack), "Number of genres to assign to each track")("mood-count", program_options::value<unsigned>()->default_value(defaultParams.moodCount), "Number of moods to generate")("mood-count-per-track", program_options::value<unsigned>()->default_value(defaultParams.moodCountPerTrack), "Number of moods to assign to each track")("help,h", "produce help message");
+ options.add_options()("conf,c", program_options::value<std::string>()->default_value("/opt/local/etc/lms.conf"), "lms config file")("media-library-count", program_options::value<unsigned>()->default_value(defaultParams.mediaLibraryCount), "Number of media libraries to use")("release-count-per-batch", program_options::value<unsigned>()->default_value(defaultParams.releaseCountPerBatch), "Number of releases to generate before committing transaction")("release-count", program_options::value<unsigned>()->default_value(defaultParams.releaseCount), "Number of releases to generate")("track-count-per-release", program_options::value<unsigned>()->default_value(defaultParams.trackCountPerRelease), "Number of tracks per release")("compilation-ratio", program_options::value<float>()->default_value(defaultParams.compilationRatio), "Compilation ratio (compilation means all tracks have a different artist)")("track-path", program_options::value<std::string>()->required(), "Path of a valid track file, that will be used for all generated tracks")("genre-count", program_options::value<unsigned>()->default_value(defaultParams.genreCount), "Number of genres to generate")("genre-count-per-track", program_options::value<unsigned>()->default_value(defaultParams.genreCountPerTrack), "Number of genres to assign to each track")("mood-count", program_options::value<unsigned>()->default_value(defaultParams.moodCount), "Number of moods to generate")("mood-count-per-track", program_options::value<unsigned>()->default_value(defaultParams.moodCountPerTrack), "Number of moods to assign to each track")("help,h", "produce help message");

program_options::variables_map vm;
program_options::store(program_options::parse_command_line(argc, argv, options), vm);
diff --git src/tools/recommendation/LmsRecommendation.cpp src/tools/recommendation/LmsRecommendation.cpp
index 578de0ba..4a1a4a73 100644
--- src/tools/recommendation/LmsRecommendation.cpp
+++ src/tools/recommendation/LmsRecommendation.cpp
@@ -132,7 +132,7 @@ int main(int argc, char* argv[])
core::Service<core::logging::ILogger> logger{ std::make_unique<core::logging::StreamLogger>(std::cout) };

po::options_description desc{ "Allowed options" };
- desc.add_options()("help,h", "print usage message")("conf,c", po::value<std::string>()->default_value("/etc/lms.conf"), "LMS config file")("artists,a", "Display recommendation for artists")("releases,r", "Display recommendation for releases")("tracks,t", "Display recommendation for tracks")("max,m", po::value<unsigned>()->default_value(3), "Max similarity result count");
+ desc.add_options()("help,h", "print usage message")("conf,c", po::value<std::string>()->default_value("/opt/local/etc/lms.conf"), "LMS config file")("artists,a", "Display recommendation for artists")("releases,r", "Display recommendation for releases")("tracks,t", "Display recommendation for tracks")("max,m", po::value<unsigned>()->default_value(3), "Max similarity result count");

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);


From 4de02058a1a6db8600c476c2759925b76a52434d Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Sat, 14 Sep 2024 15:24:22 +0800
Subject: [PATCH] Fix lms.conf

---
conf/lms.conf | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git conf/lms.conf conf/lms.conf
index 4fcca840..14aa01ce 100644
--- conf/lms.conf
+++ conf/lms.conf
@@ -2,10 +2,10 @@

# Path to the working directory
# Must have write privileges in order to create and modify this directory
-working-dir = "/var/lms/";
+working-dir = "/opt/local/var/lms/";

# ffmpeg location
-ffmpeg-file = "/usr/bin/ffmpeg";
+ffmpeg-file = "/opt/local/bin/ffmpeg";

# Log files, empty means stdout
log-file = "";
@@ -22,14 +22,14 @@ behind-reverse-proxy = false;

# If enabled, these files have to exist and have correct permissions
tls-enable = false;
-tls-cert = "/var/lms/cert.pem";
-tls-key = "/var/lms/privkey.pem";
-tls-dh = "/var/lms/dh2048.pem";
+tls-cert = "/opt/local/var/lms/cert.pem";
+tls-key = "/opt/local/var/lms/privkey.pem";
+tls-dh = "/opt/local/var/lms/dh2048.pem";

# Path to the resources used by the web interface.
-wt-resources = "/usr/share/Wt/resources";
-docroot = "/usr/share/lms/docroot/;/resources,/css,/images,/js,/favicon.ico";
-approot = "/usr/share/lms/approot";
+wt-resources = "/opt/local/share/Wt/resources";
+docroot = "/opt/local/share/lms/docroot/;/resources,/css,/images,/js,/favicon.ico";
+approot = "/opt/local/share/lms/approot";
# Location for deployment (See README if you want to deploy on a non root path)
deploy-path = "/";

87 changes: 87 additions & 0 deletions audio/lms/files/777c36005bdcdc09e1813a84f3f2c0acc0b47fac.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
From 777c36005bdcdc09e1813a84f3f2c0acc0b47fac Mon Sep 17 00:00:00 2001
From: emeric <[email protected]>
Date: Fri, 13 Sep 2024 23:27:53 +0200
Subject: [PATCH] Do not use pipe2 to make code more portable, ref #514

---
src/libs/core/impl/ChildProcess.cpp | 39 +++++++++++++++++++----------
1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/libs/core/impl/ChildProcess.cpp b/src/libs/core/impl/ChildProcess.cpp
index d2956a3d..599bd16b 100644
--- src/libs/core/impl/ChildProcess.cpp
+++ src/libs/core/impl/ChildProcess.cpp
@@ -66,36 +66,49 @@ namespace lms::core
static std::mutex mutex;
std::unique_lock<std::mutex> lock{ mutex };

- int pipe[2];
+ int pipefd[2];

- int res{ pipe2(pipe, O_NONBLOCK | O_CLOEXEC) };
- if (res < 0)
- throw SystemException{ errno, "pipe2 failed!" };
+ // Use 'pipe' instead of 'pipe2', more portable
+ if (pipe(pipefd) < 0)
+ throw SystemException{ errno, "pipe failed!" };
+
+ // Manually set the O_NONBLOCK and O_CLOEXEC flags for both ends of the pipe
+ if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) == -1)
+ throw SystemException{ errno, "fcntl failed to set O_NONBLOCK!" };
+
+ if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) == -1)
+ throw SystemException{ errno, "fcntl failed to set O_NONBLOCK!" };
+
+ if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1)
+ throw SystemException{ errno, "fcntl failed to set FD_CLOEXEC!" };
+
+ if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1)
+ throw SystemException{ errno, "fcntl failed to set FD_CLOEXEC!" };

- {
#if defined(__linux__) && defined(F_SETPIPE_SZ)
+ {
// Just a hint here to prevent the writer from writing too many bytes ahead of the reader
constexpr std::size_t pipeSize{ 65536 * 4 };

- if (fcntl(pipe[0], F_SETPIPE_SZ, pipeSize) == -1)
+ if (fcntl(pipefd[0], F_SETPIPE_SZ, pipeSize) == -1)
throw SystemException{ errno, "fcntl failed!" };
- if (fcntl(pipe[1], F_SETPIPE_SZ, pipeSize) == -1)
+ if (fcntl(pipefd[1], F_SETPIPE_SZ, pipeSize) == -1)
throw SystemException{ errno, "fcntl failed!" };
-#endif
}
+#endif

- res = fork();
+ int res{ fork() };
if (res == -1)
throw SystemException{ errno, "fork failed!" };

if (res == 0) // CHILD
{
- close(pipe[0]);
+ close(pipefd[0]);
close(STDIN_FILENO);
close(STDERR_FILENO);

// Replace stdout with pipe write
- if (dup2(pipe[1], STDOUT_FILENO) == -1)
+ if (dup2(pipefd[1], STDOUT_FILENO) == -1)
exit(-1);

std::vector<const char*> execArgs;
@@ -108,10 +121,10 @@ namespace lms::core
}
else // PARENT
{
- close(pipe[1]);
+ close(pipefd[1]);
{
boost::system::error_code assignError;
- _childStdout.assign(pipe[0], assignError);
+ _childStdout.assign(pipefd[0], assignError);
if (assignError)
throw SystemException{ assignError, "fork failed!" };
}