diff options
author | eomanis | 2021-11-15 01:36:44 +0100 |
---|---|---|
committer | eomanis | 2021-11-15 01:36:44 +0100 |
commit | 22f02d2d279a259e479d1865822db8aae9c7a9af (patch) | |
tree | 84ea807d7f49bcbeb57b59d2faea9d580b33caca | |
download | aur-22f02d2d279a259e479d1865822db8aae9c7a9af.tar.gz |
Initial package release
-rw-r--r-- | .SRCINFO | 19 | ||||
-rwxr-xr-x | PKGBUILD | 64 | ||||
-rwxr-xr-x | fix-pom.xslt | 51 | ||||
-rwxr-xr-x | jmusicbot@.service | 67 |
4 files changed, 201 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..1e07ecf6580d --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,19 @@ +pkgbase = jmusicbot + pkgdesc = A cross-platform Discord music bot with a clean interface + pkgver = 0.3.6 + pkgrel = 1 + url = https://github.com/jagrosh/MusicBot + arch = any + license = Apache + makedepends = java-environment>=11 + makedepends = maven + makedepends = libxslt + depends = java-runtime-headless>=11 + source = JMusicBot-0.3.6.tar.gz::https://github.com/jagrosh/MusicBot/archive/refs/tags/0.3.6.tar.gz + source = fix-pom.xslt + source = jmusicbot@.service + sha384sums = 84f26730f6dbda43780e329a85fe826f84c9ce42f431ceafb02a55f53cf2613b4b5a4a630904ab95a6131bcc96b4aeff + sha384sums = b14dcf390d40f51d40b2aee4e8c44722837ad7a9850ecfd48174c74e8ed50709b6a64a817c301a2186e6386c26de0440 + sha384sums = 12ca3d4af2f117fee113034cca66558aa2cec47865245f58b1a4e71ae2cebd24783e14f644292e9344b290c1962448a8 + +pkgname = jmusicbot diff --git a/PKGBUILD b/PKGBUILD new file mode 100755 index 000000000000..04ae22aa0439 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,64 @@ +# Maintainer: eomanis at web dot de + +_appname='jmusicbot' +pkgname="$_appname" +_pkgverUpstream="0.3.6" +pkgver="${_pkgverUpstream//-/.}" +pkgrel=1 +pkgdesc="A cross-platform Discord music bot with a clean interface" +arch=('any') +url='https://github.com/jagrosh/MusicBot' +license=('Apache') +depends=('java-runtime-headless>=11') +makedepends=('java-environment>=11' 'maven' 'libxslt') +source=("JMusicBot-${_pkgverUpstream}.tar.gz::https://github.com/jagrosh/MusicBot/archive/refs/tags/${_pkgverUpstream}.tar.gz" + "fix-pom.xslt" + "jmusicbot@.service") +sha384sums=('84f26730f6dbda43780e329a85fe826f84c9ce42f431ceafb02a55f53cf2613b4b5a4a630904ab95a6131bcc96b4aeff' + 'b14dcf390d40f51d40b2aee4e8c44722837ad7a9850ecfd48174c74e8ed50709b6a64a817c301a2186e6386c26de0440' + '12ca3d4af2f117fee113034cca66558aa2cec47865245f58b1a4e71ae2cebd24783e14f644292e9344b290c1962448a8') + +build() { + local buildDir="${srcdir}/MusicBot-${_pkgverUpstream}" + + cd "$buildDir" + + # Project version in pom.xml is set to "Snapshot" + # Set it to the upstream version + xsltproc --nonet --stringparam project-version "$_pkgverUpstream" "${srcdir}/fix-pom.xslt" "pom.xml" > "pom.xml.tmp" + mv "pom.xml" "pom.xml.original" + mv "pom.xml.tmp" "pom.xml" + + # Build with Maven + mvn clean + mvn install +} + +package() { + local buildDir="${srcdir}/MusicBot-${_pkgverUpstream}" + local jarFileName="JMusicBot-${_pkgverUpstream}-All.jar" + local jarFileNameUnversioned="JMusicBot.jar" + local refConfFileName="reference-${_pkgverUpstream}.conf" + local refConfFileNameUnversioned="reference.conf" + + # Place the .jar file and create a non-versioned symlink to it + mkdir --parents "${pkgdir}/usr/bin" + cd "${pkgdir}/usr/bin" + cp --target-directory . "${buildDir}/target/$jarFileName" + chmod u=rwx,go=rx "$jarFileName" + ln -s "$jarFileName" "$jarFileNameUnversioned" + + # Place the reference configuration file and create a non-versioned + # symlink to it + mkdir --parents "${pkgdir}/usr/share/jmusicbot" + cd "${pkgdir}/usr/share/jmusicbot" + cp "${buildDir}/src/main/resources/reference.conf" "$refConfFileName" + chmod u=rwx,go=rx "$refConfFileName" + ln -s "$refConfFileName" "$refConfFileNameUnversioned" + + # Place the systemd instantiated system service + mkdir --parents "${pkgdir}/usr/lib/systemd/system" + cd "${pkgdir}/usr/lib/systemd/system" + cp --target-directory . "${srcdir}/jmusicbot@.service" + chmod u=rwx,go=rx "jmusicbot@.service" +} diff --git a/fix-pom.xslt b/fix-pom.xslt new file mode 100755 index 000000000000..01a8cf9e959e --- /dev/null +++ b/fix-pom.xslt @@ -0,0 +1,51 @@ +<?xml version = "1.0" encoding = "UTF-8"?> + +<xsl:stylesheet version = "1.0" +xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" +xmlns = "http://maven.apache.org/POM/4.0.0" +xmlns:m = "http://maven.apache.org/POM/4.0.0" +exclude-result-prefixes="m"> + + <!-- + Sets a Maven pom.xml's project version to a specific value if it is + "Snapshot" + + Apply to a pom.xml file like this, but replace every = with - + xsltproc ==nonet ==stringparam project-version "the.version" this.xslt pom.xml > new-pom.xml + + I would like to thank these people for making this XSLT possible: + + Romain Pelisse for this article at developers.redhat.com: + https://developers.redhat.com/blog/2013/12/05/xml-editing-bash-script + (xsltproc usage, passing in parameters) + + User "michael.hor257k" for this answer at stackoverflow.com: + https://stackoverflow.com/questions/61872525/updating-pom-xml-elements-using-xslt/61874979#61874979 + (XML namespaces magic) + + Apologies go to my brain for subjecting it to the topic of XML + processing + --> + + <!-- Retain the "encoding" attribute in the emitted XML --> + <xsl:output encoding="UTF-8" /> + + <!-- Parameter value is passed in with the xsltproc invocation --> + <xsl:param name="project-version"/> + + <!-- Copy all nodes and their attributes (identity transform) --> + <xsl:template match="@*|node()" name="identity"> + <xsl:copy> + <xsl:apply-templates select="@*|node()" /> + </xsl:copy> + </xsl:template> + + <!-- + Replace upstream /project/version node value "Snapshot" with the + actual version number + --> + <xsl:template match="m:version/text()[.='Snapshot']" name="set-project-version"> + <xsl:value-of select="$project-version" /> + </xsl:template> + +</xsl:stylesheet> diff --git a/jmusicbot@.service b/jmusicbot@.service new file mode 100755 index 000000000000..c4f205cc3ea6 --- /dev/null +++ b/jmusicbot@.service @@ -0,0 +1,67 @@ +# JMusicBot minimally-privileged systemd instantiated service +# +# Example: The instance name is "my-channel", e.g. the service instance +# is "jmusicbot@my\x2dchannel.service": +# - The service will run as user "jmusicbot-my-channel" +# - Working directory: "/srv/jmusicbot-my-channel" +# - Configuration: "/srv/jmusicbot-my-channel/config.txt" +# - State: "/srv/jmusicbot-my-channel/serversettings.json" +# - Playlists dir: "/srv/jmusicbot-my-channel/Playlists" +# +# Setup steps for the "my-channel" service instance, as root, in bash: +# - Create new user "jmusicbot-my-channel" with home directory: +# # useradd --home-dir /srv/jmusicbot-my-channel --create-home --shell /usr/bin/nologin jmusicbot-my-channel +# - Start interactive bash shell as the new user: +# # sudo --user=jmusicbot-my-channel --shell /bin/bash +# - Go to the new users's home directory: +# $ cd +# - Copy the reference configuration file to the new user's home +# directory: +# $ cp /usr/share/jmusicbot/reference.conf config.txt +# - Edit configuration file to your liking: +# $ nano config.txt +# - Return to the root shell: +# $ exit +# - Start service instance: +# # systemctl start "jmusicbot@$(systemd-escape "my-channel").service" + +[Unit] +Description=JMusicBot instance "%I" +Requires=network.target local-fs.target +After=network.target local-fs.target + +[Install] +WantedBy=multi-user.target + +[Service] +Type=exec +User=jmusicbot-%I +ExecStart=/usr/bin/java -Dnogui=true -jar /usr/bin/JMusicBot.jar +WorkingDirectory=/srv/jmusicbot-%I +Restart=always +RestartSec=5 + +# Security and hardening options copied from +# https://gist.github.com/ageis/f5595e59b1cddb1513d1b425a323db04 +NoNewPrivileges=yes +PrivateTmp=yes +PrivateDevices=yes +DevicePolicy=closed +# Deny write access to the entire file system +ProtectSystem=strict +# Selectively allow write access for required paths +ReadWritePaths=/srv/jmusicbot-%I +# Do not allow any access whatsoever to /home, /root and /run/user +ProtectHome=yes +ProtectControlGroups=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +# Only AF_INET and AF_INET6 +RestrictAddressFamilies=AF_INET AF_INET6 +RestrictNamespaces=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +# This service uses Java, which uses a virtual machine, and this option +# is not compatible with virtual machines +#MemoryDenyWriteExecute=yes +LockPersonality=yes |