| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Linux Vulnerability Mitigation |
| 4 |
# Copyright (C) 2026 Daniel Baumann <[email protected]> |
| 5 |
# |
| 6 |
# SPDX-License-Identifier: PD |
| 7 |
# |
| 8 |
# This program is free software: you have unlimited permission |
| 9 |
# to copy, distribute and modify it. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 |
|
| 15 |
set -e |
| 16 |
|
| 17 |
PROGRAM="linux-vulnerability-mitigation" |
| 18 |
COMMAND="$(basename "${0}")" |
| 19 |
|
| 20 |
SHARE="/usr/share/${PROGRAM}" |
| 21 |
|
| 22 |
if [ -t 1 ] && [ -t 2 ] |
| 23 |
then |
| 24 |
RED="\033[1;33;31m" |
| 25 |
NORMAL="\033[0m" |
| 26 |
fi |
| 27 |
|
| 28 |
Parameters () |
| 29 |
{ |
| 30 |
GETOPT_LONGOPTIONS="mitigations:,help," |
| 31 |
GETOPT_OPTIONS="m:,h," |
| 32 |
|
| 33 |
PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name="${COMMAND}" --options ${GETOPT_OPTIONS} --shell sh -- "${@}")" |
| 34 |
|
| 35 |
# shellcheck disable=SC2181 |
| 36 |
if [ "${?}" != "0" ] |
| 37 |
then |
| 38 |
echo "'${COMMAND}': getopt exit" >&2 |
| 39 |
exit 1 |
| 40 |
fi |
| 41 |
|
| 42 |
eval set -- "${PARAMETERS}" |
| 43 |
|
| 44 |
while true |
| 45 |
do |
| 46 |
case "${1}" in |
| 47 |
-m|--mitigations) |
| 48 |
MITIGATIONS="${2}" |
| 49 |
shift 2 |
| 50 |
;; |
| 51 |
|
| 52 |
-h|--help) |
| 53 |
Usage |
| 54 |
;; |
| 55 |
|
| 56 |
--) |
| 57 |
shift 1 |
| 58 |
break |
| 59 |
;; |
| 60 |
|
| 61 |
*) |
| 62 |
echo "'${COMMAND}': getopt error" >&2 |
| 63 |
exit 1 |
| 64 |
;; |
| 65 |
esac |
| 66 |
done |
| 67 |
} |
| 68 |
|
| 69 |
Usage () |
| 70 |
{ |
| 71 |
echo "Usage: ${PROGRAM} ${COMMAND} -m|--mitigation={MITIGATION|MITIGATION1,MITIGATION2,...|ALL}" >&2 |
| 72 |
echo |
| 73 |
echo "See ${PROGRAM}-${COMMAND}(1), ${PROGRAM}(1) and ${PROGRAM}(7) for more information." |
| 74 |
} |
| 75 |
|
| 76 |
Parameters "${@}" |
| 77 |
|
| 78 |
MITIGATIONS_RUN="" |
| 79 |
|
| 80 |
for MITIGATION in ${MITIGATIONS} |
| 81 |
do |
| 82 |
case "${MITIGATION}" in |
| 83 |
ALL) |
| 84 |
MITIGATIONS_RUN="$(find "${SHARE}/mitigations" -mindepth 1 -printf '%f\n' | sort -V)" |
| 85 |
;; |
| 86 |
esac |
| 87 |
done |
| 88 |
|
| 89 |
if [ -z "${MITIGATIONS_RUN}" ] |
| 90 |
then |
| 91 |
if [ -n "${MITIGATIONS}" ] |
| 92 |
then |
| 93 |
MITIGATIONS_RUN="$(echo "${MITIGATIONS}" | sed -e 's|,| |g')" |
| 94 |
else |
| 95 |
Usage |
| 96 |
exit 1 |
| 97 |
fi |
| 98 |
fi |
| 99 |
|
| 100 |
# Run |
| 101 |
case "$(id -u)" in |
| 102 |
0) |
| 103 |
;; |
| 104 |
|
| 105 |
*) |
| 106 |
echo "${RED}error:${NORMAL} '${COMMAND}' operation requires superuser privilege" >&2 |
| 107 |
exit 1 |
| 108 |
;; |
| 109 |
esac |
| 110 |
|
| 111 |
for MITIGATION in ${MITIGATIONS_RUN} |
| 112 |
do |
| 113 |
if [ ! -x "${SHARE}/mitigations/${MITIGATION}" ] |
| 114 |
then |
| 115 |
echo "${RED}error:${NORMAL} '${MITIGATION}' no such mitigation" >&2 |
| 116 |
exit 1 |
| 117 |
fi |
| 118 |
|
| 119 |
"${SHARE}/mitigations/${MITIGATION}" remove |
| 120 |
|
| 121 |
echo " ${RED}removing ${NORMAL} $(basename "${MITIGATION}") $(awk -F= '/^DATE=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}") $(awk -F= '/^NAME=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}")" |
| 122 |
done |