Skip to content

Commit

Permalink
Build .deb package
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoBCD committed Jan 27, 2025
1 parent 90b9afd commit 6bffffc
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ jobs:
# with:
# name: test-results
# path: pytest-report.xml
#
- name: Build deb
run: |
make
39 changes: 2 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
# Byte-compiled files
*.pyc
*.pyo
*.pyd
__pycache__/

# Virtual environment
/venv/
/.env/

# Distribution files
/build/
/dist/
/*.egg-info/

# System-specific files (can appear anywhere)
.DS_Store
Thumbs.db

# IDE and editor files
/.vscode/
/.idea/
*.swp
*.swo

# Test artifacts (can appear anywhere)
*.coverage
htmlcov/
.tox/
.nox/
.pytest_cache/
.cache/
.mypy_cache/
.pyre/
dmypy.json

# Uploaded files (specific to this project)
*.deb
/uploads/
/build/
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
default: build-deb

.PHONY: run
run: pypltagent-eth.py
python3 ./pypltagent-eth.py


# See the rootless-builds.txt in dpkg-dev.
.PHONY: build-deb
build-deb:
mkdir -p build/pypltagent/usr/bin
cp pypltagent-eth.py build/pypltagent/usr/bin/pypltagent-eth
chmod +x build/pypltagent/usr/bin/pypltagent-eth

mkdir -p build/pypltagent/DEBIAN
cp debian/control build/pypltagent/DEBIAN/
cp debian/postinst build/pypltagent/DEBIAN/
cp debian/prerm build/pypltagent/DEBIAN/

mkdir -p build/pypltagent/lib/systemd/system
cp debian/pypltagent.service build/pypltagent/lib/systemd/system/
dpkg-deb --build --root-owner-group build/pypltagent
mv build/pypltagent.deb pypltagent.noarch.deb
rm -rf build

.PHONY: stub
stub:
9 changes: 9 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: pypltagent
Version: 1.0
Section: utils
Priority: optional
Architecture: all
Maintainer: Blue Clover <support@bcdevices.com>
Depends: python3, systemd
Description: A Python script for PLT agent
This script helps manage PLT agent operations via ethernet.his script helps manage PLT agent operations via ethernet.
20 changes: 20 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

# Ensure the 'pltagent' user exists
if ! id -u pltagent > /dev/null 2>&1; then
useradd -r -s /usr/sbin/nologin -G plugdev pltagent
echo "User 'pltagent' created and added to 'plugdev' group."
fi

mkdir -p /var/run/pltagent/uploads
chown -R pltagent:plugdev /var/run/pltagent/uploads

# Reload systemd to recognize the new service
systemctl daemon-reload

# Enable and start the service
systemctl enable pypltagent.service
systemctl start pypltagent.service

echo "pypltagent service installed and started."
8 changes: 8 additions & 0 deletions debian/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

# Stop and disable the service
systemctl stop pypltagent.service || true
systemctl disable pypltagent.service || true

echo "pypltagent service stopped and disabled."
17 changes: 17 additions & 0 deletions debian/pypltagent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=PLT Agent Ethernet Service
After=network.target

[Service]
ExecStart=/usr/bin/pypltagent-eth
Restart=always
User=pltagent
Group=plugdev
Environment=PYTHONUNBUFFERED=1
#WorkingDirectory=/usr/bin
WorkingDirectory=/var/run/pltagent
ExecStartPre=/bin/mkdir -p /var/run/pltagent/uploads
ExecStartPre=/bin/chown -R pltagent:plugdev /var/run/pltagent/uploads

[Install]
WantedBy=multi-user.target

0 comments on commit 6bffffc

Please sign in to comment.