Skip to content

Commit

Permalink
added debian packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
tirolerstefan committed Aug 29, 2021
1 parent bd43255 commit dd3bca9
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 4 deletions.
17 changes: 17 additions & 0 deletions dpkg/build_pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

cd content

# copy files to debian package structure
cp -v ../../kaifareader.py usr/lib/kaifareader/
cp -v ../../meter_template.json etc/kaifareader/
cp -v ../../systemd/kaifareader.service lib/systemd/system/

dpkg-buildpackage -uc -us

if [ $? -ne 0 ]; then
echo "Error creating debian package"
exit 1
fi

cd ..
5 changes: 5 additions & 0 deletions dpkg/content/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kaifareader (0.1) unstable; urgency=medium

* Initial release.

-- <16918854+tirolerstefan@users.noreply.github.com> Sun, 29 Aug 2021 09:01:26 +0200
1 change: 1 addition & 0 deletions dpkg/content/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13
10 changes: 10 additions & 0 deletions dpkg/content/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source: kaifareader
Priority: optional
Maintainer: Stefan Felkel <16918854+tirolerstefan@users.noreply.github.com>
Standards-Version: 4.5.1
Homepage: https://github.com/tirolerstefan/kaifa

Package: kaifareader
Architecture: all
Depends: ${misc:Depends}, ${shlibs:Depends}, python3, python3-serial, python3-pycryptodome
Description: Read out Kaifa M309 using serial connection.
5 changes: 5 additions & 0 deletions dpkg/content/debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
etc/kaifareader/meter_template.json
lib/systemd/system/kaifareader.service
usr/lib/kaifareader/kaifareader.py


66 changes: 66 additions & 0 deletions dpkg/content/debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh

set -e

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
configure)
# Adapt permissions of working directory
mkdir -p /var/run/kaifareader
chmod 777 /var/run/kaifareader

mkdir -p /var/log/kaifareader
chmod 777 /var/log/kaifareader
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# Automatically added by dh_installsystemd/12.1.1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask 'kaifareader.service' >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled 'kaifareader.service'; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable 'kaifareader.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state 'kaifareader.service' >/dev/null || true
fi
fi
# End automatically added section

# Automatically added by dh_installsystemd/12.1.1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action 'kaifareader.service' >/dev/null || true
fi
fi
# End automatically added section
24 changes: 24 additions & 0 deletions dpkg/content/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -e

# Automatically added by dh_installsystemd/12.1.1
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section

# Automatically added by dh_installsystemd/12.1.1
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask 'kaifareader.service' >/dev/null || true
fi
fi

if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge 'kaifareader.service' >/dev/null || true
deb-systemd-helper unmask 'kaifareader.service' >/dev/null || true
fi
fi
# End automatically added section
7 changes: 7 additions & 0 deletions dpkg/content/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

%:
dh $@
1 change: 1 addition & 0 deletions dpkg/content/debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
2 changes: 1 addition & 1 deletion kaifareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def log_error(self, s):


class Constants:
config_file = "meter.json"
config_file = "/etc/kaifareader/meter.json"
frame1_start_bytes = b'\x68\xfa\xfa\x68' # 68 FA FA 68
frame2_start_bytes = b'\x68\x72\x72\x68' # 68 72 72 68
export_format_solarview = "SOLARVIEW"
Expand Down
5 changes: 2 additions & 3 deletions meter_template.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"loglevel": "logging.DEBUG",
"logfile": "/var/log/kaifa.log",
"logfile": "/var/log/kaifareader/kaifa.log",
"port": "/dev/ttyUSB0",
"baudrate": 2400,
"parity": "serial.PARITY_NONE",
"stopbits": "serial.STOPBITS_ONE",
"bytesize": "serial.EIGHTBITS",
"key_hex_string": "",
"interval": 15,
"key_hex_string": "",
"export_format": "SOLARVIEW",
"export_file_abspath": "/tmp/export.txt"
"export_file_abspath": "/var/run/kaifareader/kaifa.txt"
}
10 changes: 10 additions & 0 deletions systemd/kaifareader.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=kaifareader
After=syslog.target network.target ntp.service

[Service]
ExecStart=/usr/bin/python3 /usr/lib/kaifareader/kaifareader.py
StandardOutput=null

[Install]
WantedBy=multi-user.target

0 comments on commit dd3bca9

Please sign in to comment.