summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 3e2abf66b7b1046ccb42a08f3ab3b5dcfb30ce47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# shellcheck shell=bash
# shellcheck disable=SC2034  # Various variables that are used by makepkg
# shellcheck disable=SC2154  # Various variables that are provided by makepkg
# Maintainer: eomanis at web dot de

_appname='jmusicbot'
pkgname="$_appname"
_pkgverUpstream="0.4.3"
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"
        "jmusicbot.service")
sha384sums=('a71020a417953ce4252deada8ecfac2b3568b16c95d15cb507ec8860205455d4792371780166a553ea2d314964561026'
            'b14dcf390d40f51d40b2aee4e8c44722837ad7a9850ecfd48174c74e8ed50709b6a64a817c301a2186e6386c26de0440'
            '0e2f5b34b17ab99c425712b8e164493538c0d8df45b9d997649dbf6332bbdef7d6ce33e195ed331cf02d132ee2fa7e88'
            'b57c88e240c167debd323399b4144a1f0a566205ccfe54075f06481fe6cfb105f92bc94536575b84bbc1607c102b5e75')

# Build parameters
# Uncomment and edit to build with a specific Java Development Kit
#JAVA_HOME="/usr/lib/jvm/java-11-openjdk"
# Uncomment and edit to use a specific Maven installation
#MVN_HOME="/opt/maven"

build() {
    local buildDir="${srcdir}/MusicBot-${_pkgverUpstream}"

    cd "$buildDir" || return 1

    # 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"

    # Set JAVA_HOME if it is not set
    if test -z ${JAVA_HOME+x}; then
        JAVA_HOME="/usr/lib/jvm/default"
    fi
    export JAVA_HOME
    echo "JAVA_HOME is \"$JAVA_HOME\"" >&2

    # Set MVN_HOME if it is not set
    if test -z ${MVN_HOME+x}; then
        MVN_HOME="/opt/maven"
    fi
    export MVN_HOME
    echo "MVN_HOME is \"$MVN_HOME\"" >&2

    # 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"

    # Create the required directories
    install --mode=u=rwx,go=rx --directory -- \
        "${pkgdir}/usr/bin" \
        "${pkgdir}/usr/share/jmusicbot" \
        "${pkgdir}/usr/lib/systemd/system" \
        "${pkgdir}/usr/lib/systemd/user"

    # Place the .jar file and create a non-versioned symlink to it
    install --mode=u=rwx,go=rx --target-directory="${pkgdir}/usr/bin" -- "${buildDir}/target/$jarFileName"
    ln --symbolic --relative -- "${pkgdir}/usr/bin/$jarFileName" "${pkgdir}/usr/bin/$jarFileNameUnversioned"

    # Create bash launcher: Default
    echo -n \
"#!/bin/bash
/usr/bin/java -jar \"/usr/bin/${jarFileNameUnversioned}\" \"\$@\"
"                   > "${pkgdir}/usr/bin/jmusicbot"
    chmod -- u=rwx,go=rx "${pkgdir}/usr/bin/jmusicbot"

    # Create bash launcher: Command line only
    echo -n \
"#!/bin/bash
/usr/bin/java -Dnogui=true -jar \"/usr/bin/${jarFileNameUnversioned}\" \"\$@\"
"                   > "${pkgdir}/usr/bin/jmusicbot-nogui"
    chmod -- u=rwx,go=rx "${pkgdir}/usr/bin/jmusicbot-nogui"

    # Place the reference configuration file and create a non-versioned
    # symlink to it
    install --mode=u=rw,go=r -- "${buildDir}/src/main/resources/reference.conf" "${pkgdir}/usr/share/jmusicbot/$refConfFileName"
    ln --symbolic --relative -- "${pkgdir}/usr/share/jmusicbot/$refConfFileName" "${pkgdir}/usr/share/jmusicbot/$refConfFileNameUnversioned"

    # Place the systemd instantiated system service
    install --mode=u=rw,go=r --target-directory="${pkgdir}/usr/lib/systemd/system" -- "${srcdir}/jmusicbot@.service"

    # Place the systemd user service
    install --mode=u=rw,go=r --target-directory="${pkgdir}/usr/lib/systemd/user" -- "${srcdir}/jmusicbot.service"
}