Best way for monitoring and alerting of running Bluefin version

Okay … After a lot of googling, duckduckgoing and also some chatgpting I think I have something that works. I also took inspiration from ublue-motd. The issue mentioned above talks about user-motd.sh, which I couldn’t find.

Maybe somebody can take a look at the script and give me feedback? That would be great! I’ll attach it below.

BTW: I specifically didn’t customize ublue-motd as I thought it was something very different after all. What do you think?

But what now?

But now I don’t know how to proceed, as I’m a rooky sysadmin coming from more traditional distros like Debian and only slowly venturing into the atomic distros.

How do I get my script to work on Bluefin? Normally I would create a systemd timer and a unit file. But on a read-only file system… :exploding_head:

Can somebody help me with that?

#!/usr/bin/bash

bluenotify() {
	
	local NOTIFY_TITLE=""
	local NOTIFY_BODY=""
	local NOTIFY_ICON=""
	local NOTIFY_ACTION=""

	case $1 in
		update)
			NOTIFY_TITLE="Update Now"
			NOTIFY_BODY="Your latest available image is over 1 month old. Please update now."
			NOTIFY_ICON="software-update-urgent"
			NOTIFY_ACTION='UPDATE=Update Now'
			;;
		reboot)
			NOTIFY_TITLE="Reboot Now"
			NOTIFY_BODY="There is a newer image available. Just reboot to use it."
			NOTIFY_ICON="system-reboot"
			NOTIFY_ACTION='REBOOT=Reboot Now'
			;;
	esac

    local ACTION=$(notify-send \
		--icon="$NOTIFY_ICON" \
		--urgency=critical \
		--action="$NOTIFY_ACTION" \
		--action=INFO="More Info" \
		"$NOTIFY_TITLE" "$NOTIFY_BODY")
    
	case $ACTION in
		UPDATE)
			xdg-terminal-exec -- bash -c 'ujust update'
			;;
		REBOOT)
			xdg-terminal-exec -- bash -c 'systemctl reboot'
			;;
		INFO)
			xdg-terminal-exec -- bash -c 'rpm-ostree status --booted'
			;;
	esac
}

AVAILABLE_IMAGE_DATE=$(rpm-ostree status --booted | sed -n 's/.*Timestamp: \(.*\)/\1/p')
AVAILABLE_IMAGE_DATE_SECONDS=$(date -d "$AVAILABLE_IMAGE_DATE" +%s)
BOOTED_IMAGE_DATE=$(rpm-ostree status --booted | sed -n 's/.*Version:.*(\(.*\))/\1/p')
BOOTED_IMAGE_DATE_SECONDS=$(date -d "$BOOTED_IMAGE_DATE" +%s)
CURRENT_SECONDS=$(date +%s)

AGE_AVAILABLE_IMAGE=$((CURRENT_SECONDS - AVAILABLE_IMAGE_DATE_SECONDS))
AGE_BOOTED_IMAGE=$((CURRENT_SECONDS - BOOTED_IMAGE_DATE_SECONDS))
DIFF_IMAGES=$((AVAILABLE_IMAGE_DATE_SECONDS - BOOTED_IMAGE_DATE_SECONDS))

MONTH=$((30 * 24 * 60 * 60))
WEEK=$((7 * 24 * 60 * 60))

if [ "$AGE_BOOTED_IMAGE" -lt "$WEEK" ]; then
	exit
elif [ -n "$AVAILABLE_IMAGE_DATE" ] && [ "$AGE_AVAILABLE_IMAGE" -ge "$MONTH" ]; then
	bluenotify update
elif [ -n "$AVAILABLE_IMAGE_DATE" ] && [ "$DIFF_IMAGES" -ge "$WEEK" ]; then
	bluenotify reboot
fi

1 Like