Debian Codegraph @

libexec/check

raw
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 GREEN="\033[1;33;32m"
26 YELLOW="\033[1;33;33m"
27 NORMAL="\033[0m"
28 fi
29
30 Parameters ()
31 {
32 GETOPT_LONGOPTIONS="mitigations:,help,"
33 GETOPT_OPTIONS="m:,h,"
34
35 PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name="${COMMAND}" --options ${GETOPT_OPTIONS} --shell sh -- "${@}")"
36
37 # shellcheck disable=SC2181
38 if [ "${?}" != "0" ]
39 then
40 echo "'${COMMAND}': getopt exit" >&2
41 exit 1
42 fi
43
44 eval set -- "${PARAMETERS}"
45
46 while true
47 do
48 case "${1}" in
49 -m|--mitigations)
50 MITIGATIONS="${2}"
51 shift 2
52 ;;
53
54 -h|--help)
55 Usage
56 ;;
57
58 --)
59 shift 1
60 break
61 ;;
62
63 *)
64 echo "'${COMMAND}': getopt error" >&2
65 exit 1
66 ;;
67 esac
68 done
69 }
70
71 Usage ()
72 {
73 echo "Usage: ${PROGRAM} ${COMMAND} [-m|--mitigation={MITIGATION|MITIGATION1,MITIGATION2,...|ALL}]" >&2
74 echo
75 echo "See ${PROGRAM}-${COMMAND}(1), ${PROGRAM}(1) and ${PROGRAM}(7) for more information."
76 }
77
78 Parameters "${@}"
79
80 MITIGATIONS="${MITIGATIONS:-ALL}"
81
82 for MITIGATION in ${MITIGATIONS}
83 do
84 case "${MITIGATION}" in
85 ALL)
86 MITIGATIONS_RUN="$(find "${SHARE}/mitigations" -mindepth 1 -printf '%f\n' | sort -V)"
87 ;;
88 esac
89 done
90
91 if [ -z "${MITIGATIONS_RUN}" ]
92 then
93 if [ -n "${MITIGATIONS}" ]
94 then
95 MITIGATIONS_RUN="$(echo "${MITIGATIONS}" | sed -e 's|,| |g')"
96 else
97 Usage
98 exit 1
99 fi
100 fi
101
102 # Run
103 for MITIGATION in ${MITIGATIONS_RUN}
104 do
105 if [ ! -x "${SHARE}/mitigations/${MITIGATION}" ]
106 then
107 echo "${RED}error:${NORMAL} '${MITIGATION}' no such mitigation" >&2
108 exit 1
109 fi
110
111 set +e
112 "${SHARE}/mitigations/${MITIGATION}" status
113 RETURN="${?}"
114 set -e
115
116 case "${RETURN}" in
117 0)
118 CHECK="${GREEN}fixed ${NORMAL}"
119 ;;
120
121 1)
122 CHECK="${YELLOW}mitigated ${NORMAL}"
123 ;;
124
125 2)
126 CHECK="${RED}vulnerable ${NORMAL}"
127 ;;
128 esac
129
130 echo " ${CHECK} $(basename "${MITIGATION}") $(awk -F= '/^DATE=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}") $(awk -F= '/^NAME=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}")"
131 done