Current Dir: /snap/canonical-livepatch/418/resources/
[DIR] tests [ delete | rename ]
[FILE] 20canonical-livepatch [ edit | delete | rename ]
[FILE] 99-livepatch-kernel-upgrade-required [ edit | delete | rename ]
[FILE] livepatch-kernel-installed [ edit | delete | rename ]
[FILE] reboot-required-check [ edit | delete | rename ]
Viewing: /snap/canonical-livepatch/418/resources/99-livepatch-kernel-upgrade-required
#!/bin/sh
#
# MOTD update script for livepatch-client.
#
LIVEPATCH="/snap/bin/canonical-livepatch"
REBOOT_REQUIRED="/var/run/reboot-required"
TIMEOUT_SECONDS=10
if [ ! -x "$LIVEPATCH" ]; then
exit 0
fi
msg=$(timeout "$TIMEOUT_SECONDS" "$LIVEPATCH" kernel-upgrade-required 2> /dev/null)
code=$?
if [ "$code" -eq 0 ]; then
echo "$msg"
echo
fi
if { [ "$code" -eq 1 ] || [ "$code" -eq 2 ]; } && [ -n "$msg" ] && [ ! -f "$REBOOT_REQUIRED" ]; then
# Livepatch covers the running kernel (1) or has no recommendation (2),
# but may still print a protection message. Show it only when the
# policy is livepatch-aware and `/var/run/reboot-required` is absent;
# if the marker is present, the system's own reboot notice takes
# precedence and a second, possibly contradictory message is avoided.
policy_json=$(timeout "$TIMEOUT_SECONDS" "$LIVEPATCH" config reboot-notification-policy --format=json 2> /dev/null)
if [ "$policy_json" = '{"reboot-notification-policy":"livepatch-aware"}' ]; then
echo "$msg"
echo
fi
fi