summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-08-03 20:43:22 +0200
committerErich Eckner <git@eckner.net>2022-08-03 20:43:22 +0200
commit80567d7b4a624331bd333a678b653d4cb8ac3a02 (patch)
treedd2e743325df1795c3c1a417928c45aaa3620fe2
downloadcolocation-client-80567d7b4a624331bd333a678b653d4cb8ac3a02.tar.xz
initial commit
-rw-r--r--.gitignore3
-rw-r--r--Makefile59
-rw-r--r--colocation-client.conf27
-rw-r--r--colocation-client.in21
-rw-r--r--colocation-client.service.in7
-rw-r--r--colocation-client.timer.in10
6 files changed, 127 insertions, 0 deletions
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 <opensource at eckner dot net>
+#
+# 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