Debian Codegraph @

libexec/install

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_RUN=""
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 case "$(id -u)" in
103 0)
104 ;;
105
106 *)
107 echo "${RED}error:${NORMAL} '${COMMAND}' operation requires superuser privilege" >&2
108 exit 1
109 ;;
110 esac
111
112 for MITIGATION in ${MITIGATIONS_RUN}
113 do
114 if [ ! -x "${SHARE}/mitigations/${MITIGATION}" ]
115 then
116 echo "${RED}error:${NORMAL} '${MITIGATION}' no such mitigation" >&2
117 exit 1
118 fi
119
120 "${SHARE}/mitigations/${MITIGATION}" install
121
122 echo " ${GREEN}installing ${NORMAL} $(basename "${MITIGATION}") $(awk -F= '/^DATE=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}") $(awk -F= '/^NAME=/ { print $2 }' "${SHARE}/mitigations/${MITIGATION}")"
123 done