2015-03-16 19:38:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# grub2-verify
|
|
|
|
# Checks the signatures of every file which is has a signature in /boot.
|
2018-01-12 20:46:55 +00:00
|
|
|
# Author: Bandie
|
2015-03-16 19:38:36 +00:00
|
|
|
# Licence: GNU-GPLv3
|
|
|
|
|
2015-12-30 21:32:46 +00:00
|
|
|
red=$(tput setaf 1)
|
|
|
|
green=$(tput setaf 2)
|
|
|
|
normal=$(tput sgr0)
|
2015-03-17 06:23:23 +00:00
|
|
|
|
2015-12-30 21:32:46 +00:00
|
|
|
all_files=( )
|
|
|
|
error_files=( )
|
2015-03-17 06:23:23 +00:00
|
|
|
|
|
|
|
# Signature check part + error counter + file counter + file list
|
|
|
|
|
2015-12-30 21:32:46 +00:00
|
|
|
echo "Checking signatures in /boot..." >&2
|
|
|
|
while IFS= read -r -d '' i; do
|
|
|
|
if ! gpg --verify-files "$i" >/dev/null 2>&1; then
|
|
|
|
error_files+=( "$i" )
|
2015-03-16 19:38:36 +00:00
|
|
|
fi
|
2015-12-30 21:32:46 +00:00
|
|
|
all_files+=( "$i" )
|
|
|
|
done < <(find /boot -name "*.sig" -print0)
|
|
|
|
|
2015-03-17 06:23:23 +00:00
|
|
|
# Nothing to verify? Exit 2.
|
2015-12-30 21:32:46 +00:00
|
|
|
if (( ${#all_files[@]} == 0 )); then
|
|
|
|
echo "Nothing to verify." >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2015-03-17 06:23:23 +00:00
|
|
|
# Message
|
2015-12-30 21:32:46 +00:00
|
|
|
printf '%s' 'Found ' >&2
|
|
|
|
if (( ${#error_files} == 0 )); then
|
|
|
|
printf '%s' "$green" "no" "$normal" >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
else
|
2015-12-30 21:32:46 +00:00
|
|
|
printf '%s' "$red" "${#error_files[@]}" "$normal" >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
fi
|
2015-12-30 21:32:46 +00:00
|
|
|
if (( ${#error_files[@]} == 1 )); then
|
|
|
|
echo " bad signature." >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
else
|
2015-12-30 21:32:46 +00:00
|
|
|
echo " bad signatures." >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
fi
|
|
|
|
|
2015-03-17 06:23:23 +00:00
|
|
|
# File list and exit codes
|
2015-12-30 21:32:46 +00:00
|
|
|
if (( ${#error_files[@]} > 0 )); then
|
|
|
|
printf 'BAD signature: %s\n' "${error_files[@]}"
|
2015-03-16 19:38:36 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
2015-03-17 06:54:03 +00:00
|
|
|
|
2015-12-30 21:32:46 +00:00
|
|
|
exit 99
|