TAINT_PROPRIETARY_MODULE=0
TAINT_FORCED_MODULE=1
TAINT_UNSAFE_SMP=2
TAINT_FORCED_RMMOD=3
TAINT_MACHINE_CHECK=4
TAINT_BAD_PAGE=5
TAINT_USER=6
TAINT_DIE=7
TAINT_OVERRIDDEN_ACPI_TABLE=8
TAINT_WARN=9
TAINT_CRAP=10
TAINT_FIRMWARE_WORKAROUND=11
TAINT_OOT_MODULE=12

_check() {
  if [ $(($tainted & 1<<$1)) -ne 0 ]; then
    result_short="$result_short$2"
    result_long="$result_long * $3\n"
  fi
}

add_1tainted() {
  tainted=$(cat /proc/sys/kernel/tainted)
  if [ "$tainted" -gt 0 ]; then
    local result_short result_long
    _check $TAINT_PROPRIETARY_MODULE 'P' 'Proprietary module has been loaded.'
    _check $TAINT_FORCED_MODULE 'F' 'Module has been forcibly loaded.'
    _check $TAINT_UNSAFE_SMP 'S' 'SMP with CPUs not designed for SMP.'
    _check $TAINT_FORCED_RMMOD 'R' 'User forced a module unload.'
    _check $TAINT_MACHINE_CHECK 'M' 'System experienced a machine check exception.'
    _check $TAINT_BAD_PAGE 'B' 'System has hit bad_page.'
    _check $TAINT_USER 'U' 'Userspace-defined naughtiness.'
    _check $TAINT_DIE 'D' 'Kernel has oopsed before.'
    _check $TAINT_OVERRIDDEN_ACPI_TABLE 'A' 'ACPI table overridden.'
    _check $TAINT_WARN 'W' 'Taint on warning.'
    _check $TAINT_CRAP 'C' 'Module from drivers/staging has been loaded.'
    _check $TAINT_FIRMWARE_WORKAROUND 'I' 'Working around severe firmware bug.'
    _check $TAINT_OOT_MODULE 'O' 'Out-of-tree module has been loaded.'
    echo "** Tainted: $result_short ($tainted)" >&3
    printf "$result_long" >&3
  else
    echo '** Not tainted' >&3
  fi
  echo >&3
}

ask_1tainted() {
  true
}
