summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: aa7a0fb76a6e4be3484a25e5a39fb8c7dcc7f7d6 (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
# Maintainer: Nikos Toutountzoglou <nikos.toutou@protonmail.com>
# Contributor: Josef Miegl <josef@miegl.cz>
# Contributor: Xavier Devlamynck <magicrhesus@ouranos.be>

pkgname=kamailio
pkgver=6.1.4
pkgrel=1
pkgdesc="SIP Server for large VoIP and real-time communication platforms"
arch=('x86_64')
url="https://www.kamailio.org"
license=('GPL-2.0-or-later')

depends=(
  'bash' 'glibc' 'readline' 'ncurses' 'expat' 'jansson' 'libev'
)

makedepends=(
  'cmake' 'gcc' 'make' 'pkg-config' 'flex' 'bison' 'clang'
  'openssl' 'libmariadbclient' 'postgresql-libs' 'sqlite'
  'python' 'lua' 'libxml2' 'curl' 'libunistring' 'util-linux'
  'lynx' 'libxslt' 'docbook2x' 'docbook-xsl' 'lksctp-tools'
)

optdepends=(
  'mariadb-libs: MySQL/MariaDB database support'
  'postgresql-libs: PostgreSQL database support'
  'sqlite: SQLite database support'
  'python: Python 3 KEMI scripting support'
  'lua: Lua KEMI scripting support'
  'curl: HTTP client support'
  'libxml2: XML operations'
  'unixodbc: ODBC database support'
  'lksctp-tools: SCTP transport support'
)

backup=(
  'etc/kamailio/kamailio.cfg'
  'etc/kamailio/kamctlrc'
  'etc/kamailio/tls.cfg'
)

install="${pkgname}.install"

source=("https://www.kamailio.org/pub/${pkgname}/latest/src/${pkgname}-${pkgver}_src.tar.gz"
        "${pkgname}.sysusers"
        "${pkgname}.tmpfiles")
sha256sums=('290624b6624edc230af0fc458fb7e481e64b893be7cb5084398e587942992e0a'
            'cbc0d7510a52791cb2016d91df9543433f3b8467efec196ed06d025ba5f8a0fa'
            'edcbe39e6c5c368109e791693302dfc41c1b63f654eb6311281a8bdfc4adfbf3')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # Patch helper scripts in source to look in /usr/bin
  find utils/kamctl/ -type f -exec sed -i 's|/usr/sbin|/usr/bin|g' {} +

  # Patch systemd service
  if [ -f "pkg/${pkgname}/obs/${pkgname}.service" ]; then
    sed -i \
      -e "s#ExecStart=/usr/sbin/${pkgname}#ExecStart=/usr/bin/${pkgname}#g" \
      -e "s#EnvironmentFile=-/etc/sysconfig/${pkgname}#EnvironmentFile=-/etc/default/${pkgname}#g" \
      "pkg/${pkgname}/obs/${pkgname}.service"
  fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  local modules='acc;alias_db;async;auth;auth_db;avpops;benchmark;blst;cfg_rpc;cfgutils;corex;counters;ctl;debugger;dialog;dialplan;dispatcher;dmq;domain;domainpolicy;drouting;enum;exec;group;htable;ipops;jansson;jsonrpcs;kex;lcr;maxfwd;mqueue;nathelper;path;pdt;permissions;pike;pipelimit;prefix_route;pv;ratelimit;regex;registrar;rls;rr;rtimer;sanity;sca;sdpops;siputils;sl;speeddial;sqlops;statistics;textops;tm;tmx;topoh;uac;usrloc;xlog;db_mysql;db_postgres;db_sqlite;tls;websocket;sctp;app_python3;app_lua'

  local cmake_options=(
    -B build
    -S .
    -Wno-dev
    -DCMAKE_BUILD_TYPE=None
    -DINCLUDE_MODULES="${modules}"
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_LIBDIR=/usr/lib
    -DCMAKE_INSTALL_BINDIR=/usr/bin
    -DCMAKE_INSTALL_SBINDIR=/usr/bin
    -DCMAKE_INSTALL_SYSCONFDIR=/etc
    -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/kamailio
    -DCMAKE_INSTALL_MANDIR=/usr/share/man
    -DBUILD_DOC=ON
    -DLYNX_EXECUTABLE=/usr/bin/lynx
    -DXSLTPROC_EXECUTABLE=/usr/bin/xsltproc
    -DDOCBOOK2X_EXECUTABLE=/usr/bin/docbook2x-man
    -DUSE_TCP=ON
    -DUSE_TLS=ON
    -DUSE_SCTP=ON
    -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}"
    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}"
  )

  # Configure and build
  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  
  DESTDIR="${pkgdir}" cmake --install build

  # Enforce Arch Linux standard (Binaries in /usr/bin)
  if [ -d "${pkgdir}/usr/sbin" ]; then
    mv "${pkgdir}/usr/sbin/"* "${pkgdir}/usr/bin/"
    rmdir "${pkgdir}/usr/sbin"
  fi

  # Sanitize Config Paths (/usr/local -> /etc or /usr)
  find "${pkgdir}/etc/kamailio" -name "*.cfg" -type f -exec sed -i 's|/usr/local/etc|/etc|g' {} +
  find "${pkgdir}/etc/kamailio" -name "*.cfg" -type f -exec sed -i 's|/usr/local/lib|/usr/lib|g' {} +

  # Fix kamctlrc specifically
  if [ -f "${pkgdir}/etc/kamailio/kamctlrc" ]; then
    sed -i "s|${srcdir}/${pkgname}-${pkgver}||g" "${pkgdir}/etc/kamailio/kamctlrc"
    sed -i 's|/usr/sbin|/usr/bin|g' "${pkgdir}/etc/kamailio/kamctlrc"
    sed -i 's|/usr/local|/usr|g' "${pkgdir}/etc/kamailio/kamctlrc"
  fi

  # Clean executable scripts in /usr/bin
  for file in kamctl kamdbctl; do
    if [ -f "${pkgdir}/usr/bin/${file}" ]; then
      sed -i "s|${srcdir}/${pkgname}-${pkgver}||g" "${pkgdir}/usr/bin/${file}"
      sed -i "s|${srcdir}||g" "${pkgdir}/usr/bin/${file}"
      sed -i 's|/usr/sbin|/usr/bin|g' "${pkgdir}/usr/bin/${file}"
    fi
  done

  # Standard Cleanup & System Integration
  find "${pkgdir}/usr/share/man" -type d -empty -delete

  install -Dm644 "COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  install -Dm644 "pkg/${pkgname}/obs/${pkgname}.service" \
    "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"

  install -Dm644 "${srcdir}/${pkgname}.sysusers" \
    "${pkgdir}/usr/lib/sysusers.d/${pkgname}.conf"

  install -Dm644 "${srcdir}/${pkgname}.tmpfiles" \
    "${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"
}

# vim:set ts=2 sw=2 et: