summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 9d76b72c8e65bca9e5300253c5efecf8fdc06dac (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
_pkgname=zigbee2mqtt
pkgname=zigbee2mqtt-git
pkgver=2.7.2.r0.g3a49c957
pkgrel=1
pkgdesc='A Zigbee to MQTT bridge'
arch=('x86_64' 'armv7h' 'aarch64')
url='https://www.zigbee2mqtt.io'
license=('GPL-3.0-or-later')
depends=('nodejs')
conflicts=('zigbee2mqtt')
provides=('zigbee2mqtt')
makedepends=('git' 'typescript' 'npm' 'pnpm' 'python')
optdepends=(
  'mosquitto: MQTT broker')
source=(
  'zigbee2mqtt::git+https://github.com/Koenkk/zigbee2mqtt.git#branch=dev'
  'zigbee2mqtt.service'
  'zigbee2mqtt.sysusers'
  'zigbee2mqtt.tmpfiles')
backup=('etc/zigbee2mqtt/configuration.yaml')
options=('!strip' '!emptydirs')

pkgver() {
  cd "${_pkgname}"
  git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "${_pkgname}"
  # Allow updating the lockfile to match the installed pnpm version
  pnpm i --no-frozen-lockfile
}

build() {
  cd "${_pkgname}"
  pnpm run build
}

package() {
  cd "${_pkgname}"
  # Remove devDependencies to reduce package size
  pnpm prune --prod

  install -m0755 -d "${pkgdir}/usr/share/webapps/${_pkgname}"
  cp -a node_modules dist "${pkgdir}/usr/share/webapps/${_pkgname}"

  install -m0644 cli.js -t "${pkgdir}/usr/share/webapps/${_pkgname}"
  install -m0644 index.js -t "${pkgdir}/usr/share/webapps/${_pkgname}"
  install -m0644 package.json -t "${pkgdir}/usr/share/webapps/${_pkgname}"

  install -Dm644 data/configuration.example.yaml "${pkgdir}/etc/${_pkgname}/configuration.yaml"

  install -Dm644 "${srcdir}/${_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"

  # Universal cleanup (dev files, other OS)
  local prune_dirs=(
    -name '.github'
    -o -name '.idea'
    -o -name '.tscache'
    -o -wholename '*/man'
    -o -wholename '*/test'
    -o -wholename '*/scripts'
    -o -wholename '*/git-hooks'
    -o -wholename '*/android-*'
    -o -wholename '*/win32-*'
    -o -wholename '*/darwin-*'
  )

  # Architecture specific cleanup
  case "$CARCH" in
    x86_64)
      prune_dirs+=( -o -wholename '*/linux-arm*' )
      ;;
    aarch64)
      prune_dirs+=( -o -wholename '*/linux-x64' -o -wholename '*/linux-arm' )
      ;;
    arm*)
      prune_dirs+=( -o -wholename '*/linux-x64' -o -wholename '*/linux-arm64' )
      ;;
  esac

  find "${pkgdir}/usr/share/webapps/${_pkgname}/node_modules" -type d \( "${prune_dirs[@]}" \) -exec rm -rvf {} +
}

sha256sums=('SKIP'
            '02dbaab1711521e3b4004dbf24084e736ae4c2eae97f5c5553c85b05fa807525'
            '8a0e9967ad95ee2464b08cf6e985c6b358272214fceb8fdee2eeaaf92e48d32a'
            '8f0fbe06c8d6e8fdf37feb31f244930025d76785451f9049fd90fe6e23c259f6')