From c8d539691cbeded1c4ee1389afa6625485cc9c44 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 13 Mar 2024 19:54:28 +0000 Subject: Apt updates indicator --- i3/check-updates.py | 35 +++++++++++++++++++++++++++++++++++ i3/i3status.conf | 5 +++++ 2 files changed, 40 insertions(+) create mode 100755 i3/check-updates.py (limited to 'i3') diff --git a/i3/check-updates.py b/i3/check-updates.py new file mode 100755 index 0000000..2e25c4b --- /dev/null +++ b/i3/check-updates.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# add a crontab entry with crontab -e: +# 0 */2 * * * $HOME/.config/nvim/i3/check-updates.py +# +# create /etc/apt/apt.conf.d/10periodic with: +# APT::Periodic::Enable "1"; +# APT::Periodic::Update-Package-Lists "1"; +# APT::Periodic::AutocleanInterval "7"; +# APT::Periodic::Verbose "1"; +# + + +import subprocess +import pathlib +import os + +CMD = ["apt", "list", "--upgradeable"] + + +def check_updates(): + output = str(subprocess.check_output(CMD, stderr=subprocess.DEVNULL)) + output = output.splitlines() + return len(output[1:-1]) + + +if __name__ == "__main__": + pending = check_updates() + if pending == 0: + result = "" + else: + result = f"{pending} updates" + + with open(os.path.join(pathlib.Path.home(), ".pending_updates"), "wt") as fd: + fd.write(result) diff --git a/i3/i3status.conf b/i3/i3status.conf index 349924d..2cb2a16 100644 --- a/i3/i3status.conf +++ b/i3/i3status.conf @@ -15,6 +15,7 @@ order += "cpu_usage" order += "cpu_temperature 0" order += "memory" order += "disk /" +order += "read_file updates" order += "volume master" order += "tztime local" @@ -49,3 +50,7 @@ volume master { mixer = "Master" mixer_idx = 0 } + +read_file updates { + path = "/home/reidrac/.pending_updates" +} -- cgit v1.2.3