Check if a reboot is neccessary

Here’s a script that looks for reboot-requiring packages from /etc/pacman.d/hooks/eos-reboot-required.hook.
Otherwise it is quite similar to what @Kresimir showed.

#!/bin/bash

# Check if a reboot would be necessary after system update.

DIE() {
    echo "Error: $1" >&2
    exit 1
}

Main()
{
    local updates
    local hookpkgs
    local up hook

    pacman -Q eos-update-notifier >&/dev/null || DIE "sorry, package eos-update-notifier is required."

    readarray -t updates  <<< $(checkupdates | awk '{print $1}')
    readarray -t hookpkgs <<< $(cat /etc/pacman.d/hooks/eos-reboot-required.hook | grep "^Target = " | awk '{print $3}')

    for up in "${updates[@]}" ; do
        for hook in "${hookpkgs[@]}" ; do
            case "$up" in
                $hook)
                    echo "Reboot will be required after system update." >&2
                    return 0
                    ;;
            esac
        done
    done
    echo "Reboot will not be required after updating." >&2
    return 1
}

Main "$@"
4 Likes