name: landscape-client
base: core22
version: '23.08'
icon: snap/gui/landscape-logo-256.png
website: https://ubuntu.com/landscape
summary: Client for the Canonical systems management product Landscape
description: |
  Landcape is a web-based tool for managing Ubuntu systems. This snap, or the
  equivalent debian package is necessary if you want your machine to be managed
  in a Landscape account. It provides the Landscape client and requires a
  Landscape account.

grade: devel # must be 'stable' to release into candidate/stable channels
architectures:
  - build-on: [amd64]
  - build-on: [arm64]
  - build-on: [armhf]
  - build-on: [ppc64el]
  - build-on: [s390x]
confinement: strict

apps:
  landscape-client:
    daemon: simple
    install-mode: disable
    command: usr/bin/landscape-client
    plugs:
      - hardware-observe
      - mount-observe
      - network
      - network-bind
      - network-observe
      - scsi-generic
      - shutdown
      - snapd-control
      - system-observe
    environment:
      LANDSCAPE_CLIENT_SNAP: 1
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
  config:
    command: usr/bin/landscape-config
    plugs: [network]
    environment:
      LANDSCAPE_CLIENT_SNAP: 1
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

layout:
  /etc/landscape-client.conf:
    bind-file: $SNAP_COMMON/etc/landscape-client.conf
  /var/lib/landscape/client:
    bind: $SNAP_DATA/var/lib/landscape/client
  /var/log/landscape:
    bind: $SNAP_DATA/var/log/landscape

package-repositories:
  - type: apt
    ppa: landscape/self-hosted-beta

parts:
  landscape-client:
    plugin: dump
    source: .
    source-type: local  # Don't use 'git' - it forces you to commit your changes
    build-packages:
      - debhelper
      - devscripts
      - dh-python
      - gawk
      - libdistro-info-perl
      - lsb-release
      - net-tools
      - po-debconf
      - python3-apt
      - python3-configobj
      - python3-dev
      - python3-distutils-extra
      - python3-twisted
    override-build: |
      git commit -n -a -m "dev build for snap" --no-gpg-sign --allow-empty
      cat << EOF > debian/changelog
      landscape-client (0.0.1) UNRELEASED; urgency=medium

        * Test build for snap

       -- Guy Incognito <guy.incognito@landscape.client>  Fri, 1 Sep 2023 00:00:00 +0000
      EOF
      mkdir -p landscape-client-0.0.1
      git ls-files --recurse-submodules | xargs -I {} cp -r --parents {} landscape-client-0.0.1/
      rm -rf landscape-client-0.0.1/debian
      tar -czf landscape-client-0.0.1.tar.gz landscape-client-0.0.1
      cp -r debian landscape-client-0.0.1
      cd landscape-client-0.0.1 && debuild -b --no-sign
      cp ../landscape-*_0.0.1_*.deb $CRAFT_PART_INSTALL
    stage-packages:
      - adduser
      - bc
      - ca-certificates
      - debconf
      - libpam-modules
      - lsb-base
      - lsb-release
      - lshw
      - python3
      - python3-apt
      - python3-configobj
      - python3-gdbm
      - python3-netifaces
      - python3-pycurl
      - python3-twisted
      - python3-dbus
      - ubuntu-advantage-tools
    override-prime: |
      craftctl default
      rm $CRAFT_PRIME/landscape-*_0.0.1_*.deb
      dpkg-deb -x $CRAFT_STAGE/landscape-common_0.0.1_*.deb $CRAFT_PRIME
      dpkg-deb -x $CRAFT_STAGE/landscape-client_0.0.1_*.deb $CRAFT_PRIME
