summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanp72022-11-12 21:32:57 +0300
committerivanp72022-11-18 15:50:10 +0300
commit52d8d1286ed0fa97d9151ba91790abf180ac27de (patch)
treefd2053d02e09098f481c3d1792f83d73b3b85932
downloadaur-usage-logging.tar.gz
initial commit
-rw-r--r--.SRCINFO12
-rw-r--r--.gitignore5
-rw-r--r--PKGBUILD22
-rwxr-xr-xanother-minute.sh20
-rw-r--r--usage-logging.install14
5 files changed, 73 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..eb5687c2ea13
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,12 @@
+pkgbase = usage-logging
+ pkgdesc = Create daily log files with hour x minute rectangle diagram of device on/off status
+ pkgver = 1
+ pkgrel = 1
+ install = usage-logging.install
+ arch = any
+ license = Unlicense
+ depends = cron
+ source = another-minute.sh
+ md5sums = 7a365ee024107614b65e2317c018977c
+
+pkgname = usage-logging
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..f361e857c070
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+src/
+pkg/
+*.pkg.tar.zst
+*.pkg.tar.zst.sig
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..a4d87b274e31
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,22 @@
+# Maintainer : Ivan Podmazov <ivanpzv [eight] at gmail com>
+
+pkgname=usage-logging
+pkgdesc="Create daily log files with hour x minute rectangle diagram of device on/off status"
+
+pkgver=1
+pkgrel=1
+
+arch=('any')
+license=('Unlicense')
+depends=(cron)
+
+source=('another-minute.sh')
+md5sums=('7a365ee024107614b65e2317c018977c')
+
+install=usage-logging.install
+
+package ()
+{
+ install -Dm 744 another-minute.sh "$pkgdir/usr/bin/usage-logging/another-minute.sh"
+}
+
diff --git a/another-minute.sh b/another-minute.sh
new file mode 100755
index 000000000000..bc7068e8b0be
--- /dev/null
+++ b/another-minute.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+DATE_TIME="$(date +'%F.%u %_H:%M')"
+DATE="${DATE_TIME%% *}"
+TIME="${DATE_TIME##* }"
+HOUR="${TIME%%:*}"
+MINUTE="${TIME##*:}"
+
+LINE="$(($HOUR + 1))"
+
+LOGDIR="/var/log/usage"
+LOGFILE="$LOGDIR/$DATE"
+
+[ -d "$LOGDIR" ] || mkdir -p -- "$LOGDIR"
+
+[ -f "$LOGFILE" ] ||
+ dd if=/dev/zero bs=1 count=$((24*60)) 2> /dev/null | tr '\0' '.' | fold -w 60 > "$LOGFILE"
+
+sed -i -E "${LINE}s/^(.{$MINUTE})./\1#/" "$LOGFILE"
+
diff --git a/usage-logging.install b/usage-logging.install
new file mode 100644
index 000000000000..658c93ddd696
--- /dev/null
+++ b/usage-logging.install
@@ -0,0 +1,14 @@
+CRON_TASK="* * * * * /usr/bin/usage-logging/another-minute.sh"
+
+post_install ()
+{
+ echo "Adding cron task..."
+ crontab -l | { cat; echo "$CRON_TASK"; } | crontab -
+}
+
+pre_remove ()
+{
+ echo "Removing cron task..."
+ crontab -l | grep -Fxv "$CRON_TASK" | crontab -
+}
+