name: mosquitto
version: 2.1.0
summary: Eclipse Mosquitto MQTT broker
description: This is a message broker that supports version 5.0, 3.1.1, and 3.1 of the MQTT
    protocol.
    MQTT provides a method of carrying out messaging using a publish/subscribe
    model. It is lightweight, both in terms of bandwidth usage and ease of
    implementation. This makes it particularly useful at the edge of the network
    where a sensor or other simple device may be implemented using an arduino for
    example.
confinement: strict
grade: stable
base: core20

apps:
  mosquitto:
    command: launcher.sh
    daemon: simple
    restart-condition: always
    plugs: [home, network, network-bind]

  ctrl:
    command: usr/bin/mosquitto_ctrl
    plugs: [home, network]

  pub:
    command: usr/bin/mosquitto_pub
    plugs: [home, network]

  rr:
    command: usr/bin/mosquitto_rr
    plugs: [home, network]

  sub:
    command: usr/bin/mosquitto_sub
    plugs: [home, network]

  passwd:
    command: usr/bin/mosquitto_passwd
    plugs: [home]


parts:
  script:
    plugin: dump
    source: snap/local/
    prime:
      - default_config.conf
      - launcher.sh
  config:
    plugin: dump
    source: .
    prime:
      - mosquitto.conf


  mosquitto:
    after:
      - lws
    plugin: make
    make-parameters:
      - prefix=/usr
      - WITH_WEBSOCKETS=lws
      - WITH_ADNS=yes
      - CFLAGS="-Wall -ggdb -O2 -I$SNAPCRAFT_STAGE/usr/include -D_GNU_SOURCE"
    source: https://github.com/eclipse/mosquitto
    source-type: git

    build-packages:
      - libssl-dev
      - xsltproc
      - docbook-xsl
      - gcc
      - g++
    stage-packages:
      - libssl1.1
      - ca-certificates
    prime:
      - usr/sbin/mosquitto
      - usr/bin/mosquitto_ctrl
      - usr/bin/mosquitto_pub
      - usr/bin/mosquitto_rr
      - usr/bin/mosquitto_sub
      - usr/bin/mosquitto_passwd
      - usr/lib/libmosquitto.so*
      - usr/lib/mosquitto_dynamic_security.so*
      - lib/*-linux-gnu/libcrypto.so*
      - lib/*-linux-gnu/libssl.so*
      - usr/include/mosquitto.h
      - usr/include/mosquitto_broker.h
      - usr/include/mosquitto_plugin.h
      - usr/include/mqtt_protocol.h
      - usr/include/mosquitto/*.h

  lws:
    after:
      - cjson
    plugin: cmake
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DLWS_IPV6=ON
      - -DLWS_WITHOUT_CLIENT=ON
      - -DLWS_WITHOUT_EXTENSIONS=ON
      - -DLWS_WITH_ZIP_FOPS=OFF
      - -DLWS_WITH_ZLIB=OFF
      - -DLWS_WITH_SHARED=OFF
    source: https://github.com/warmcat/libwebsockets/archive/v2.4.2.tar.gz
    source-type: tar
    stage:
      - usr/include/libwebsockets.h
      - usr/include/lws_config.h
      - usr/lib/libwebsockets.a
    prime: [-*]

  cjson:
    plugin: cmake
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_C_FLAGS=-fPIC
      - -DBUILD_SHARED_AND_STATIC_LIBS=OFF
      - -DBUILD_SHARED_LIBS=OFF
      - -DCJSON_BUILD_SHARED_LIBS=OFF
      - -DCJSON_OVERRIDE_BUILD_SHARED_LIBS=OFF
      - -DENABLE_CJSON_TEST=OFF
    source: https://github.com/DaveGamble/cJSON/archive/v1.7.14.tar.gz
    source-type: tar
    stage:
      - usr/include/cjson/cJSON.h
      - usr/lib/libcjson.a
    prime: [-*]
