Debian Codegraph @

libexec/status

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