From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id gGjnAga4EWcKYAEAe85BDQ:P1 (envelope-from ) for ; Fri, 18 Oct 2024 01:21:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id gGjnAga4EWcKYAEAe85BDQ (envelope-from ) for ; Fri, 18 Oct 2024 03:21:10 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XTlMJJba; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b=HHzZYjRJ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=systemreboot.net (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1729214469; a=rsa-sha256; cv=none; b=SmnOJmft/qoJVEvFgjKLnnyTf712Pel11CNYlzO/eAIfsKqWZWIWjkkG09GDZBpZ3TUKcN BkjnoOh3LaRkXCTlDou5z+3mc8Lkz0MCOnBgxts+72tfnvRPnHHqRTyrV8r7tcqKX6Jw5W 0wCROZowTviL8HmdW9vC+U09WilxWIFGj+dO1BspDfeW3oZZifN2deXUYYKaS2ljXAt0ln Rj9vWeRRvV0zvwwLxR23cvXwP6S9DOD6FcMnuelMOEHUauoaCPUaQRntVkpBRSG6oVAq3c nohJEZaHd6MYxs45KYxHXn6lYDJAD84XWa0qlIQwt+jJHRuLkE6yB6KUEnijrA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XTlMJJba; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b=HHzZYjRJ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=systemreboot.net (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1729214469; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=MqwVWz8M0JDm6AiiKFLyE7Uh2/pkfbo9vVeDpbaTXaE=; b=rASofzLRHS5JXvBRDPXgTGxsjxIQXwyB5CBT0ZiyvGRQkN3z/qOSzhtEb9LMEHn6NPcLnG 1rOWqnkfdlsBXOhja2DyV3HyFTgnGTy/6QO0rkWKJDET3MxOgNUtKTpUHlQEcozkev0pSt Ccst+yvKxXC31gdgcWlQCmee+Ta5ALnsPTjDiEAKH+h26tFX7zz7aXQL06mIoBNZhP08fL 0i/dRkYqHJCM0cTefTOXu0rsHHKxSWv2AwDAzUQLEC/ED3NW1iravqPJjeP8krWYTwLmER 0OlvXMD6EINxhcDRgoLKtYuxMieE9yCuaYNT3rPpCwKuma65PqzVvdX+ADZsJQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B704B8421B for ; Fri, 18 Oct 2024 03:21:08 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1bfi-0008C7-6s; Thu, 17 Oct 2024 21:20:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t1bfh-0008Br-AD for guix-patches@gnu.org; Thu, 17 Oct 2024 21:20:53 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1bfh-0007Y3-1t; Thu, 17 Oct 2024 21:20:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=MqwVWz8M0JDm6AiiKFLyE7Uh2/pkfbo9vVeDpbaTXaE=; b=XTlMJJba9mr8TEJDTAGyHFUcGjQjaagvPLgsvGs2bmBJj3JLqUzSQxQsvS9dJXH0MiYjrOD5XqisBv+OpxX/tHeknazFo3kdOHLq1wNteCFuO3DRbfeWOSHvAGHaEzovy6h8H0GZXlIg/LmqxsbA1OsQdN/LZjSEHtzZh89HXd5/EFQcSIq75uprlRhar2hIhVQkYG/8vSPO99BlOWTH/Rg0eQtqhIwfgwCyWwHHO1Lzmd0h4xuAPm1czfRR42dhymbvJj+2j+uHJ/ucHt8/ImjaRoPV9179B0DJz+mpyw3yj7LYZvvkZq+2XQTcN3JDCj1l55/cQXXynzFY8a/Zdw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t1bfr-0007u2-1V; Thu, 17 Oct 2024 21:21:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72398] [PATCH v8] services: Add readymedia-service-type. References: <4fee1c18adcfd29d40d5b557bf52db0e531c3f16.1722421592.git.me@fabionatali.com> In-Reply-To: <4fee1c18adcfd29d40d5b557bf52db0e531c3f16.1722421592.git.me@fabionatali.com> Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: me@fabionatali.com, arunisaac@systemreboot.net, mirai@makinata.eu, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Fri, 18 Oct 2024 01:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72398@debbugs.gnu.org Cc: Arun Isaac , Fabio Natali , Fabio Natali , Arun Isaac , Bruno Victal , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Fabio Natali , Arun Isaac , Bruno Victal , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 72398-submit@debbugs.gnu.org id=B72398.172921441929941 (code B ref 72398); Fri, 18 Oct 2024 01:21:02 +0000 Received: (at 72398) by debbugs.gnu.org; 18 Oct 2024 01:20:19 +0000 Received: from localhost ([127.0.0.1]:36419 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1bf8-0007mq-6P for submit@debbugs.gnu.org; Thu, 17 Oct 2024 21:20:19 -0400 Received: from mugam.systemreboot.net ([139.59.75.54]:33430) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t1bf5-0007me-5B for 72398@debbugs.gnu.org; Thu, 17 Oct 2024 21:20:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=MqwVWz8M0JDm6AiiKFLyE7Uh2/pkfbo9vVeDpbaTXaE=; b=HHzZYjRJGFhGkIvF2dbDzORCuN WuxS2ubDrxJ6wb/OS47jwpflj9X4t/bxBRQLlZUYgofjTzm4q9JE52ZCgwBjOR0KpbB1OYx+KZgZx PPikheGuJhy7+/zaCcj280l6jBAv6mNIIWQDuuXaIhBkqidzX5DV37NX+Ny2fmHcI+4KtDslQhyfA wNqKVXObo2etCh93SQj6Ox4gGv5YaDDtC/s3qjP3HQnle3++MWtVxoP50yzJSDUA7vC5vHlI+1fCW Jfx03XDP0biLR65ACIS+7d+qyoOKAsAwAI3bmahLRoaH3aqiwYDz+Bx8HyTm6dw2VWSgW0mdm830Y tAXpCLHA==; Received: from [192.168.2.1] (port=37396 helo=localhost.localdomain) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98) (envelope-from ) id 1t1bYo-0000000008K-2DiG; Fri, 18 Oct 2024 02:13:47 +0100 From: Arun Isaac Date: Fri, 18 Oct 2024 02:19:39 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 1.61 X-Spam-Score: 1.61 X-Migadu-Queue-Id: B704B8421B X-Migadu-Scanner: mx10.migadu.com X-TUID: yyKyAaDGm1nY From: Fabio Natali * doc/guix.texi (Miscellaneous Services): New node. * gnu/local.mk: Add mention of new files. * gnu/services/upnp.scm: New file. * gnu/tests/upnp.scm: New file. Change-Id: I6a3c9db9e7504df308038343ed48e4409a323581 Signed-off-by: Arun Isaac --- doc/guix.texi | 101 ++++++++++++++++++++ gnu/local.mk | 2 + gnu/services/upnp.scm | 208 ++++++++++++++++++++++++++++++++++++++++++ gnu/tests/upnp.scm | 155 +++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+) create mode 100644 gnu/services/upnp.scm create mode 100644 gnu/tests/upnp.scm diff --git a/doc/guix.texi b/doc/guix.texi index b91d229d7c..b9f71527a3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41774,6 +41774,107 @@ Miscellaneous Services @end deftp +@c %end of fragment + +@cindex DLNA/UPnP +@subsubheading DLNA/UPnP Services + +The @code{(gnu services upnp)} module offers services related to +@acronym{UPnP, Universal Plug and Play} and @acronym{DLNA, Digital +Living Network Alliance}, networking protocols that can be used for +media streaming and device interoperability within a local network. For +now, this module provides the @code{readymedia-service-type}. + +@uref{https://sourceforge.net/projects/minidlna/, ReadyMedia} (formerly +known as MiniDLNA) is a DLNA/UPnP-AV media server. The project's +daemon, @code{minidlnad}, can serve media files (audio, pictures, and +video) to DLNA/UPnP-AV clients available on the network. +@code{readymedia-service-type} is a Guix service that wraps around +ReadyMedia's @code{minidlnad}. + +Consider the following configuration: +@lisp +(use-service-modules upnp @dots{}) + +(operating-system + @dots{} + (services + (list (service readymedia-service-type + (readymedia-configuration + (media-directoriess + (list (readymedia-media-directory + (path "/media/audio") + (types '(A))) + (readymedia-media-directory + (path "/media/video") + (types '(V))) + (readymedia-media-directory + (path "/media/misc")))) + (extra-config '(("notify_interval" . 60))))) + @dots{}))) +@end lisp + +This sets up the ReadyMedia daemon to serve files from the media folders +specified in @code{media-directories}. The @code{media-directories} +field is mandatory. All other fields (such as network ports and the +server name) come with a predefined default and can be omitted. + +@c %start of fragment + +@deftp {Data Type} readymedia-configuration +Available @code{readymedia-configuration} fields are: + +@table @asis +@item @code{readymedia} (default: @code{readymedia}) (type: package) +The ReadyMedia package to be used for the service. + +@item @code{friendly-name} (default: @code{#f}) (type: maybe-string) +A custom name that will be displayed on connected clients. + +@item @code{media-directories} (type: list) +The list of media folders to serve content from. Each item is a +@code{readymedia-media-directory}. + +@item @code{cache-directory} (default: @code{"/var/cache/readymedia"}) (type: string) +A folder for ReadyMedia's cache files. If not existing already, the +folder will be created as part of the service activation and the +ReadyMedia user will be assigned ownership. + +@item @code{log-directory} (default: @code{"/var/log/readymedia"}) (type: string) +A folder for ReadyMedia's log files. If not existing already, the +folder will be created as part of the service activation and the +ReadyMedia user will be assigned ownership. + +@item @code{port} (default: @code{#f}) (type: maybe-integer) +A custom port that the service will be listening on. + +@item @code{extra-config} (default: @code{'()}) (type: alist) +An association list of further options, as accepted by ReadyMedia. +@end table + +@end deftp + +@c %end of fragment + +@c %start of fragment + +@deftp {Data Type} readymedia-media-directory +A @code{media-directories} entry includes a folder @code{path} and, +optionally, the @code{types} of media files included within the +folder. + +@table @asis +@item @code{path} (type: string) +The media folder location. + +@item @code{types} (default: @code{'()}) (type: list) +A list indicating the types of file included in the media folder. +Valid values are combinations of individual media types, i.e. symbol +@code{A} for audio, @code{P} for pictures, @code{V} for video. An +empty list means that no type is specified. +@end table + +@end deftp @c %end of fragment diff --git a/gnu/local.mk b/gnu/local.mk index 29d76e7bce..81031c9bdd 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -756,6 +756,7 @@ GNU_SYSTEM_MODULES = \ %D%/services/syncthing.scm \ %D%/services/sysctl.scm \ %D%/services/telephony.scm \ + %D%/services/upnp.scm \ %D%/services/version-control.scm \ %D%/services/vnc.scm \ %D%/services/vpn.scm \ @@ -846,6 +847,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/singularity.scm \ %D%/tests/ssh.scm \ %D%/tests/telephony.scm \ + %D%/tests/upnp.scm \ %D%/tests/version-control.scm \ %D%/tests/virtualization.scm \ %D%/tests/vnc.scm \ diff --git a/gnu/services/upnp.scm b/gnu/services/upnp.scm new file mode 100644 index 0000000000..27cbcbaa28 --- /dev/null +++ b/gnu/services/upnp.scm @@ -0,0 +1,208 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Fabio Natali +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services upnp) + #:use-module (gnu build linux-container) + #:use-module (gnu packages admin) + #:use-module (gnu packages upnp) + #:use-module (gnu services admin) + #:use-module (gnu services base) + #:use-module (gnu services shepherd) + #:use-module (gnu services) + #:use-module (gnu system file-systems) + #:use-module (gnu system shadow) + #:use-module (guix gexp) + #:use-module (guix least-authority) + #:use-module (guix modules) + #:use-module (guix records) + #:use-module (ice-9 match) + #:export (%readymedia-default-cache-directory + %readymedia-default-log-directory + %readymedia-default-port + %readymedia-log-file + %readymedia-user-account + %readymedia-user-group + readymedia-configuration + readymedia-configuration? + readymedia-configuration-readymedia + readymedia-configuration-port + readymedia-configuration-cache-directory + readymedia-configuration-extra-config + readymedia-configuration-friendly-name + readymedia-configuration-log-directory + readymedia-configuration-media-directories + readymedia-media-directory + readymedia-media-directory-path + readymedia-media-directory-types + readymedia-media-directory? + readymedia-service-type)) + +;;; Commentary: +;;; +;;; UPnP services. +;;; +;;; Code: + +(define %readymedia-default-cache-directory "/var/cache/readymedia") +(define %readymedia-default-log-directory "/var/log/readymedia") +(define %readymedia-log-file "minidlna.log") +(define %readymedia-user-group "readymedia") +(define %readymedia-user-account "readymedia") + +(define-record-type* + readymedia-configuration make-readymedia-configuration + readymedia-configuration? + (readymedia readymedia-configuration-readymedia + (default readymedia)) + (port readymedia-configuration-port + (default #f)) + (cache-directory readymedia-configuration-cache-directory + (default %readymedia-default-cache-directory)) + (log-directory readymedia-configuration-log-directory + (default %readymedia-default-log-directory)) + (friendly-name readymedia-configuration-friendly-name + (default #f)) + (media-directories readymedia-configuration-media-directories) + (extra-config readymedia-configuration-extra-config + (default '()))) + +;; READYMEDIA-MEDIA-DIR is a record that indicates the path of a media folder +;; and the types of media included within it. Allowed individual types are the +;; symbols 'A' for audio, 'V' for video, and 'P' for pictures. The types field +;; can contain any combination of individual types; an empty list means that +;; no type is specified. +(define-record-type* + readymedia-media-directory make-readymedia-media-directory + readymedia-media-directory? + (path readymedia-media-directory-path) + (types readymedia-media-directory-types + (default '()))) + +(define (readymedia-configuration->config-file config) + "Return the ReadyMedia/MiniDLNA configuration file corresponding to CONFIG." + (match-record config + (port friendly-name cache-directory log-directory media-directories extra-config) + (apply mixed-text-file + "minidlna.conf" + "db_dir=" cache-directory "\n" + "log_dir=" log-directory "\n" + (if friendly-name + (string-append "friendly_name=" friendly-name "\n") + "") + (if port + (string-append "port=" (number->string port) "\n") + "") + (append (map (match-record-lambda (path types) + (apply string-append + "media_dir=" + (append (map symbol->string types) + (match types + (() (list)) + (_ (list ","))) + (list path)))) + media-directories) + (map (lambda (x) + (match (pk x) + ((key . value) + (string-append key "=" value "\n")))) + extra-config))))) + +(define (readymedia-shepherd-service config) + "Return a least-authority ReadyMedia/MiniDLNA Shepherd service." + (match-record config + (cache-directory log-directory media-directories) + (let ((minidlna-conf (readymedia-configuration->config-file config))) + (shepherd-service + (documentation "Run the ReadyMedia/MiniDLNA daemon.") + (provision '(readymedia)) + (requirement '(networking user-processes)) + (start + #~(make-forkexec-constructor + (list #$(least-authority-wrapper + (file-append (readymedia-configuration-readymedia config) + "/sbin/minidlnad") + #:name "minidlna" + #:mappings + (cons* (file-system-mapping + (source cache-directory) + (target source) + (writable? #t)) + (file-system-mapping + (source log-directory) + (target source) + (writable? #t)) + (file-system-mapping + (source minidlna-conf) + (target source)) + (map (lambda (directory) + (file-system-mapping + (source (readymedia-media-directory-path directory)) + (target source) + (writable? #f))) + media-directories)) + #:namespaces (delq 'net %namespaces)) + "-f" + #$minidlna-conf + "-S") + #:log-file #$(string-append log-directory "/" %readymedia-log-file) + #:user #$%readymedia-user-account + #:group #$%readymedia-user-group)) + (stop #~(make-kill-destructor)))))) + +(define readymedia-accounts + (list (user-account + (name "readymedia") + (group "readymedia") + (system? #t) + (comment "ReadyMedia/MiniDLNA daemon user") + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin"))) + (user-group + (name "readymedia") + (system? #t)))) + +(define (readymedia-activation config) + "Set up directories for ReadyMedia/MiniDLNA." + (match-record config + (cache-directory log-directory media-directories) + (with-imported-modules (source-module-closure '((gnu build activation))) + #~(begin + (use-modules (gnu build activation)) + + (for-each (lambda (directory) + (unless (file-exists? directory) + (mkdir-p/perms directory + (getpw #$%readymedia-user-account) + #o755))) + (list #$cache-directory + #$log-directory + #$@(map readymedia-media-directory-path + media-directories))))))) + +(define readymedia-service-type + (service-type + (name 'readymedia) + (extensions + (list (service-extension shepherd-root-service-type + (compose list readymedia-shepherd-service)) + (service-extension account-service-type + (const readymedia-accounts)) + (service-extension activation-service-type + readymedia-activation))) + (description + "Run @command{minidlnad}, the ReadyMedia/MiniDLNA media server."))) diff --git a/gnu/tests/upnp.scm b/gnu/tests/upnp.scm new file mode 100644 index 0000000000..e4bce30d89 --- /dev/null +++ b/gnu/tests/upnp.scm @@ -0,0 +1,155 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Fabio Natali +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests upnp) + #:use-module (gnu services) + #:use-module (gnu services networking) + #:use-module (gnu services upnp) + #:use-module (gnu system vm) + #:use-module (gnu tests) + #:use-module (guix gexp) + #:export (%test-readymedia)) + +(define %readymedia-cache-file "files.db") +(define %readymedia-cache-path + (string-append %readymedia-default-cache-directory + "/" + %readymedia-cache-file)) +(define %readymedia-log-path + (string-append %readymedia-default-log-directory + "/" + %readymedia-log-file)) +(define %readymedia-default-port 8200) +(define %readymedia-media-directory "/media") +(define %readymedia-configuration-test + (readymedia-configuration + (media-directories + (list (readymedia-media-directory (path %readymedia-media-directory) + (types '(A V))))))) + +(define (run-readymedia-test) + (define os + (marionette-operating-system + (simple-operating-system + (service dhcp-client-service-type) + (service readymedia-service-type + %readymedia-configuration-test)) + #:imported-modules '((gnu services herd) + (json parser)) + #:requirements '(readymedia))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette + (list #$(virtual-machine + (operating-system os) + (port-forwardings '()))))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "readymedia") + + ;; ReadyMedia user + (test-assert "ReadyMedia user exists" + (marionette-eval + '(begin + (getpwnam #$%readymedia-user-account) + #t) + marionette)) + (test-assert "ReadyMedia group exists" + (marionette-eval + '(begin + (getgrnam #$%readymedia-user-group) + #t) + marionette)) + + ;; Cache directory and file + (test-assert "cache directory exists" + (marionette-eval + '(eq? (stat:type (stat #$%readymedia-default-cache-directory)) + 'directory) + marionette)) + (test-assert "cache directory has correct ownership" + (marionette-eval + '(let ((cache-dir (stat #$%readymedia-default-cache-directory)) + (user (getpwnam #$%readymedia-user-account))) + (and (eqv? (stat:uid cache-dir) (passwd:uid user)) + (eqv? (stat:gid cache-dir) (passwd:gid user)))) + marionette)) + (test-assert "cache directory has expected permissions" + (marionette-eval + '(eqv? (stat:perms (stat #$%readymedia-default-cache-directory)) + #o755) + marionette)) + + ;; Log directory and file + (test-assert "log directory exists" + (marionette-eval + '(eq? (stat:type (stat #$%readymedia-default-log-directory)) + 'directory) + marionette)) + (test-assert "log directory has correct ownership" + (marionette-eval + '(let ((log-dir (stat #$%readymedia-default-log-directory)) + (user (getpwnam #$%readymedia-user-account))) + (and (eqv? (stat:uid log-dir) (passwd:uid user)) + (eqv? (stat:gid log-dir) (passwd:gid user)))) + marionette)) + (test-assert "log directory has expected permissions" + (marionette-eval + '(eqv? (stat:perms (stat #$%readymedia-default-log-directory)) + #o755) + marionette)) + (test-assert "log file exists" + (marionette-eval + '(file-exists? #$%readymedia-log-path) + marionette)) + (test-assert "log file has expected permissions" + (marionette-eval + '(eqv? (stat:perms (stat #$%readymedia-log-path)) + #o640) + marionette)) + + ;; Service + (test-assert "ReadyMedia service is running" + (marionette-eval + '(begin + (use-modules (gnu services herd) + (srfi srfi-1)) + (live-service-running + (find (lambda (live-service) + (memq 'readymedia + (live-service-provision live-service))) + (current-services)))) + marionette)) + (test-assert "ReadyMedia service is listening for connections" + (wait-for-tcp-port #$%readymedia-default-port marionette)) + + (test-end)))) + + (gexp->derivation "readymedia-test" test)) + +(define %test-readymedia + (system-test + (name "readymedia") + (description "Test the ReadyMedia service.") + (value (run-readymedia-test)))) base-commit: d95588242c605fbb72e25fe36a0903a1538e9018 -- 2.45.2