summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 6b1091153b1b13b2204cd4bdeca727e1689f1eaa (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Maintainer: Matheus Gabriel Werny de Lima <matheusgwdl@protonmail.com>

_pkgname=matomo

# shellcheck disable=SC2034
pkgname=matomo-git
# shellcheck disable=SC2034
pkgver=latest_tag
# shellcheck disable=SC2034
pkgrel=1
# shellcheck disable=SC2034
epoch=
# shellcheck disable=SC2034
pkgdesc="A powerful web analytics platform."
# shellcheck disable=SC2034
arch=("any")
url="https://github.com/matomo-org/${_pkgname}"
# shellcheck disable=SC2034
license=("GPL3")
# shellcheck disable=SC2034
groups=()
# shellcheck disable=SC2034
depends=("php" "php-fpm" "php-gd")
# shellcheck disable=SC2034
makedepends=("composer" "curl" "git" "gzip")
# shellcheck disable=SC2034
checkdepends=()
# shellcheck disable=SC2034
optdepends=("apache: HTTP server"
"certbot: Creates SSL certificates."
"mariadb: Database"
"nginx: HTTP server")
# shellcheck disable=SC2034
provides=("${_pkgname}")
# shellcheck disable=SC2034
conflicts=("matomo")
# shellcheck disable=SC2034
replaces=()
# shellcheck disable=SC2034
backup=()
# shellcheck disable=SC2034
options=()
# shellcheck disable=SC2034
install=
# shellcheck disable=SC2034
changelog=
# shellcheck disable=SC2034
source=("git+${url}.git")
# shellcheck disable=SC2034
noextract=()
# shellcheck disable=SC2034
md5sums=("SKIP")
# shellcheck disable=SC2034
validpgpkeys=()

pkgver()
{
    # shellcheck disable=SC2154
    cd "${srcdir}"/"${_pkgname}"/ || exit
    version=$(git describe --tags --abbrev=0)
    printf "%s" "${version}" | sed "s/^v//;s/-/_/g;s/\//./g"
}

build()
{
    # Information
    echo -e "\033[0;32mConfiguration is needed before the installation. For assistance, read the included \"README.md\".\033[0m"

    cd "${srcdir}"/"${_pkgname}"/ || exit
    git checkout tags/"$(git describe --tags --abbrev=0)"
    git submodule update --init --merge --recursive
    composer install --no-dev
}

package()
{
    # Assure that the directories exist.
    # shellcheck disable=SC2154
    mkdir -p "${pkgdir}"/etc/systemd/system/php-fpm.service.d/
    mkdir -p "${pkgdir}"/usr/share/doc/"${_pkgname}"/
    mkdir -p "${pkgdir}"/usr/share/licenses/"${_pkgname}"/
    mkdir -p "${pkgdir}"/usr/share/webapps/"${_pkgname}"/misc/

    # Install the software.
    cp -r "${srcdir}"/"${_pkgname}"/ "${pkgdir}"/usr/share/webapps/

    ## GeoIP database
    cur_year=$(date +"%Y")
    cur_month=$(date +"%m")

    while [ "$(curl -s -o /dev/null/ -w "%{http_code}" https://download.db-ip.com/free/dbip-city-lite-"${cur_year}"-"${cur_month}".mmdb.gz)" != "200" ]; do
        # Remove the preceding 0.
        if [ "${cur_month::1}" == "0" ]; then
            cur_month=${cur_month:1}
        fi

        # Take the last month.
        if [ "${cur_month}" -gt 1 ]; then
            ((cur_month--))
        else
            ((cur_year--))
            cur_month=12
        fi

        # Put a 0 at the beginning.
        if [ "${#cur_month}" == 2 ]; then
            cur_month="0${cur_month}"
        fi
    done

    curl https://download.db-ip.com/free/dbip-city-lite-"${cur_year}"-"${cur_month}".mmdb.gz -o "DBIP-City-Lite.mmdb.gz"
    gzip -d "${srcdir}"/DBIP-City-Lite.mmdb.gz
    install -Dm644 "${srcdir}"/DBIP-City-Lite.mmdb "${pkgdir}"/usr/share/webapps/"${_pkgname}"/misc/

    ## Configure php-fpm.
    echo -e "[Service]
ReadWritePaths = /usr/share/webapps/${_pkgname}/config/
ReadWritePaths = /usr/share/webapps/${_pkgname}/matomo.js
ReadWritePaths = /usr/share/webapps/${_pkgname}/misc/user/
ReadWritePaths = /usr/share/webapps/${_pkgname}/plugins/
ReadWritePaths = /usr/share/webapps/${_pkgname}/tmp/" > "${pkgdir}"/etc/systemd/system/php-fpm.service.d/override_matomo.conf

    ## Set the owner.
    chown -R http:http "${pkgdir}"/usr/share/webapps/"${_pkgname}"/

    # Install the documentation.
    install -Dm644 "${srcdir}"/"${_pkgname}"/README.md "${pkgdir}"/usr/share/doc/"${_pkgname}"/

    # Install the license.
    install -Dm644 "${srcdir}"/"${_pkgname}"/LICENSE "${pkgdir}"/usr/share/licenses/"${_pkgname}"/
}