Skip to content

Commit

Permalink
updating debian packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed Jul 31, 2024
1 parent 644f189 commit ea27b26
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 87 deletions.
39 changes: 11 additions & 28 deletions .github/workflows/debian.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Debian package
name: Build Debian Package

on:
push:
Expand All @@ -10,41 +10,24 @@ env:

jobs:
build-artifact:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@master

- name: Install packaging dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y \
python3 python3-dev python3-pip python3-venv python3-all \
dh-python debhelper devscripts dput software-properties-common \
python3-distutils python3-setuptools python3-wheel python3-stdeb \
python3-all
- name: Install Debian Package Building Dependencies
run: sudo bash debian/install_pkg_build_deps.sh

- name: Build Debian/Apt sdist_dsc
run: |
python3 -m pip install .
rm -Rf deb_dist/*
python3 setup.py --command-packages=stdeb.command sdist_dsc
- name: Create Debian Package
run: make clean package

- name: Build Debian/Apt bdist_deb
run: |
python3 -m pip install .
export REPO_NAME=$(echo ${{ github.repository }} | awk -F"/" '{print $2}')
python3 setup.py --command-packages=stdeb.command bdist_deb
ls -al deb_dist/
cp deb_dist/python3-${REPO_NAME}_*_all.deb deb_dist/python3-${REPO_NAME}_latest_all.deb
- uses: actions/upload-artifact@master
- name: Upload Artifacts to GitHub
uses: actions/upload-artifact@master
with:
name: artifact-deb
path: |
deb_dist/*.deb
path: deb_dist/*.deb

- name: Create Release
- name: Create GitHub Release
id: create_release
uses: actions/create-release@master
env:
Expand All @@ -55,7 +38,7 @@ jobs:
draft: false
prerelease: false

- name: Upload Release Asset
- name: Upload Release Asset to GitHub
id: upload-release-asset
uses: svenstaro/upload-release-action@v2
with:
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/python-publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,21 @@ on:
jobs:
deploy:

runs-on: ubuntu-22.04
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools wheel twine
- name: Build
run: |
python3 setup.py sdist bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/python-test_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ on:
jobs:
build:

runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11", "3.12"]
# python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ __pycache__
known_craft.csv
.mypy_cache/
.pytest_cache/config.ini
config.ini
53 changes: 39 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Makefile from https://github.com/snstac/pytak
# PyTAK Makefile
#
# Copyright Sensors & Signals LLC https://www.snstac.com
# Copyright Sensors & Signals LLC https://www.snstac.com/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,10 +14,14 @@
# limitations under the License.
#

this_app = dronecot
.DEFAULT_GOAL := all
REPO_NAME ?= $(shell echo $(wildcard */__init__.py) | awk -F'/' '{print $$1}')
SHELL := /bin/bash
.DEFAULT_GOAL := editable
# postinst = $(wildcard debian/*.postinst.sh)
# service = $(wildcard debian/*.service)

all: editable
prepare:
mkdir -p build/

develop:
python3 setup.py develop
Expand All @@ -26,13 +30,13 @@ editable:
python3 -m pip install -e .

install_test_requirements:
python3 -m pip install -r requirements_test.txt
python3 -m pip install -r requirements_test.txt

install:
python3 setup.py install

uninstall:
python3 -m pip uninstall -y $(this_app)
python3 -m pip uninstall -y $(REPO_NAME)

reinstall: uninstall install

Expand All @@ -43,16 +47,16 @@ clean:
@rm -rf *.egg* build dist *.py[oc] */*.py[co] cover doctest_pypi.cfg \
nosetests.xml pylint.log output.xml flake8.log tests.log \
test-result.xml htmlcov fab.log .coverage __pycache__ \
*/__pycache__
*/__pycache__ deb_dist .mypy_cache

pep8:
flake8 --max-line-length=88 --extend-ignore=E203 --exit-zero $(this_app)/*.py
flake8 --max-line-length=88 --extend-ignore=E203 --exit-zero $(REPO_NAME)/*.py

flake8: pep8

lint:
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
--max-line-length=88 -r n $(this_app)/*.py || exit 0
--max-line-length=88 -r n $(REPO_NAME)/*.py || exit 0

pylint: lint

Expand All @@ -68,11 +72,32 @@ pytest:
test: editable install_test_requirements pytest

test_cov:
pytest --cov=$(this_app) --cov-report term-missing
pytest --cov=$(REPO_NAME) --cov-report term-missing

black:
black .

mkdocs:
pip install -r docs/requirements.txt
mkdocs serve
mkdocs serve

deb_dist:
python3 setup.py --command-packages=stdeb.command sdist_dsc

deb_custom:
cp debian/$(REPO_NAME).conf $(wildcard deb_dist/*/debian)/$(REPO_NAME).default
cp debian/$(REPO_NAME).postinst $(wildcard deb_dist/*/debian)/$(REPO_NAME).postinst
cp debian/$(REPO_NAME).service $(wildcard deb_dist/*/debian)/$(REPO_NAME).service

bdist_deb: deb_dist deb_custom
cd deb_dist/$(REPO_NAME)-*/ && dpkg-buildpackage -rfakeroot -uc -us

faux_latest:
cp deb_dist/$(REPO_NAME)_*-1_all.deb deb_dist/$(REPO_NAME)_latest_all.deb
cp deb_dist/$(REPO_NAME)_*-1_all.deb deb_dist/python3-$(REPO_NAME)_latest_all.deb

package: bdist_deb faux_latest

extract:
dpkg-deb -e $(wildcard deb_dist/*latest_all.deb) deb_dist/extract
dpkg-deb -x $(wildcard deb_dist/*latest_all.deb) deb_dist/extract
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ DroneCOT captures & reports real-time data received from drones into TAK product

DroneCOT has been evaluated with WinTAK, iTAK, ATAK & TAK Server.

DroneCOT is in active use today in a variety of missions.

`Documentation is available here. <https://dronecot.rtfd.io>`_

License
Expand Down
72 changes: 72 additions & 0 deletions debian/dronecot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# dronecot.conf from https://github.com/snstac/dronecot
#
# Debian specific runtime configuration for dronecot.
#
# Copyright Sensors & Signals LLC https://www.snstac.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# DroneCOT Configuration: https://dronecot.rtfd.io/
# Change values here, and restart with: sudo systemctl restart dronecot

# Enable or Disable the dronecot software daemon.
# ENABLED=1

# URL to CoT destination. Must be a URL, e.g. tcp://1.2.3.4:1234 or tls://...:1234, etc.
# COT_URL=udp+wo://239.2.3.1:6969

# CoT Stale period ("timeout"), in seconds.
# COT_STALE=3600

# Override COT Event Type ("marker type").
# COT_TYPE=a-u-S-X-M



# PyTAK Configuration: https://pytak.rtfd.io/
# Change values here, and restart with: sudo systemctl restart aiscot

# Sets TAK Protocol to use for CoT output.
# TAK_PROTO=0

# Sets debug-level logging. Any value other than 0 is considered True. False if unset.
# DEBUG=

# TAK Data Packages containing TAK Server connection settings, TLS certificates, etc.
# PREF_PACKAGE=

# Path to a file containing the unencrypted plain-text PEM format Client Certificate.
# This file can contain both the Client Cert & Client Key, or the Client Cert alone.
# In the later case (cert alone), PYTAK_TLS_CLIENT_KEY must be set to the Client Key.
# PYTAK_TLS_CLIENT_CERT=

# Path to a file containing the unencrypted plain-text PEM format Client Private Key
# for the associated PYTAK_TLS_CLIENT_CERT.
# PYTAK_TLS_CLIENT_KEY=

# Password for password protected certificates or password protected Private Keys.
# PYTAK_TLS_CLIENT_PASSWORD=

# Disable destination TLS Certificate Verification.
# PYTAK_TLS_DONT_VERIFY=

# Disable destination TLS Certificate Common Name (CN) Verification.
# PYTAK_TLS_DONT_CHECK_HOSTNAME=

# File containing the CA Trust Store to use for remote certificate verification.
# PYTAK_TLS_CLIENT_CAFILE=

# Expected hostname or CN of the connected server. Not used unless verifying hostname.
# PYTAK_TLS_SERVER_EXPECTED_HOSTNAME=

81 changes: 81 additions & 0 deletions debian/dronecot.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
# dronecot.postinst from https://github.com/snstac/dronecot
#
# Copyright Sensors & Signals LLC https://www.snstac.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

echo "dronecot Post Install"

# shellcheck source=dronecot.conf
[ -f "/etc/default/dronecot" ] && . /etc/default/dronecot

# Sane defaults:
[ -z "$SERVER_HOME" ] && SERVER_HOME=/run/dronecot
[ -z "$SERVER_USER" ] && SERVER_USER=dronecot
[ -z "$SERVER_NAME" ] && SERVER_NAME="Remote ID to TAK Gateway System User"
[ -z "$SERVER_GROUP" ] && SERVER_GROUP=dronecot

# Groups that the user will be added to, if undefined, then none.
ADDGROUP=""

# create user to avoid running server as root
# 1. create group if not existing
if ! getent group | grep -q "^$SERVER_GROUP:" ; then
echo -n "Adding group $SERVER_GROUP.."
addgroup --quiet --system "$SERVER_GROUP" 2>/dev/null ||true
echo "..done"
fi
# 2. create homedir if not existing
test -d "$SERVER_HOME" || mkdir "$SERVER_HOME"
# 3. create user if not existing
if ! getent passwd | grep -q "^$SERVER_USER:"; then
echo -n "Adding system user $SERVER_USER.."
adduser --quiet \
--system \
--ingroup "$SERVER_GROUP" \
--no-create-home \
--disabled-password \
"$SERVER_USER" 2>/dev/null || true
echo "..done"
fi
# 4. adjust passwd entry
usermod -c "$SERVER_NAME" \
-d "$SERVER_HOME" \
-g "$SERVER_GROUP" \
"$SERVER_USER"
# 5. adjust file and directory permissions
if ! dpkg-statoverride --list "$SERVER_HOME" >/dev/null
then
chown -R "$SERVER_USER":adm "$SERVER_HOME"
chmod u=rwx,g=rxs,o= "$SERVER_HOME"
fi
# 6. Add the user to the ADDGROUP group
if test -n "$ADDGROUP"
then
if ! groups "$SERVER_USER" | cut -d: -f2 | \
grep -qw "$ADDGROUP"; then
adduser "$SERVER_USER" "$ADDGROUP"
fi
fi

systemctl enable dronecot.service

echo "---- dronecot Install Complete ----"
echo "Documentation: https://dronecot.rtfd.io/"
echo "Configure: sudo nano /etc/default/dronecot"
echo "Start: sudo systemctl start dronecot.service"
echo "Logs: sudo journalctl -fu dronecot"

exit 0
Loading

0 comments on commit ea27b26

Please sign in to comment.