From a42e9adffc06665b38655a8a3dc4bf50e09a0961 Mon Sep 17 00:00:00 2001 From: hermanntoast Date: Wed, 25 May 2022 15:35:46 +0200 Subject: [PATCH] Many nice changes * Add workflows for automate building * add deb package builder * move sample script * add daemon handler --- .github/workflows/release.yml | 70 +++++++++++ buildpackage.sh | 4 + debian/changelog | 5 + debian/compat | 1 + debian/control | 12 ++ debian/postinst | 23 ++++ debian/rules | 112 ++++++++++++++++++ usr/bin/tripoli | 58 +++++++++ .../share/tripoli/samples}/sampleScript.sh | 0 tripoli.py => usr/share/tripoli/tripoli.py | 14 ++- 10 files changed, 293 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 buildpackage.sh create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/postinst create mode 100755 debian/rules create mode 100755 usr/bin/tripoli rename {samples => usr/share/tripoli/samples}/sampleScript.sh (100%) rename tripoli.py => usr/share/tripoli/tripoli.py (87%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e8e59a1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + + workflow_dispatch: + +name: Build Release + +jobs: + deb-package: + name: build DEB-Package + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install dependencies + run: sudo apt update && sudo apt install debhelper -y + + - name: Build + run: ./buildpackage.sh + + - name: Copy artifacts + run: mkdir archives && cp ../*.* ./archives + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: deb-package + path: archives/* + + github-release: + needs: deb-package + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + name: GitHub Release + runs-on: ubuntu-20.04 + steps: + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: deb-package + + - name: Extract current changes + run: cat *.changes | sed '0,/^Changes:$/d' | sed '/Checksums.*/Q' | sed '1,2d' | tail >> ./current-changes + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + body_path: ./current-changes + + - name: Delete current changes file + run: rm ./current-changes + + - name: Upload Release Assets + id: upload-release-assets + uses: dwenegar/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} + assets_path: . \ No newline at end of file diff --git a/buildpackage.sh b/buildpackage.sh new file mode 100755 index 0000000..b055e1e --- /dev/null +++ b/buildpackage.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# build the debian package +dpkg-buildpackage -rfakeroot -tc -sa -us -uc -I".directory" -I".git" -I"buildpackage.sh" \ No newline at end of file diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..4c78836 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +tripoli (0.0.1~rc1) bullseye; urgency=medium + + * First release for version 0.0.1 + + -- hermanntoast Tue, 24 May 2022 18:12:46 +0200 \ No newline at end of file diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..ca39356 --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: tripoli +Section: admin +Priority: optional +Maintainer: hermanntoast +Build-Depends: debhelper (>= 4.0.0), fakeroot + +Package: tripoli +Architecture: all +Depends: python3 +Homepage: hermann-toast.de +Recommends: +Description: Create XFCE Shell extentions \ No newline at end of file diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000..5830d74 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +case "$1" in + install|configure) + echo "Creating directories und copy samples..." + mkdir -p ~/.config/tripoli/ + mkdir -p ~/.config/tripoli/log/ + cp -f /usr/share/tripoli/samples/sampleScript.sh ~/.config/tripoli/ + echo "Creating startup script for all users..." + echo "#!/bin/sh" > /etc/profile.d/tripoli.sh + echo "python3 /usr/share/tripoli/tripoli.py 2>&1 > /dev/null &" >> /etc/profile.d/tripoli.sh + chmod +x /etc/profile.d/tripoli.sh + ;; + upgrade|abort-upgrade) + ;; + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 0 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1c4c4e8 --- /dev/null +++ b/debian/rules @@ -0,0 +1,112 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 by Joey Hess. +# +# This version is for a hypothetical package that builds an +# architecture-dependant package, as well as an architecture-independent +# package. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This is the debhelper compatibility version to use. +export DH_COMPAT=5 + +#ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) +# CFLAGS += -g +#endif +#ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) +# INSTALL_PROGRAM += -s +#endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build-arch: configure-stamp build-arch-stamp +build-arch-stamp: + dh_testdir + + # Add here command to compile/build the package. + #$(MAKE) + + touch build-arch-stamp + +build-indep: configure-stamp build-indep-stamp +build-indep-stamp: + dh_testdir + + # Add here command to compile/build the arch indep package. + # It's ok not to do anything here, if you don't need to build + # anything for this package. + + touch build-indep-stamp + +build: build-arch build-indep + +clean: clean1 +clean1: + dh_testdir + dh_testroot + rm -f build-indep-stamp build-arch-stamp configure-stamp + + # Add here commands to clean up after the build process. + #-$(MAKE) clean + + dh_clean + + +install: DH_OPTIONS= +install: build + dh_testdir + dh_testroot + dh_prep + dh_installdirs + + # Add here commands to install the package. + dh_install + # fixing default not being installed + mkdir -p debian/tripoli + rsync -avr --exclude='.installed' usr debian/tripoli + + +# Build architecture-independent files here. +# Pass -i to all debhelper commands in this target to reduce clutter. +binary-indep: build install + dh_testdir + dh_testroot + dh_installdirs + dh_installdebconf + dh_installdocs +# dh_installexamples -i +# dh_installmenu -i + dh_installlogrotate -i +# dh_installemacsen -i +# dh_installpam -i +# dh_installmime -i + dh_installinit -i + dh_installcron -i +# dh_installman -i +# dh_installinfo -i +# dh_undocumented -i + dh_installchangelogs + dh_link + dh_compress + dh_fixperms + dh_installdeb +# dh_perl -i + dh_gencontrol + dh_md5sums + dh_builddeb + +# Build architecture-dependent files here. +binary-arch: install +# We have nothing to do by default. + + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure clean1 \ No newline at end of file diff --git a/usr/bin/tripoli b/usr/bin/tripoli new file mode 100755 index 0000000..70f003e --- /dev/null +++ b/usr/bin/tripoli @@ -0,0 +1,58 @@ +#!/bin/bash + +function start() { + if isRunning; then + echo "Tripoli is already running!" + else + echo -n "Starting tripoli... " + python3 /usr/share/tripoli/tripoli.py 2>&1 > /dev/null & + echo "[OK]" + fi +} + +function stop() { + if isRunning; then + echo -n "Stopping tripoli... " + ps -aux | grep python | grep tripoli | awk '{print $2}' | xargs kill + echo "[OK]" + else + echo "Tripoli is not running!" + fi +} + +function isRunning() { + if [ $(ps -aux | grep python | grep tripoli | wc -l) -gt 0 ]; then + return 0 + else + return 1 + fi +} + +function getPID() { + return $(ps -aux | grep python | grep tripoli | awk '{print $2}') +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + sleep 2 + start + ;; + status) + if isRunning; then + getPID + echo "Tripoli is running with pid $?" + else + echo "Tripoli is not running!" + fi + ;; + *) + echo "Option not known! Use start, stop, restart or status!" + ;; +esac \ No newline at end of file diff --git a/samples/sampleScript.sh b/usr/share/tripoli/samples/sampleScript.sh similarity index 100% rename from samples/sampleScript.sh rename to usr/share/tripoli/samples/sampleScript.sh diff --git a/tripoli.py b/usr/share/tripoli/tripoli.py similarity index 87% rename from tripoli.py rename to usr/share/tripoli/tripoli.py index 73fc285..52d16f2 100755 --- a/tripoli.py +++ b/usr/share/tripoli/tripoli.py @@ -11,9 +11,10 @@ from gi.repository import Gtk as gtk, AppIndicator3 as appindicator, GLib -logging.basicConfig(format='%(levelname)s: %(asctime)s %(message)s', level=logging.CRITICAL) +scriptPath = os.path.expanduser("~") + "/.config/tripoli/" +logPath = os.path.expanduser("~") + "/.config/tripoli/log/" -scriptPath = "~/.config/tripoli/" +logging.basicConfig(filename=logPath + 'tripoli.log', format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) def __execute(command) -> list: commandline = "" @@ -91,11 +92,12 @@ def main(): if __name__ == "__main__": try: - print("Start application...") + logging.info("Starting application...") main() except KeyboardInterrupt: - print() exit() except Exception as e: - print(e) - pass \ No newline at end of file + logging.critical(e) + pass + finally: + logging.info("Stopping application...") \ No newline at end of file