#!/bin/sh

# If we're rebooting after a panic, an oom or a watchdog reboot, grab
# the kernel logs and pass em to rdxd for uploading.
case "$(cat /proc/cmdline)" in
    *lastboot=watchdog*)
        WHAT="Watchdog fired"
        ;;
    *lastboot=panic*)
        WHAT="Kernel Panic"
        ;;
    *lastboot=oom*)
        WHAT="Kernel OOM"
        ;;
    *lastboot=reboot*)
        # this is the normal case
        WHAT=""
        ;;
    *lastboot=*)                # unexpected/new case
        WHAT=$(printf "Unexpected lastboot: %s" \
            $(sed 's,^.*lastboot=\(.*\)$,\1,' < /proc/cmdline ))
        ;;
    *)
        WHAT=""
        ;;
esac

if [ -n "$WHAT" ]; then
    klog last | rdx_reporter -F -C "$WHAT" -c "$WHAT" -d "$WHAT"
fi
