summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 9b3d254961da0d4b2261333e9c2dfda0297c0b25 (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
#!/usr/bin/env bash
# shellcheck disable=SC2034
# shellcheck disable=SC2154
# The PKGBUILD for farmOS.
# Maintainer: Matheus <matheusgwdl@protonmail.com>
# Contributor: Matheus <matheusgwdl@protonmail.com>

readonly _pkgname="farmOS"

pkgname="farmos"
pkgver="3.3.2"
pkgrel="1"
pkgdesc="A web-based farm record keeping application."
arch=("any")
url="https://github.com/farmOS/${_pkgname}"
license=("GPL-2.0-or-later")
depends=("bash" "perl" "php" "php-fpm" "php-gd" "php-sodium")
makedepends=("composer")
optdepends=("apache: HTTP server"
    "certbot: Creates SSL certificates."
    "mariadb: Database"
    "nginx: HTTP server"
    "php-geos-git: Geometry"
    "php-pgsql: Database support for PostgreSQL"
    "php-sqlite: Database support for SQLite"
    "postgresql: Database"
    "sqlite: Database")
source=("${pkgname}-v${pkgver}.tar.gz::${url}/releases/download/${pkgver}/${_pkgname}-${pkgver}.tar.gz"
    "override-${pkgname}.conf")
sha256sums=("94fcf6dd465b78f28d7681092d6683a35651e75730cb35377e6e62210c5e710f"
    "d42161c817011222d256232cacecf6b176901d48f8e7db70a10de5e98ea102bd")

build()
{
    cd "${srcdir}"/"${_pkgname}"/ || exit 1
    composer install --no-dev
}

package()
{
    # Assure that the directories exist.
    mkdir -p "${pkgdir}"/usr/lib/systemd/system/php-fpm.service.d/
    mkdir -p "${pkgdir}"/usr/share/doc/"${pkgname}"/
    mkdir -p "${pkgdir}"/usr/share/webapps/"${pkgname}"/

    # Install the software.
    cp -r "${srcdir}"/"${_pkgname}"/* "${pkgdir}"/usr/share/webapps/"${pkgname}"/
    install -Dm644 "${srcdir}"/override-"${pkgname}".conf "${pkgdir}"/usr/lib/systemd/system/php-fpm.service.d/
    chown -R http:http "${pkgdir}"/usr/share/webapps/"${pkgname}"/

    ## Configuration
    sed -i "s/^# \\\$settings\['file_private_path'\] = '';$/\$settings['file_private_path'] = '\/usr\/share\/webapps\/${pkgname}\/web\/sites\/default\/private\/files\/';/g" "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php

    if ! grep -Eq "^\\\$settings\['file_private_path'\] = '/usr/share/webapps/${pkgname}/web/sites/default/private/files/';$" "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php; then
        echo "String not found!" >&2
        exit 1
    fi

    perl -0e "s/# \\\$config\['user.settings'\]\['anonymous'\] = 'Visitor';\n/# \\\$config['user.settings']['anonymous'] = 'Visitor';\n\\\$config['system.performance']['css']['preprocess'] = FALSE;\n\\\$config['system.performance']['js']['preprocess'] = FALSE;\n/g" -i -p "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php

    if ! pcregrep -Mq "# \\\$config\['user.settings'\]\['anonymous'\] = 'Visitor';\n\\\$config\['system.performance'\]\['css'\]\['preprocess'\] = FALSE;\n\\\$config\['system.performance'\]\['js'\]\['preprocess'\] = FALSE;\n" "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php; then
        echo "String not found!" >&2
        exit 1
    fi

    sed -i "s/^# \\\$settings\['trusted_host_patterns'\] = \[\];/\$settings['trusted_host_patterns'] = ['^127\\\.0\\\.0\\\.1$', '^localhost$'];/g" "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php

    if ! grep -Eq "^\\\$settings\['trusted_host_patterns'\] = \['\^127\\\.0\\\.0\\\.1\\\$', '\^localhost\\\$'\];$" "${pkgdir}"/usr/share/webapps/"${pkgname}"/web/sites/default/default.settings.php; then
        echo "String not found!" >&2
        exit 1
    fi

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