pub / pp-notifier

Instant Messenger Notification daemon for the PinePhone
git clone https://src.jayvii.de/pub/pp-notifier.git
Home | Log | Files | Exports | Refs | README | RSS

commit 57eeafe6b4f7a3a0c93eb4e4778ca26aac1d9f08
parent 4b6654468466d131a9aa80a5ca5202add01ae672
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu, 16 Sep 2021 15:30:47 +0200

Packaging for Debian

Diffstat:
A.gitignore | 6++++++
A.gitlab-ci.yml | 35+++++++++++++++++++++++++++++++++++
DMakefile | 9---------
Aconfig.sample | 8++++++++
Adebian/changelog | 6++++++
Adebian/control | 15+++++++++++++++
Adebian/copyright | 27+++++++++++++++++++++++++++
Adebian/install | 2++
Adebian/rules | 15+++++++++++++++
Adebian/salsa-cli.yml | 4++++
Adebian/source/format | 1+
Aim-notifier | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mim-notifier.desktop | 5+++--
Dim-notifier.sh | 125-------------------------------------------------------------------------------
14 files changed, 245 insertions(+), 136 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +debian/.debhelper +debian/debhelper-build-stamp +debian/im-notifier +debian/im-notifier.substvars +debian/files + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml @@ -0,0 +1,35 @@ + +variables: + DEBIAN_FRONTEND: noninteractive + # Common dependencies on all jobs + DEPS_DEV: "" + # Build dependencies for the .deb + DEPS_DEB: "build-essential debhelper devscripts" + +.before_script_template: &basic-deps + before_script: + - rm -f /etc/apt/apt.conf.d/docker-clean + # Don't build manual database on installation + - | + debconf-set-selections << EOF + man-db man-db/auto-update boolean false + EOF + - apt-get -qq update + #- apt-get -qq install -y --no-install-recommends ${DEPS_DEV} -o=Dpkg::Use-Pty=0 > /dev/null + + +debian: + stage: build + only: + - master + image: debian:bullseye + <<: *basic-deps + + script: + - apt-get -qq install -y --no-install-recommends -o=Dpkg::Use-Pty=0 ${DEPS_DEB} > /dev/null + - dpkg-buildpackage -us -uc -b + - mv ../im-notifier*.deb . + + artifacts: + name: 'DEB packages' + paths: ['im-notifier*.deb'] diff --git a/Makefile b/Makefile @@ -1,9 +0,0 @@ -install: - mkdir -p ${HOME}/.local/bin - mkdir -p ${HOME}/.config/autostart - install -m 700 ./im-notifier.sh ${HOME}/.local/bin/ - install -m 755 ./im-notifier.desktop ${HOME}/.config/autostart/ - -uninstall: - ${RM} ${HOME}/.local/bin/im-notifier.sh - ${RM} ${HOME}/.config/autostart/im-notifier.desktop diff --git a/config.sample b/config.sample @@ -0,0 +1,8 @@ +# Common Configurations +POLLTIME=30 +TIMEOUT=25 + +# Telegram Configurations +TELEGRAM=0 +TG_ICON="document-send" +TG_ACTION="telegram-desktop" Home | diff --git a/debian/changelog b/debian/changelog @@ -0,0 +1,6 @@ +im-notifier (0.0.1) unstable; urgency=medium + + * Initial release. + * Debian Packaging + + -- Jan "JayVii" <jayvii[AT]posteo[DOT]de> Thu, 16 Sep 2021 15:17:00 +0100 diff --git a/debian/control b/debian/control @@ -0,0 +1,15 @@ +Source: im-notifier +Section: net +Priority: optional +Maintainer: Jan "JayVii" <jayvii[AT]posteo[DOT]de> +Build-Depends: debhelper (>=13), debhelper-compat (= 13) +Standards-Version: 4.6.0 +Rules-Requires-Root: no +Homepage: https://src.jayvii.de/PinePhone/Notifier + +Package: im-notifier +Architecture: all +Depends: ${misc:Depends}, libglib2.0-bin, dbus +Recommends: telegram-cli +Description: Checks your current IM messages via several CLI clients for + different plattform and notifies you about potential messages. diff --git a/debian/copyright b/debian/copyright @@ -0,0 +1,27 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: Notifier +Upstream-Contact: Jan "JayVii" <jayvii[AT]posteo[DOT]de> +Source: https://src.jayvii.de/PinePhone/Notifier + +Files: * +Copyright: 2021 JayVii <jayvii[AT]posteo[DOT]de> +License: GPL-3+ + +License: GPL-3+ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + . + On Debian systems, the full text of the GNU General Public + License version 3 can be found in the file + '/usr/share/common-licenses/GPL-3'. diff --git a/debian/install b/debian/install @@ -0,0 +1,2 @@ +im-notifier usr/bin +im-notifier.desktop usr/share/applications diff --git a/debian/rules b/debian/rules @@ -0,0 +1,15 @@ +#!/usr/bin/make -f +# output every command that modifies files on the build system. +DH_VERBOSE = 1 + +%: + dh $@ + + +#override_dh_installdocs: +# Do not install a copyright file for the wrapper +# indeed, no /usr/share/docs/wl-screenshot is needed! +#dh_installdocs --exclude=debian/copyright + +# Do not install changelogs for space conservation +#override_dh_installchangelogs: diff --git a/debian/salsa-cli.yml b/debian/salsa-cli.yml @@ -0,0 +1,4 @@ +--- +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml diff --git a/debian/source/format b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/im-notifier b/im-notifier @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2021 JayVii +# SPDX-License-Identifier: GPL-3.0-or-later + +# Settings -------------------------------------------------------------------- + +# Load Config file if present +if [[ -f "$HOME/.config/im-notifier/config" ]]; then + source "$HOME/.config/im-notifier/config" +fi + +# Set timings +if [[ -z $POLLTIME ]]; then + POLLTIME=30 +fi +if [[ -z $TIMEOUT ]]; then + TIMEOUT=25 +fi + +# Telegram Settings +if [[ -z $TELEGRAM ]] && [[ -z $(command -v telegram-cli) ]]; then + TELEGRAM=1 + echo "Enabling Telegram!" +fi +if [[ -z $TG_ICON ]]; then + TG_ICON="document-send" +fi +if [[ -z $TG_ACTION ]]; then + TG_ACTION="telegram-desktop" +fi +TG_NOTIFICATION_ID=0 + +# Modules --------------------------------------------------------------------- + +## Common +function im_notify { + gdbus call --session \ + --dest=org.freedesktop.Notifications \ + --object-path=/org/freedesktop/Notifications \ + --method=org.freedesktop.Notifications.Notify \ + "$1" $2 "$3" "$1" "$4" "$5" \ + '{"category": <"im.received">}' 3000 +} +function im_unnotify { + gdbus call --session \ + --dest=org.freedesktop.Notifications \ + --object-path=/org/freedesktop/Notifications \ + --method=org.freedesktop.Notifications.CloseNotification \ + $1 +} +function im_signal_listen { + while :; do + INVOKEDACTION=$(dbus-monitor \ + "type='signal',sender='org.freedesktop.Notifications',interface='org.freedesktop.Notifications'" | \ + head -7 | grep -E "im-notify-*") + if [[ "$INVOKEDACTION" == " string \"im-notify-tg\"" ]]; then + exec "${TG_ACTION}" + fi + sleep 5 # actions probably do not happen more often than that + done +} + +## Telegram +function tg_check { + telegram-cli --disable-colors \ + --exec dialog_list | \ + grep -E "[1-9][0-9]* unread" +} +function tg_kill { + sleep $1 + if [[ ! -z $(pidof telegram-cli) ]]; then + pkill telegram-cli + fi +} +function tg_notify { + im_notify "Telegram" $2 "$TG_ICON" "$1" "['im-notify-tg', 'Open Message']" +} + +# Run Daemon ------------------------------------------------------------------ + +# Notify user about running state of the daemon +INITMSG="Enabled Services:" +if [[ $TELEGRAM != 0 ]]; then + INITMSG="$INITMSG Telegram" +fi +im_notify "IM-Notifier" 0 "gnome-settings" "$INITMSG" "[]" + +# Run Signal Listener (executes actions) +im_signal_listen & + +# Run daemon in endless while-loop +while :; do + + # Telegram + if [[ $TELEGRAM != 0 ]]; then + + # kill after some time + tg_kill $TIMEOUT & + + # Check Telegram Messages + TG_UNREAD=$(tg_check) + + if [[ ! -z "$TG_UNREAD" ]]; then + # Notify Telegram Messages + TG_NOTIFICATION_ID=$(tg_notify \ + "$TG_UNREAD" $TG_NOTIFICATION_ID | \ + sed -e 's/^.*\s//' -e 's/[^0-9]//g') + elif [[ $TG_NOTIFICATION_ID != 0 ]]; then + # Close Notification + im_unnotify $TG_NOTIFICATION_ID + TG_NOTIFICATION_ID=0 + fi + fi + + # Sleep until next round... + sleep $POLLTIME + +done + +# Notify user about running state of the daemon +im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier stopped..." "[]" + +# EOF im-notifier.sh diff --git a/im-notifier.desktop b/im-notifier.desktop @@ -1,6 +1,7 @@ [Desktop Entry] -Name=Instant Message Notifier -Exec=sh -c ${HOME}/.local/bin/im-notifier.sh +Name=IM-Notifier +GenericName=Instant Message Notifier +Exec=/usr/bin/im-notifier Terminal=false Categories=Network Type=Application diff --git a/im-notifier.sh b/im-notifier.sh @@ -1,125 +0,0 @@ -#!/usr/bin/env bash - -# Set timings -if [[ -z $POLLTIME ]]; then - POLLTIME=30 -fi -if [[ -z $TIMEOUT ]]; then - TIMEOUT=25 -fi - -# Telegram Settings -if [[ -z $TELEGRAM ]] && [[ -z $(command -v telegram-cli) ]]; then - TELEGRAM=1 - echo "Enabling Telegram!" -fi -if [[ -z $TG_ICON ]]; then - TG_ICON="document-send" -fi -if [[ -z $TG_ACTION ]]; then - TG_ACTION="telegram-desktop" -fi -TG_NOTIFICATION_ID=0 - -# Modules --------------------------------------------------------------------- - -## Common -function im_notify { - if [[ $(printf "$XDG_CURRENT_DESKTOP" | grep -i "gnome") != "" ]]; then - gdbus call --session \ - --dest=org.freedesktop.Notifications \ - --object-path=/org/freedesktop/Notifications \ - --method=org.freedesktop.Notifications.Notify \ - "$1" $2 "$3" "$1" "$4" "$5" \ - '{"category": <"im.received">}' 3000 - else - # unfortunately, this does not replace old messages - notify-send --app-name="$3" --icon="$3" --category="im.received" \ - "$1" "$4" - echo 0 - fi -} -function im_unnotify { - if [[ $(printf "$XDG_CURRENT_DESKTOP" | grep -i "gnome") != "" ]]; then - gdbus call --session \ - --dest=org.freedesktop.Notifications \ - --object-path=/org/freedesktop/Notifications \ - --method=org.freedesktop.Notifications.CloseNotification \ - $1 - else - echo 0 - fi -} -function im_signal_listen { - while :; do - INVOKEDACTION=$(dbus-monitor "type='signal',sender='org.freedesktop.Notifications',interface='org.freedesktop.Notifications'" | \ - head -7 | \ - grep -E "im-notify-*") - if [[ "$INVOKEDACTION" == " string \"im-notify-tg\"" ]]; then - exec "${TG_ACTION}" - fi - sleep 5 # actions probably do not happen more often than that - done -} - -## Telegram -function tg_check { - telegram-cli --disable-colors \ - --exec dialog_list | \ - grep -E "[1-9][0-9]* unread" -} -function tg_kill { - sleep $1 - if [[ ! -z $(pidof telegram-cli) ]]; then - pkill telegram-cli - fi -} -function tg_notify { - im_notify "Telegram" $2 "$TG_ICON" "$1" "['im-notify-tg', 'Open Message']" -} - -# Run Daemon ------------------------------------------------------------------ - -# Notify user about running state of the daemon -INITMSG="Enabled Services:" -if [[ $TELEGRAM != 0 ]]; then - INITMSG="$INITMSG Telegram" -fi -im_notify "IM-Notifier" 0 "gnome-settings" "$INITMSG" "[]" - -# Run Signal Listener -im_signal_listen & - -# Run daemon in endless while-loop -while :; do - - # Telegram - if [[ $TELEGRAM != 0 ]]; then - - # kill after some time - tg_kill $TIMEOUT & - - # Check Telegram Messages - TG_UNREAD=$(tg_check) - - if [[ ! -z "$TG_UNREAD" ]]; then - # Notify Telegram Messages - TG_NOTIFICATION_ID=$(tg_notify \ - "$TG_UNREAD" $TG_NOTIFICATION_ID | \ - sed -e 's/^.*\s//' -e 's/[^0-9]//g') - elif [[ $TG_NOTIFICATION_ID != 0 ]]; then - # Close Notification - im_unnotify $TG_NOTIFICATION_ID - TG_NOTIFICATION_ID=0 - fi - fi - - # Sleep until next round... - sleep $POLLTIME - -done - -# Notify user about running state of the daemon -im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier stopped..." "[]" - -# EOF im-notifier.sh