From 80567d7b4a624331bd333a678b653d4cb8ac3a02 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 3 Aug 2022 20:43:22 +0200 Subject: initial commit --- .gitignore | 3 +++ Makefile | 59 ++++++++++++++++++++++++++++++++++++++++++++ colocation-client.conf | 27 ++++++++++++++++++++ colocation-client.in | 21 ++++++++++++++++ colocation-client.service.in | 7 ++++++ colocation-client.timer.in | 10 ++++++++ 6 files changed, 127 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 colocation-client.conf create mode 100644 colocation-client.in create mode 100644 colocation-client.service.in create mode 100644 colocation-client.timer.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89b3ddf --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +colocation-client +colocation-client.service +colocation-client.timer diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a1864ef --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +# +# colocation-client - simple skripts for updating the status of colocation clients +# +# Copyright (c) 2022 Erich Eckner +# +# 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +SHELL = /bin/bash +DESTDIR = +ETCDIR = /etc +BINDIR = /usr/bin +LIBDIR = /usr/lib + +VERSION = 0.0 + +all: colocation-client colocation-client.service colocation-client.timer + +%: %.in + sed " \ + s/#VERSION#/$(VERSION)/; \ + s@#BINDIR#@$(BINDIR)@; \ + s@#ETCDIR#@$(ETCDIR)@; \ + s@#HELPTEXT#\(\s\+\)#@ --help \1display this help and exit\n --version\1display version and exit@; \ + " $< > $@ && \ + ( [[ "$@" = *.* ]] || chmod +x "$@" ) + +.PHONY: install dist clean + +install: all + install -D -m0755 -t $(DESTDIR)$(BINDIR) colocation-client + install -D -m0644 -t $(DESTDIR)$(LIBDIR)/systemd/system colocation-client.service colocation-client.timer + install -D -m0644 -t $(DESTDIR)$(ETCDIR) colocation-client.conf + +clean: + git clean -x -d -f + +dist: clean + git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true + ! git tag -d v$(VERSION) 2> /dev/null + git tag v$(VERSION) + knock-knock || true + git push + git push --tags + +# End of file diff --git a/colocation-client.conf b/colocation-client.conf new file mode 100644 index 0000000..fb80d37 --- /dev/null +++ b/colocation-client.conf @@ -0,0 +1,27 @@ +{ + "colocation_server": "https://colocation.eckner.net/", + "machines": + [ + { + "machine": "fenster-lo", + "key": "decaf", + "values": { + "running": { + } + } + }, + { + "machine": "fenster", + "key": "deadbeef", + "values": { + "power": { + "command": "lights-out get power", + "result": "stdout" + }, + "ping": { + "command": "ping -c1 fenster" + } + } + } + ] +} diff --git a/colocation-client.in b/colocation-client.in new file mode 100644 index 0000000..dfb1662 --- /dev/null +++ b/colocation-client.in @@ -0,0 +1,21 @@ +#!/bin/bash + +configuration_file="${1:-#ETC#/colocation-client.conf}" + +jq '{ + colocation_server, + machine: .machines[] +} | { + url: ( + .colocation_server + + "update.php" + + ( + "?machine=" + + .machine.machine + + "&key=" + + .machine.key + ) + ), + values: .machine.values, +}' \ +<"${configuration_file}" diff --git a/colocation-client.service.in b/colocation-client.service.in new file mode 100644 index 0000000..2ab0650 --- /dev/null +++ b/colocation-client.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=update colocation status +After=lights-out-init.service + +[Service] +Type=oneshot +ExecStart=#BINDIR#/colocation-client diff --git a/colocation-client.timer.in b/colocation-client.timer.in new file mode 100644 index 0000000..5fec6b0 --- /dev/null +++ b/colocation-client.timer.in @@ -0,0 +1,10 @@ +[Unit] +Description=update colocation status every few minutes + +[Timer] +OnCalendar=*:00/10:00 +RandomizedDelaySec=600 +FixedRandomDelay=True + +[Install] +WantedBy=timers.target -- cgit v1.2.3-54-g00ecf