Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ install: all
cp hooks/* "$(DESTDIR)/etc/needrestart/hook.d/"
cp ex/needrestart.conf "$(DESTDIR)/etc/needrestart/"
cp ex/notify.conf "$(DESTDIR)/etc/needrestart/"
cp ex/matrix.conf "$(DESTDIR)/etc/needrestart/"
chmod 0600 "$(DESTDIR)/etc/needrestart/matrix.conf"
cp ex/iucode.sh "$(DESTDIR)/etc/needrestart/"
mkdir -p "$(DESTDIR)/etc/needrestart/conf.d"
cp ex/conf.d/* "$(DESTDIR)/etc/needrestart/conf.d/"
Expand Down
11 changes: 11 additions & 0 deletions ex/matrix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

export MATRIX_SERVER="https://matrix.org/"

# The room ID where the message should be posted (not the room alias).
# https://matrix.org/docs/older/client-server-api/#creating-a-room
export MATRIX_ROOM_ID=""

# Authentication Token from the account that posts the messages.
# https://matrix.org/docs/older/client-server-api/#registration
# Therefore, this file should be kept secret! chmod 0600 matrix.conf
export MATRIX_TOKEN=""
3 changes: 3 additions & 0 deletions ex/notify.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# Disable mail to user (notify.d/600-mail)
NR_NOTIFYD_DISABLE_MAIL='1'

# Disable matrix messages (notify.d/800-matrix)
NR_NOTIFYD_DISABLE_MATRIX='1'


# Where to find the shell function library from gettext-base
#GETTEXTLIB='/usr/bin/gettext.sh'
62 changes: 62 additions & 0 deletions ex/notify.d/800-matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

# needrestart - Restart daemons after library updates.
#
# Authors:
# Hans-Christoph Steiner <hans@eds.org>
#
# Copyright Holder:
# 2026 (C) Hans-Christoph Steiner <hans@eds.org>
#
# License:
# 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.
#

# Use /usr/bin/curl to post a message to a Matrix room

CURL=/usr/bin/curl
test -x "$CURL" || exit 1

. /usr/lib/needrestart/notify.d.sh

if [ "$NR_NOTIFYD_DISABLE_MATRIX" = '1' ]; then
echo "[$0] disabled in global config" 1>&2
exit 1
fi

MATRIXCONF="$(dirname "$NOTIFYCONF")/matrix.conf"

perms=$(stat --format=%a "$MATRIXCONF")
if [ "$perms" -ne "600" ]; then
echo "[$0] $MATRIXCONF has unsafe permissions $perms - aborting!" 1>&2
exit 1;
fi

if [ ! -r "$MATRIXCONF" ]; then
echo "[$0] Unable to read $MATRIXCONF - aborting!" 1>&2
exit 1;
fi

. "$MATRIXCONF"

echo "[$0] notify Matrix room $MATRIX_ROOM_ID on $MATRIX_SERVER" 1>&2

body=$({
_NR_FQDN=$(hostname -f)
eval_gettext 'Your session on host $_NR_FQDN ($NR_SESSION) is running obsolete binaries or libraries as listed below.'
echo
echo
gettext "Please consider a relogin or restart of the affected processes!"
echo
echo
cat
})

$CURL \
--header "Authorization: Bearer $MATRIX_TOKEN" \
--header "Content-Type: application/json" \
--json "{\"msgtype\": \"m.text\", \"body\": \"$(echo $body)\"}" \
"${MATRIX_SERVER}_matrix/client/r0/rooms/${MATRIX_ROOM_ID}/send/m.room.message"