summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: e65603631473af958186e11c974f8e5dde75edd7 (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
# Maintainer: wyf9661 <wyf9661@hotmail.com>
# Contributor: Keithsel <keithsel@disroot.org>
pkgname=9router-bin
pkgver=0.5.35
pkgrel=1
pkgdesc="AI router and proxy providing an OpenAI-compatible endpoint for multiple AI providers"
arch=('x86_64')
url="https://github.com/decolua/9router"
license=('MIT')
depends=('nodejs')
makedepends=('npm' 'python')
optdepends=('systemd: user service management via systemctl --user')
install="${pkgname}.install"
options=('!strip')
source=("${pkgname}-${pkgver}.tgz::https://registry.npmjs.org/9router/-/9router-${pkgver}.tgz"
        '9router.sh' '9router.service' '.env.example')
sha256sums=('faec36903c8a0abf5a34b09435f86de20bf8d17e97504d28e6656ee7914c38fd'
            '912c4a6f0c3589a23dd4e015c28500643727086b89463ec79f62e6dc569a4804'
            'd3cf28a661868f9cab0ba942e5be2a57f3a9cff4a66c6b9e4a26f4f0881e6f36'
            'be29534e45b564eca0a854fd06a06166a5ca0992a48bcedbc36b31e364521786')

build() {
  # npm extracts to a fixed package/ directory
  _pkgroot="${srcdir}/package"
  cd "${_pkgroot}"

  # Isolate npm cache to avoid polluting user directory
  export HOME="${srcdir}/npm-home"
  export JOBS=$(nproc)

  npm install --omit=dev --no-save --no-audit --no-fund --prefer-offline \
    enquirer node-forge node-machine-id react react-dom

  # Rebuild native module (SQLite)
  cd "${_pkgroot}/app" && npm rebuild better-sqlite3

  # Remove systray: poor Linux compatibility, triggers antivirus false positives
  rm -rf "${_pkgroot}/node_modules/systray"
}

package() {
  _pkgroot="${srcdir}/package"
  cd "${_pkgroot}"

  install -dm755 "${pkgdir}/usr/lib/node_modules/9router"
  cp -a . "${pkgdir}/usr/lib/node_modules/9router/"

  local _dest="${pkgdir}/usr/lib/node_modules/9router"

  # Clean up build artifacts and path leaks (targeted, no full-tree scan)
  find "${_dest}" -name package.json -print0 | xargs -r -0 sed -i '/_where/d'
  find "${_dest}" -type f \( -name "*.mk" -o -name "Makefile" -o -name "*.d" -o -name "config.gypi" \) -delete

  # Set correct permissions (single recursive pass)
  chmod -R a+rX "${_dest}"

  install -Dm755 "${srcdir}/9router.sh" "${pkgdir}/usr/bin/9router"
  install -Dm644 "${srcdir}/9router.service" "${pkgdir}/usr/lib/systemd/user/9router.service"
  install -Dm644 "${srcdir}/.env.example" "${pkgdir}/usr/share/doc/${pkgname}/.env.example"
  install -Dm644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}