Debian Codegraph @

debian/linux-base-7.0.9+deb14-loong64.bug-script.loong64

raw
1 #!/bin/bash
2 set -e
3
4 PATH=/sbin:/bin:/usr/sbin:/usr/bin
5 KERNEL_VER="7.0.9+deb14-loong64"
6 MODULES_DIR="/lib/modules/${KERNEL_VER}"
7
8 add_0version() {
9 echo '** Version:' >&3
10 cat /proc/version >&3
11 echo >&3
12 if [ "$(uname -r)" != "$KERNEL_VER" ]; then
13 echo '########################################################################' >&3
14 echo '########################################################################' >&3
15 echo 'Running kernel does not match package!' >&3
16 echo '########################################################################' >&3
17 echo '########################################################################' >&3
18 echo >&3
19 fi
20 }
21 add_0version
22
23 add_1cmdline() {
24 echo '** Command line:' >&3
25 cat /proc/cmdline >&3
26 echo >&3
27 }
28 add_1cmdline
29
30 _check_1tainted() {
31 if [ $(($tainted & 1<<$1)) -ne 0 ]; then
32 result_short="$result_short$2"
33 result_long="$result_long * $3\n"
34 fi
35 }
36
37 add_1tainted() {
38 tainted=$(cat /proc/sys/kernel/tainted)
39 if [ "$tainted" -gt 0 ]; then
40 local result_short result_long
41 # Use debian/bin/update-bug-taint-list to update this
42 _check_1tainted 0 P 'proprietary module was loaded'
43 _check_1tainted 1 F 'module was force loaded'
44 _check_1tainted 2 S 'kernel running on an out of specification system'
45 _check_1tainted 3 R 'module was force unloaded'
46 _check_1tainted 4 M 'processor reported a Machine Check Exception (MCE)'
47 _check_1tainted 5 B 'bad page referenced or some unexpected page flags'
48 _check_1tainted 6 U 'taint requested by userspace application'
49 _check_1tainted 7 D 'kernel died recently, i.e. there was an OOPS or BUG'
50 _check_1tainted 8 A 'ACPI table overridden by user'
51 _check_1tainted 9 W 'kernel issued warning'
52 _check_1tainted 10 C 'staging driver was loaded'
53 _check_1tainted 11 I 'workaround for bug in platform firmware applied'
54 _check_1tainted 12 O 'externally-built ("out-of-tree") module was loaded'
55 _check_1tainted 13 E 'unsigned module was loaded'
56 _check_1tainted 14 L 'soft lockup occurred'
57 _check_1tainted 15 K 'kernel has been live patched'
58 _check_1tainted 16 X 'auxiliary taint, defined for and used by distros'
59 _check_1tainted 17 T 'kernel was built with the struct randomization plugin'
60 _check_1tainted 18 N 'an in-kernel test has been run'
61 echo "** Tainted: $result_short ($tainted)" >&3
62 printf "$result_long" >&3
63 else
64 echo '** Not tainted' >&3
65 fi
66 echo >&3
67 }
68 add_1tainted
69
70 add_dmesg() {
71 local got_log=
72 echo '** Kernel log:' >&3
73 if journalctl --system --dmesg --boot=0 --lines=100 --no-pager >&3 2>/dev/null; then
74 got_log=y
75 elif [ "$(cat /proc/sys/kernel/dmesg_restrict)" = 0 ]; then
76 dmesg > >(tail -n 100 >&3) && got_log=y
77 elif command -v sudo >/dev/null; then
78 yesno "Use sudo to read the kernel log? " yep
79 if [ "$REPLY" = yep ]; then
80 sudo dmesg > >(tail -n 100 >&3) && got_log=y
81 fi
82 fi
83 test "$got_log" || echo 'Unable to read kernel log; any relevant messages should be attached' >&3
84 echo >&3
85 }
86 add_dmesg
87
88 grep_model() {
89 case "$(uname -m)" in
90 alpha)
91 grep -E '^(system (type|variation|revision)|platform string)\b' /proc/cpuinfo
92 ;;
93 arm*)
94 grep -E '^(Processor|Hardware|Revision)\b' /proc/cpuinfo
95 ;;
96 x86_64)
97 local found=
98 for name in {sys,product,chassis,bios,board}_{vendor,name,version}; do
99 if [ -f /sys/class/dmi/id/$name ]; then
100 echo -n "$name: "
101 cat /sys/class/dmi/id/$name
102 found=y
103 fi
104 done
105 test -n "$found"
106 ;;
107 mips|mips64)
108 grep -E '^(system type|cpu model)\b' /proc/cpuinfo
109 ;;
110 parisc|parisc64)
111 grep -E '^(model|[hs]version)\b' /proc/cpuinfo
112 ;;
113 ppc|ppc64|ppc64le)
114 grep -E -i '^(board|machine|model|motherboard|platform|revision|vendor)\b' /proc/cpuinfo
115 ;;
116 s390|s390x)
117 grep -E '^processor\b' /proc/cpuinfo
118 ;;
119 sparc|sparc64)
120 grep -E '^(cpu|fpu|pmu|prom|type)\b' /proc/cpuinfo
121 ;;
122 sh4|sh4a)
123 grep -E '^(machine|cpu)\b' /proc/cpuinfo
124 ;;
125 *)
126 false
127 ;;
128 esac
129
130 # Device Tree model
131 if [ -r /proc/device-tree/model ]; then
132 echo "Device Tree model:" $(cat /proc/device-tree/model)
133 fi
134 }
135
136 add_model() {
137 local found=
138 echo '** Model information' >&3
139 grep_model >&3 2>/dev/null || echo "not available" >&3
140 echo >&3
141 }
142 add_model
143
144 add_modprobe() {
145 echo '** Configuration for modprobe:' >&3
146 modprobe -c | sed -r -e '/^(alias|softdep|#|$)/d' | LC_ALL=C sort >&3
147 echo >&3
148 }
149 add_modprobe
150
151 add_modules() {
152 echo '** Loaded modules:' >&3
153 # List modules along with any taint flags.
154 # Sort first by taint status, so tainting modules are listed at front
155 cut -d' ' -f1,7 /proc/modules | LC_ALL=C sort -k2br,2 -k1b,1 | sed 's/ //' >&3
156 echo >&3
157 }
158 add_modules
159
160 add_modules_extern() {
161 echo '** Out of tree modules:' >&3
162 if [[ -e $MODULES_DIR/modules.order ]]; then
163 find "$MODULES_DIR" -name "*.ko" -o -name "*.ko.*" -printf '%P\n' | sed -re 's/\.(xz|zstd)$//' | grep -vxFf "$MODULES_DIR"/modules.order >&3 || echo 'None found' >&3
164 else
165 echo 'Unable to check' >&3
166 fi
167 echo >&3
168 }
169 add_modules_extern
170
171 _list_etc_network_interfaces() {
172 local file
173
174 for file in /etc/network/interfaces /etc/network/interfaces.d/*; do
175 if ! [ -f "$file" ]; then
176 continue
177 fi
178 case "${file##*/}" in
179 *[^-a-zA-Z0-9_]*)
180 continue
181 ;;
182 esac
183 echo "$file"
184 done
185 }
186
187 _add_etc_network_interfaces() {
188 local file
189 test -f /etc/network/interfaces || return 0
190
191 echo '** Network interface configuration:' >&3
192
193 while read file; do
194 if ! [ -r "$file" ]; then
195 echo "*** $file: unreadable" >&3
196 echo >&3
197 continue
198 fi
199 echo "*** $file:" >&3
200 # Hide passwords/keys
201 awk '$1 ~ /key|pass|^wpa-(anonymous|identity|phase|pin|private|psk)/ { gsub(".", "*", $2); }
202 $1 == "ethtool-wol" { gsub(".", "*", $3); }
203 !/^[[:space:]]*\#/ { print; }
204 ' <"$file" >&3
205 echo >&3
206 done < <(_list_etc_network_interfaces)
207 }
208
209 add_network() {
210 yesno "Include network configuration and status from this computer? " nop
211 test $REPLY = yep || return 0
212
213 _add_etc_network_interfaces
214 echo '** Network status:' >&3
215 if command -v ip >/dev/null; then
216 echo '*** IP interfaces and addresses:' >&3
217 ip address show >&3
218 echo >&3
219 fi
220 echo '*** Device statistics:' >&3
221 cat /proc/net/dev >&3
222 echo >&3
223 if command -v netstat >/dev/null; then
224 echo '*** Protocol statistics:' >&3
225 netstat -s >&3 || true
226 echo >&3
227 fi
228 echo >&3
229 }
230 add_network
231
232 add_pci() {
233 echo '** PCI devices:' >&3
234 lspci -nnkPPD >&3 2>/dev/null || echo 'not available' >&3
235 echo >&3
236 }
237 add_pci
238
239 _add_pstore_log() {
240 if [ $# -le 3 ]; then
241 return
242 fi
243
244 local backend="$1"
245 local event="$2"
246 local date="$3"
247
248 yesno "Include log of $event at $(date -d @$date +%c) stored by $backend?" yep
249 if [ $REPLY != yep ]; then
250 return
251 fi
252
253 echo >&3
254 echo "*** Log of $event at $(date -d @$date -Iseconds) from $backend" >&3
255
256 shift 3
257 for file in "$@"; do
258 tail -n +2 "$file" | sed 's/^<.>//' >&3
259 done
260 }
261
262 add_pstore() {
263 local backend
264 local i
265 local j
266 local file
267 local date
268 local head
269 local event
270 local log_files
271
272 if ! mountpoint -q /sys/fs/pstore; then
273 return 0
274 fi
275
276 set -- /sys/fs/pstore/dmesg-*-1
277 backend=${1#*/dmesg-}
278 backend=${backend%-1}
279 if [ "$backend" = '*' ]; then
280 return 0
281 fi
282
283 i=1
284 while [ -f /sys/fs/pstore/dmesg-$backend-$i ]; do
285 file=/sys/fs/pstore/dmesg-$backend-$i
286 head="$(head -1 "$file")"
287
288 # Is this the first part of a log?
289 if [ "x${head% Part1}" != "x$head" ]; then
290 # Flush previous log, if any
291 _add_pstore_log "$backend" "$event" "$date" $log_files
292
293 event="${head% Part1}"
294 date=$(stat -c %Y $file)
295 log_files=
296 j=1
297 fi
298
299 if [ "x$head" = "x$event Part$j" ]; then
300 # Each part is prepended to the list, because they're numbered
301 # backward in log history
302 log_files="$file $log_files"
303 j=$((j + 1))
304 fi
305
306 i=$((i + 1))
307 done
308
309 # Flush last log, if any
310 _add_pstore_log "$backend" "$event" "$date" $log_files
311 }
312 add_pstore
313
314 add_usb() {
315 echo '** USB devices:' >&3
316 lsusb -tv >&3 2>/dev/null || echo 'not available' >&3
317 echo >&3
318 }
319 add_usb