# Maintainer: AgenticWorkspace <soporte@agenticworkspace.app>
#
# Repackages the official tar.gz served by versions.agenticworkspace.app; the AUR only holds this
# file. scripts/release/aur.sh (Agentic Workspace's repository) sets pkgver, pkgrel and the
# checksums of every release and publishes it.

pkgname=agentic-workspace-bin
_pkgname=agentic-workspace
pkgver=1.2.39
pkgrel=1
pkgdesc='Projects, tasks and AI agents in a local workspace'
arch=('x86_64')
url='https://versions.agenticworkspace.app'
license=('LicenseRef-AgenticWorkspace')
depends=('gtk3' 'nss' 'alsa-lib' 'libdrm' 'mesa' 'libsecret' 'xdg-utils')
optdepends=('libnotify: desktop notifications'
            'docker: agent accounts in containers'
            'git: branch and changes of the projects')
provides=("$_pkgname")
conflicts=("$_pkgname")
# strip breaks the Electron and Codex binaries; they ship without debug symbols.
options=('!strip' '!debug')
source=("$url/linux/$_pkgname-$pkgver-linux-x64.tar.gz"
        "$_pkgname.desktop")
sha256sums=('f448c70357ff9bfe4de4805d01f09f9e232344500043d9309c1eac6e88b5f6a3'
            'b367dd29a91317540f540068689c3c38ab73163e555dd352e80f0396108074ea')

package() {
  # /opt/AgenticWorkspace, as the .deb: the manual tar.gz installation that docs/DISTRIBUCION.md
  # describes uses the link /opt/agentic-workspace, and pacman would refuse to overwrite it.
  local app="$pkgdir/opt/AgenticWorkspace"
  install -d "$app"
  cp -a "$srcdir/$_pkgname-$pkgver-linux-x64/." "$app/"
  # Electron's sandbox helper, as in the .deb on systems without user namespaces.
  chmod 4755 "$app/chrome-sandbox"
  # Tells the updater that pacman manages this installation; the tar.gz does not carry it.
  printf pacman > "$app/resources/package-type"

  install -d "$pkgdir/usr/bin"
  ln -s "/opt/AgenticWorkspace/$_pkgname" "$pkgdir/usr/bin/$_pkgname"
  install -Dm644 "$app/resources/icon.png" "$pkgdir/usr/share/icons/hicolor/512x512/apps/$_pkgname.png"
  install -Dm644 "$srcdir/$_pkgname.desktop" "$pkgdir/usr/share/applications/$_pkgname.desktop"
  # The license and the third-party notices travel inside the tar.gz, matching its version.
  install -Dm644 "$app/resources/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
  install -Dm644 "$app/resources/THIRD_PARTY_NOTICES.txt" \
    "$pkgdir/usr/share/licenses/$pkgname/THIRD_PARTY_NOTICES.txt"
}
