diff --git a/.github/workflows/deb-packaging.yml b/.github/workflows/deb-packaging.yml new file mode 100644 index 0000000..36aa7ee --- /dev/null +++ b/.github/workflows/deb-packaging.yml @@ -0,0 +1,62 @@ +# This is a basic workflow to help you get started with Actions + +name: Deb Packaging + +# Controls when the action will run. +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Parse version + run: echo VERSION=$(grep '' Source/MQTTnet.Server/MQTTnet.Server.csproj | grep [0-9\.]* -o) >> $GITHUB_ENV + + - name: Build MQTTnetServer + run: dotnet publish Source/MQTTnet.Server/MQTTnet.Server.csproj --configuration Release --self-contained --runtime linux-x64 --framework net5.0 + + - name: Set up installation directory + run: mkdir -p packaging/opt/MQTTnetServer + + - name: Copy meta data + run: | + cp -R Build/deb-meta/* packaging/ + chmod 755 packaging/DEBIAN/postinst + chmod 755 packaging/DEBIAN/postrm + chmod 755 packaging/DEBIAN/prerm + + - name: Move artifacts to packaging directory + run: cp -R Source/MQTTnet.Server/bin/Release/net5.0/linux-x64/publish/* packaging/opt/MQTTnetServer + + - name: Adjust files + run: | + rm packaging/opt/MQTTnetServer/appsettings.Development.json + mv packaging/opt/MQTTnetServer/appsettings.json packaging/opt/MQTTnetServer/appsettings.template.json + + - name: Adjust permissions + run: | + cd packaging/opt/MQTTnetServer + find . -type f | xargs chmod -R 644 + chmod 755 MQTTnet.Server + + - name: Generate MD5s + run: | + cd packaging/ + md5sum $(find * -type f -not -path 'DEBIAN/*') > DEBIAN/md5sums + + - name: Patch meta + run: sed -i 's/\VERSIONPLACEHOLDER/${{ env.VERSION }}/' packaging/DEBIAN/control + + - name: Package everything + run: dpkg-deb -v --build packaging/ mqttnet-server_${{ env.VERSION }}-1_amd64.deb + + - name: Save artifact + uses: actions/upload-artifact@v2 + with: + name: mqttnet-server + path: mqttnet-server_${{ env.VERSION }}-1_amd64.deb diff --git a/Build/deb-meta/DEBIAN/control b/Build/deb-meta/DEBIAN/control new file mode 100644 index 0000000..242444c --- /dev/null +++ b/Build/deb-meta/DEBIAN/control @@ -0,0 +1,10 @@ +Package: mqttnet-server +Version: VERSIONPLACEHOLDER +Section: base +Priority: optional +Architecture: amd64 +Depends: libssl1.1 +Suggests: +Maintainer: Damian Wolgast +Description: + MQTTnet Server is a standalone cross platform MQTT server (like mosquitto) basing on this library. diff --git a/Build/deb-meta/DEBIAN/copyright b/Build/deb-meta/DEBIAN/copyright new file mode 100644 index 0000000..decf080 --- /dev/null +++ b/Build/deb-meta/DEBIAN/copyright @@ -0,0 +1,26 @@ +The source of MQTTnet is at: +https://github.com/chkr1011/MQTTnet +Project is maintained by Christian Kratky + + +MIT License + +Copyright (c) 2021 Damian Wolgast + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Build/deb-meta/DEBIAN/postinst b/Build/deb-meta/DEBIAN/postinst new file mode 100644 index 0000000..9a90e94 --- /dev/null +++ b/Build/deb-meta/DEBIAN/postinst @@ -0,0 +1,44 @@ +#!/bin/bash + +# Check if user exits +USER=mqttnetsrv +USEREXISTS=$(id -u $USER >/dev/null 2>&1; echo $?) +EC=0 +BASEPATH=/opt +INSTALLPATH=$BASEPATH/MQTTnetServer + +# If user does not exist, create it +if (( $USEREXISTS == 1 )); then + useradd -d $INSTALLPATH -r $USER + EC=$(echo $?) + + if (( $EC == 1 )); then + exit 1; + fi +fi + +# Set permissions on files +chown -R root:root $INSTALLPATH + +# Check if config does not exist and create it +if [ ! -f "$INSTALLPATH/appsettings.json" ]; then + cp $INSTALLPATH/appsettings.template.json $INSTALLPATH/appsettings.json +fi + + +# Check if setcap exists, does not exist in docker containers +SCAP=$(which setcap >/dev/null; echo $?) +if [ "$SCAP" -eq "0" ]; then + # Enable MQTTServer.NET to bind to IP interface + setcap CAP_NET_BIND_SERVICE=+eip $INSTALLPATH/MQTTnet.Server +fi + +chmod 644 /etc/systemd/system/mqttnet-server.service + +# Check if systemctl exists, does not exist in docker containers +SCTL=$(which systemctl >/dev/null; echo $?) + +if [ "$SCTL" -eq "0" ]; then + # Reload systemd because of new service file + systemctl daemon-reload +fi \ No newline at end of file diff --git a/Build/deb-meta/DEBIAN/postrm b/Build/deb-meta/DEBIAN/postrm new file mode 100644 index 0000000..9db22d4 --- /dev/null +++ b/Build/deb-meta/DEBIAN/postrm @@ -0,0 +1,8 @@ +#!/bin/bash + +# Check if systemctl exists, does not exist in docker containers +SCTL=$(which systemctl >/dev/null; echo $?) +if [ "$SCTL" -eq "0" ]; then + # Reload systemd because of new service file + systemctl daemon-reload +fi \ No newline at end of file diff --git a/Build/deb-meta/DEBIAN/prerm b/Build/deb-meta/DEBIAN/prerm new file mode 100644 index 0000000..ae23bca --- /dev/null +++ b/Build/deb-meta/DEBIAN/prerm @@ -0,0 +1,18 @@ +#!/bin/bash + +BASEPATH=/opt +INSTALLPATH=$BASEPATH/MQTTnetServer + +# Check if systemctl exists, does not exist in docker containers +SCTL=$(which systemctl >/dev/null; echo $?) +if [ "$SCTL" -eq "0" ]; then + # Stop service before uninstalling + systemctl stop mqttnet-server +fi + +# Check if setcap exists, does not exist in docker containers +SCAP=$(which setcap >/dev/null; echo $?) +if [ "$SCAP" -eq "0" ]; then + # Remove permission to open ports + setcap CAP_NET_BIND_SERVICE=-eip $INSTALLPATH/MQTTnet.Server +fi \ No newline at end of file diff --git a/Build/deb-meta/etc/systemd/system/mqttnet-server.service b/Build/deb-meta/etc/systemd/system/mqttnet-server.service new file mode 100644 index 0000000..4181624 --- /dev/null +++ b/Build/deb-meta/etc/systemd/system/mqttnet-server.service @@ -0,0 +1,14 @@ +[Unit] +Description=MQTTnetServer +After=network.target + +[Service] +ExecStart=/opt/MQTTnetServer/MQTTnet.Server +WorkingDirectory=/opt/MQTTnetServer +StandardOutput=inherit +StandardError=inherit +Restart=always +User=mqttnetsrv + +[Install] +WantedBy=multi-user.target \ No newline at end of file