diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..df27ee1 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +ifeq ($(PREFIX),) + PREFIX := /usr +endif + +install: + # systemd file + install -d $(DESTDIR)$(PREFIX)/lib/systemd/user/ + install gotify-dunst.service $(DESTDIR)$(PREFIX)/lib/systemd/user/ + + # files in /usr/lib + install -d $(DESTDIR)$(PREFIX)/lib/gotify-dunst/ + install main.py $(DESTDIR)$(PREFIX)/lib/gotify-dunst/ + install gotify-dunst.conf $(DESTDIR)$(PREFIX)/lib/gotify-dunst/ \ No newline at end of file diff --git a/README.md b/README.md index 2026fcc..2140558 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@

gotify-dunst

## Intro + This is a simple script for receiving [Gotify](https://github.com/gotify/server) messages on a Linux Desktop via [dunst](https://dunst-project.org/). ## Features @@ -12,14 +13,27 @@ This is a simple script for receiving [Gotify](https://github.com/gotify/server) ## Installation -1. Clone this repo -git clone https://github.com/ztpnk/gotify-dunst && cd gotify-dunst -2. Create a python venv `python3 -m venv .env` -3. Install python requirements -./.env/bin/pip install -r requirements.txt -4. Change the domain and token in main.py -5. Test if it runs -./.env/bin/python main.py -6. Customize the gotify-dunst.service and copy it to /etc/systemd/system -7. Start and enable the Systemd Unit -sudo systemd start gotify-dunst && sudo systemd enable gotify-dunst +### Debian (Ubuntu, Mint, etc.) + +```bash +sudo apt install git make libnotify-bin python3-websocket +git clone https://github.com/ztpnk/gotify-dunst +cd gotify-dunst +sudo make install +``` + +### Arch (Manjaro) + +```bash +sudo pacman -Syu make git libnotify python-websocket-client +git clone https://github.com/ztpnk/gotify-dunst +cd gotify-dunst +sudo make install +``` + +## Usage + +1. Run `systemctl --user enable --now gotify-dunst.service` (**no sudo**) +2. Open `~/.config/gotify-dunst/gotify-dunst.conf` in your favorite text editor. Modify the domain to your instance of Gotify and modify the token to a client token you get from the Gotify web app. +3. Run `systemctl --user restart gotify-dunst.service`. +4. (optionally) You can check the status of the service with `systemctl --user status gotify-dunst.service`. diff --git a/gotify-dunst.conf b/gotify-dunst.conf new file mode 100644 index 0000000..c9e1373 --- /dev/null +++ b/gotify-dunst.conf @@ -0,0 +1,3 @@ +[server] +domain=push.example.com +token=C2Un.92TZBzsukg diff --git a/gotify-dunst.service b/gotify-dunst.service index 058bbd6..ab511c6 100644 --- a/gotify-dunst.service +++ b/gotify-dunst.service @@ -3,10 +3,9 @@ Description=Gotify-Dunst After=network.target [Service] -User= -WorkingDirectory=/gotify-dunst/ -ExecStart=/gotify-dunst/.env/bin/python main.py +WorkingDirectory=/usr/lib/gotify-dunst/ +ExecStart=/usr/bin/env python3 main.py Restart=always [Install] -WantedBy=multi-user.target +WantedBy=default.target diff --git a/main.py b/main.py index ae71b0e..5ae793f 100644 --- a/main.py +++ b/main.py @@ -3,11 +3,31 @@ from urllib.request import urlopen import json import subprocess import os.path +import configparser + -domain = "push.example.com" -token = "z2Uny92TZBzsukg" home = os.path.expanduser('~') +configpath = home+'/.config/gotify-dunst/gotify-dunst.conf' + +if not os.path.isfile(configpath): + from shutil import copyfile + from os import makedirs + makedirs(home+'/.config/gotify-dunst/',exist_ok=True) + copyfile('gotify-dunst.conf',configpath) + +config = configparser.ConfigParser() +config.read(configpath) + +domain = config.get('server','domain',fallback=None) + +if domain in [ "push.example.com", None]: + print("Confiuration error. Make sure you have properly modified the configuration") + exit() + +token = config.get('server','token') + + path = "{}/.cache/gotify-dunst".format(home) if not os.path.isdir(path): os.mkdir(path)