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
|
|
|
|
2018-03-22 12:40:23 +00:00
|
|
|
all_files=( )
|
2015-12-30 21:32:46 +00:00
|
|
|
error_files=( )
|
2018-03-22 12:34:56 +00:00
|
|
|
missing_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
|
2018-03-22 12:34:56 +00:00
|
|
|
while IFS= read -r -d '' i
|
|
|
|
do
|
|
|
|
if ! gpg --verify-files "$i" >/dev/null 2>&1
|
|
|
|
then
|
2015-12-30 21:32:46 +00:00
|
|
|
error_files+=( "$i" )
|
2015-03-16 19:38:36 +00:00
|
|
|
fi
|
2018-03-22 12:40:23 +00:00
|
|
|
all_files+=( "$i" )
|
2018-03-22 12:34:56 +00:00
|
|
|
done < <(find /boot -type f -name "*.sig" -print0)
|
|
|
|
|
|
|
|
echo "Checking missing signatures in /boot..." >&2
|
|
|
|
while IFS= read -r -d '' i
|
|
|
|
do
|
|
|
|
if test ! -f ${i}.sig
|
|
|
|
then
|
|
|
|
missing_files+=( "$i" )
|
|
|
|
fi
|
|
|
|
done < <(find /boot -type f -not -name "*.sig" -print0)
|
2015-12-30 21:32:46 +00:00
|
|
|
|
2015-03-17 06:23:23 +00:00
|
|
|
# Nothing to verify? Exit 2.
|
2018-03-22 12:40:23 +00:00
|
|
|
if (( ${#all_files[@]} == 0 ))
|
2018-03-22 12:34:56 +00:00
|
|
|
then
|
2015-12-30 21:32:46 +00:00
|
|
|
echo "Nothing to verify." >&2
|
2015-03-16 19:38:36 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2018-03-22 12:34:56 +00:00
|
|
|
# Message signatures
|
2015-12-30 21:32:46 +00:00
|
|
|
printf '%s' 'Found ' >&2
|
2018-03-22 12:34:56 +00:00
|
|
|
if (( ${#error_files} == 0 ))
|
|
|
|
then
|
2015-12-30 21:32:46 +00:00
|
|
|
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
|
2018-03-22 12:34:56 +00:00
|
|
|
if (( ${#error_files[@]} == 1 ))
|
|
|
|
then
|
2015-12-30 21:32:46 +00:00
|
|
|
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
|
|
|
|
|
2018-03-22 12:34:56 +00:00
|
|
|
# Message missing
|
|
|
|
printf '%s' 'Found ' >&2
|
|
|
|
if (( ${#missing_files} == 0 ))
|
|
|
|
then
|
|
|
|
printf '%s' "$green" "no" "$normal" >&2
|
|
|
|
else
|
|
|
|
printf '%s' "$red" "${#missing_files[@]}" "$normal" >&2
|
|
|
|
fi
|
|
|
|
if (( ${#missing_files[@]} == 1 ))
|
|
|
|
then
|
|
|
|
echo " missing signature." >&2
|
|
|
|
else
|
|
|
|
echo " missing signatures." >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# File list
|
|
|
|
if (( ${#error_files[@]} > 0 ))
|
|
|
|
then
|
2015-12-30 21:32:46 +00:00
|
|
|
printf 'BAD signature: %s\n' "${error_files[@]}"
|
2018-03-22 12:34:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if (( ${#missing_files[@]} > 0 ))
|
|
|
|
then
|
|
|
|
printf 'MISSING signatures: %s\n' "${missing_files[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Exit codes
|
|
|
|
if (( ${#error_files[@]} > 0 ))
|
|
|
|
then
|
2015-03-16 19:38:36 +00:00
|
|
|
exit 1
|
2018-04-08 12:46:43 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if (( ${#missing_files[@]} > 0 ))
|
2018-03-22 12:34:56 +00:00
|
|
|
then
|
|
|
|
exit 3
|
2015-03-16 19:38:36 +00:00
|
|
|
fi
|
2015-03-17 06:54:03 +00:00
|
|
|
|
2018-04-08 12:46:43 +00:00
|
|
|
exit 0
|