summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 62f2b23cd9103d89d059f49f45bf4d0e7c11fcae (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Maintainer: William Gathoye <william + aur at gathoye dot be>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Massimiliano Torromeo <massimiliano dot torromeo at gmail dot com>
# Contributor: Bruno Pagani <archange at archlinux dot org>

pkgname=mattermost
pkgver=5.14.0
pkgrel=1
pkgdesc='Open source Slack-alternative in Golang and React'
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
url='https://mattermost.com'
license=('AGPL' 'Apache')

makedepends=('git' 'go-pie' 'libpng' 'npm' 'python2' 'curl' 'wget')
# Experiencing issues with gifsicle and mozjpeg on non x64 architectures.
if [ "$CARCH" != 'x86_64' ]; then
    makedepends+=('gifsicle' 'mozjpeg')
fi
optdepends=(
    'mariadb: SQL server storage'
    'percona-server: SQL server storage'
    'postgresql: SQL server storage'
)
backup=("etc/webapps/$pkgname/config.json")
source=(
    "$pkgname-server-$pkgver.tar.gz::https://github.com/$pkgname/$pkgname-server/archive/v$pkgver.tar.gz"
    "$pkgname-webapp-$pkgver.tar.gz::https://github.com/$pkgname/$pkgname-webapp/archive/v$pkgver.tar.gz"
    "mattermost-ldflags.patch"
    "$pkgname.service"
    "$pkgname.sysusers"
    "$pkgname.tmpfiles"
)
sha512sums=('7845cd37ecf85a4414eca887ebb3894be34dff66c2f832bedf58d8d08e69ccdbdf41218322cdaade44e460a676728a0d480eb86c1387faba260257a7d0a3cf89'
            '16e6671dab37b8e422915920111a9b69e84adc042a66c14fe5638a665e242f14c474e795d5abb65e76093dc7ce5b5d94e82fe77f6d58f7bdd14cbcfa1b8817b4'
            '5b761c5715387e6abf3afbe653de218b9a45708d7ffbc699856f53cc3e62760fbd0ce175615f36a4b9090182705c3343d07fca72d12275411080ab516cee3eeb'
            '6fc1b41f1ddcc44dab3e1f6bc15b7566e7c33132346b7eb0bc91d9709b4cec89ae969a57a57b6097c75868af21f438c2affda5ba1507f485c8689ab8004efd70'
            'f08d88fd91e91c8b9996cf33699f4a70d69c8c01783cf7add4781ee3c9c6596839e44c5c39f0ff39a836c6d87544eef179f51de0b037ec7f91f86bac8e24d7cc'
            'e3ffcf4b86e2ecc7166c1abf92cd4de23d81bad405db0121e513a8d81fea05eec9dd508141b14b208c4c13fbc347c56f01ed91326faa01e872ecdedcc18718f9')

prepare() {
    # cp cannot copy from a symbolic link to the destination link itself
    # a symbolic link located outside the first symbolic link folder location.
    # e.g.
    # mattermost-server is a symlink
    # mattermost-webapp is a symlink
    # we are in the folder mattermost-server and we want to execute
    # cp -RL ../mattermost-webapp/dist/* dist/mattermost/client/
    # this command will fail with
    # cp: cannot stat '../mattermost-webapp/dist/*': No such file or directory
    cd "$srcdir"
    rm -rf "$pkgname"-server "$pkgname"-webapp
    mv "$pkgname-server-$pkgver" "$pkgname"-server
    mv "$pkgname-webapp-$pkgver" "$pkgname"-webapp

    mkdir -p src/github.com/"$pkgname"
    cd src/github.com/"$pkgname"

    # Remove previous platform folders if any previous clone was effective
    rm -f "$pkgname"-server
    rm -f "$pkgname"-webapp

    # Create the directory structure to match Go namespaces
    ln -s "$srcdir"/"$pkgname"-server "$pkgname"-server
    ln -s "$srcdir"/"$pkgname"-webapp "$pkgname"-webapp
    cd "$pkgname"-server

    # Pass Arch Linux's Go compilation flags to Mattermost in order to take
    # into account advanced features like PIE.
    patch < "$srcdir"/mattermost-ldflags.patch

    # We are not using docker, no need to stop it.
    sed -r -i Makefile \
        -e 's/^clean: stop-docker/clean:/'

    # The configuration isn't available at this time yet, modify the default.
    sed -r -i build/release.mk \
        -e  's!config/config.json!config/default.json!' \
        -e 's/\$\(DIST_PATH\)\/config\/config.json/\$\(DIST_PATH\)\/config\/default.json/'

    # The Go programming language only supports 8 instruction sets, therefore
    # we cannot rely on ${CARCH} and need to cast manually.
    # src.: https://golang.org/doc/install/source#introduction
    case "$CARCH" in
        i686)
            sed -r -i build/release.mk \
                -e "5,7s/amd64/386/"
            ;;
        arm*64*|*arch*64*)
            sed -r -i build/release.mk \
                -e "5,7s/amd64/arm64/"
            ;;
        arm*)
            sed -r -i build/release.mk \
                -e "5,7s/amd64/arm/"
            ;;
    esac

    # Remove platform specific lines from the Makefile from the line beginning
    # with that statement to the end of file (we do not care of the additional
    # file copy, nor the tar compression defined below the file).
    sed '/# Download prepackaged plugins/,//d' -i ./build/release.mk

    # Enforce build hash to Arch Linux (Enterprise hash is already set to
    # none), instead of the official git hash value and use an ISO 8601
    # inspired compilation date format without any letter format (only use
    # numbers).
    sed -r -i Makefile \
        -e "s/^(\s*)BUILD_HASH =.*/\1BUILD_HASH = $pkgver-$pkgrel Arch Linux \($CARCH\)/" \
        -e 's/BUILD_DATE = \$\(shell date -u\)/BUILD_DATE = \$(shell date -u +'"'"'%Y-%m-%d %H:%M:%S'"'"')/'

    # Enforce build hash to Arch Linux as well for the field corresponding to
    # the webapp.
    cd "$srcdir/$pkgname-webapp"
    sed -r -i webpack.config.js \
        -e "s/^(\s*)COMMIT_HASH:(.*),$/\1COMMIT_HASH: JSON.stringify\(\"$pkgver-$pkgrel Arch Linux \($CARCH\)\"\),/"

    # Link against system gifsicle
    if [ "$CARCH" != 'x86_64' ]; then
        gifsicleNpm="$srcdir/$pkgname-webapp/node_modules/gifsicle/vendor/gifsicle"
        gifsicleNpm="${gifsicleNpm//\//\\/}"
        gifsicleSystem="$(which gifsicle)"
        gifsicleSystem="${gifsicleSystem//\//\\/}"
        sed -r -i Makefile \
            -e "s/(\t*)npm install(.*)/\0\n\trm \"$gifsicleNpm\"\n\tln -s \"$gifsicleSystem\" \"$gifsicleNpm\"/"
    fi
}

build() {
    # No need to build mattermost-webapp as the server is taking care of this
    # step via its build-client make instruction.

    cd "$srcdir"/src/github.com/"$pkgname/$pkgname"-server
    # Prevent the build to crash when some dependencies are not met or
    # outdated. This cleans the webapp as well (cf. mattermost-server/Makefile,
    # clean target).
    make clean
    GOPATH="$srcdir" BUILD_NUMBER=$pkgver-$pkgrel make build-linux
    GOPATH="$srcdir" BUILD_NUMBER=$pkgver-$pkgrel make build-client
    GOPATH="$srcdir" BUILD_NUMBER=$pkgver-$pkgrel make package
}

package() {
    cd "$srcdir"/src/github.com/"$pkgname/$pkgname"-server

    install -dm755 \
        "$pkgdir"/usr/bin \
        "$pkgdir"/usr/share/webapps \
        "$pkgdir"/etc/webapps \
        "$pkgdir"/usr/share/doc/"$pkgname"

    cp -a dist/"$pkgname" "$pkgdir"/usr/share/webapps/

    cd "$pkgdir"/usr/share/webapps/"$pkgname"
    install -dm755 client/plugins

    rm -rf logs
    ln -s /var/log/"$pkgname" logs

    cp config/default.json config/config.json
    mv config "$pkgdir"/etc/webapps/"$pkgname"
    ln -s /etc/webapps/"$pkgname" config

    sed -e 's@"Directory": ".*"@"Directory": "/var/lib/mattermost/"@g' \
        -e 's@tcp(dockerhost:3306)@unix(/run/mysqld/mysqld.sock)@g' \
        -i "$pkgdir"/etc/webapps/"$pkgname"/config.json

    mv NOTICE.txt README.md "$pkgdir"/usr/share/doc/"$pkgname"

    cd "$srcdir"
    install -Dm755 "bin/$pkgname" "$pkgdir/usr/share/webapps/$pkgname/bin/$pkgname"
    ln -s "/usr/share/webapps/$pkgname/bin/$pkgname" "$pkgdir/usr/bin/$pkgname"
    install -Dm644 "$pkgname.service" -t "$pkgdir/usr/lib/systemd/system/"
    install -Dm644 "$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
    install -Dm644 "$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
}