Skip to content

Commit 4b2f718

Browse files
committed
Improve the reporting script
1 parent 4536887 commit 4b2f718

File tree

2 files changed

+94
-44
lines changed

2 files changed

+94
-44
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ physics/kale/config.sh
9797
pythia8*
9898
samba/cepces
9999
samba/sscep
100+
testing/linpeas.sh
101+
testing/lynis
100102
testing/report
101103
xournalpp/autosave
102104
xournalpp/errorlogs

testing/report.sh

Lines changed: 92 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,109 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
# This is Mika's reporting script
5+
# https://github.com/AgenttiX/linux-scripts
26

37
if [ "${EUID}" -eq 0 ]; then
48
echo "This script should not be run as root."
59
exit 1
610
fi
711

8-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
9-
PARENT_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
12+
ARGS=()
13+
14+
REPORT=true
15+
SECURITY=true
16+
17+
while [[ $# -gt 0 ]]; do
18+
case $1 in
19+
--no-report)
20+
REPORT=false
21+
shift
22+
;;
23+
--no-security)
24+
SECURITY=false
25+
shift
26+
;;
27+
*)
28+
echo "Unknown argument: $1"
29+
exit 1
30+
;;
31+
esac
32+
done
33+
34+
OLDPWD="${PWD}"
35+
SCRIPT_PATH="${BASH_SOURCE[0]}"
36+
SCRIPT_DIR="$( cd "$( dirname "${SCRIPT_PATH}" )" &> /dev/null && pwd )"
37+
GIT_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
1038
export DIR="${SCRIPT_DIR}/report"
1139

1240
if [ -z "${DIR}" ]; then
1341
echo "Could not configure directory variable: ${DIR}"
1442
exit 1
1543
fi
1644

17-
# Install dependencies
18-
command -v sensors &> /dev/null
19-
LM_SENSORS_INSTALLED=$?
20-
# set +e
21-
if sudo apt update; then :; else
22-
echo "Updating repository data failed. Are there expired signing keys or missing Release files?"
23-
fi
24-
if sudo apt install git p7zip; then :; else
25-
echo "Failed to install git and p7zip. Downloading dependencies and compressing the final report may not work."
45+
# Detect if lm-sensors was already installed
46+
if command -v sensors &> /dev/null; then
47+
LM_SENSORS_INSTALLED=true
48+
else
49+
LM_SENSORS_INSTALLED=false
2650
fi
27-
echo "The following packages will enable additional reporting. Please install them if you can."
28-
sudo apt install acpi clinfo dmidecode i2c-tools lm-sensors lshw lsscsi vainfo vdpauinfo vulkan-tools
2951

30-
echo "Downloading LinPEAS"
31-
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh -o "${SCRIPT_DIR}/linpeas.sh"
32-
chmod +x "${SCRIPT_DIR}/linpeas.sh"
52+
# Install dependencies
53+
sudo apt update
54+
sudo apt install 7zip acpi clinfo dmidecode git i2c-tools lm-sensors lshw lsscsi vainfo vdpauinfo vulkan-tools wget
55+
56+
# Install security scanners
57+
if [ "${SECURITY}" = true ]; then
58+
echo "Downloading LinPEAS"
59+
wget "https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh" -O "${SCRIPT_DIR}/linpeas.sh"
60+
chmod +x "${SCRIPT_DIR}/linpeas.sh"
3361

34-
OLDPWD="${PWD}"
35-
LYNIS_DIR="${PARENT_DIR}/lynis"
36-
if [ -d "${LYNIS_DIR}" ]; then
37-
echo "Lynis was found. Updating."
38-
cd "${LYNIS_DIR}" || exit 1
39-
git pull
40-
else
41-
echo "Lynis was not found. Downloading."
42-
cd "${PARENT_DIR}" || exit 1
43-
git clone https://github.com/CISOfy/lynis
62+
LYNIS_DIR="${GIT_DIR}/lynis"
63+
if [ -d "${LYNIS_DIR}" ]; then
64+
echo "Lynis was found. Updating."
65+
cd "${LYNIS_DIR}"
66+
git pull
67+
else
68+
echo "Lynis was not found. Downloading."
69+
cd "${GIT_DIR}"
70+
git clone "https://github.com/CISOfy/lynis"
71+
fi
72+
cd "${OLDPWD}"
4473
fi
45-
cd "${OLDPWD}" || exit 1
4674

4775
# Load kernel modules for decode-dimms
4876
# https://superuser.com/a/1499521/
4977
if command -v decode-dimms &> /dev/null; then
5078
sudo modprobe at24
5179
sudo modprobe ee1004
52-
sudo modprobe eeprom
5380
sudo modprobe i2c-i801
5481
sudo modprobe i2c-amd-mp2-pci
82+
# The eeprom module may not be present on all systems.
83+
# https://bbs.archlinux.org/viewtopic.php?id=292830
84+
set +e
85+
sudo modprobe eeprom
86+
set -e
5587
fi
56-
# set -e
88+
5789
# It's not clear whether this should be before or after loading the kernel modules.
5890
# As this is after loading them, it could detect more devices, but on the other hand
59-
# it might be unsafe.
91+
# it might access some devices that it shouldn't.
6092
# TODO: test that this works
61-
if (command -v sensors &> /dev/null) && [ "${LM_SENSORS_INSTALLED}" -eq 1 ]; then
93+
if (command -v sensors &> /dev/null) && [ "${LM_SENSORS_INSTALLED}" = false ]; then
6294
echo "lm-sensors was installed with this run of the script."
6395
echo "Therefore the sensors haven't been configured yet and should be configured now."
6496
sudo sensors-detect
6597
fi
6698

99+
# Create the report directory
67100
mkdir -p "${DIR}"
68101
# Remove old results
69102
if [ "$(ls -A $DIR)" ]; then
70103
rm -r "${DIR:?}"/*
71104
fi
72105
mkdir -p "${DIR}/hdparm" "${DIR}/smartctl"
106+
cp "${SCRIPT_PATH}" "${DIR}"
73107

74108
# Basic info
75109
echo -n "Hostname: "
@@ -161,30 +195,44 @@ else
161195
echo "The command \"mdadm\" was not found."
162196
fi
163197

164-
# Lynis security scan
165-
echo "Starting Lynis as root. If you see a warning about file permissions, press enter to continue."
166-
sudo "${LYNIS_DIR}/lynis" audit system |& tee "${DIR}/lynis.txt"
198+
# Security scanners
199+
if [ "${SECURITY}" = true ]; then
200+
# Lynis security scan
201+
# This can take quite a while and should therefore be the last command to be run with sudo.
202+
echo "Starting Lynis as root. If you see a warning about file permissions, press enter to continue."
203+
sudo "${LYNIS_DIR}/lynis" audit system |& tee "${DIR}/lynis.txt"
204+
205+
# LinPEAS security scan
206+
"${SCRIPT_DIR}/linpeas.sh" |& tee "${DIR}/linpeas.txt"
207+
fi
167208

168209
# -----
169210
# Non-root info
170211
# -----
171212

172-
# LinPEAS security scan
173-
"${SCRIPT_DIR}/linpeas.sh" |& tee "${DIR}/linpeas.txt"
174-
175213
cat "/proc/acpi/wakeup" > "${DIR}/wakeup.txt"
176214
cat "/proc/cpuinfo" > "${DIR}/cpuinfo.txt"
177215
cat "/proc/mdstat" > "${DIR}/mdstat.txt"
178216
cat "/sys/power/mem_sleep" > "${DIR}/mem_sleep.txt"
179217
cat "/var/log/syslog" > "${DIR}/syslog.txt"
180218

219+
if command -v fwupdmgr &> /dev/null; then
220+
fwupdmgr get-devices > "${DIR}/fwupdmgr_devices.txt"
221+
# fwupdmgr returns exit code 2 when no updates are found.
222+
set +e
223+
fwupdmgr get-updates > "${DIR}/fwupdmgr_updates.txt"
224+
set -e
225+
else
226+
echo "The command \"fwupdmgr\" was not found."
227+
fi
228+
181229
report_command acpi --everything --details
182230
report_command arp
183231
report_command clinfo
184232
report_command decode-dimms
185233
report_command df --human-readable
186234
report_command dpkg --list
187-
report_command fwupdmgr get-updates
235+
report_command fastfetch
188236
report_command glxinfo -t
189237
report_command intel_gpu_top -L
190238
report_command lsblk
@@ -194,10 +242,9 @@ report_command lsmod
194242
report_command lspci
195243
report_command lsscsi
196244
# lsusb seems to return 1 on virtual servers.
197-
# set +e
245+
set +e
198246
report_command lsusb
199-
# set -e
200-
report_command neofetch --stdout
247+
set -e
201248
report_command numba --sysinfo
202249
report_command nvidia-smi
203250

@@ -228,7 +275,8 @@ if command -v upower &> /dev/null; then
228275
{
229276
upower --enumerate
230277
upower --dump
231-
upower --wakeups
278+
# This no longer works on Kubuntu 25.04
279+
# upower --wakeups
232280
} &> "${DIR}/upower.txt"
233281
else
234282
echo "The command \"upower\" was not found."
@@ -246,7 +294,7 @@ if [ -d "/var/log/samba" ] && command -v rsync &> /dev/null; then
246294
rsync -av --progress "/var/log/samba" "${DIR}" --exclude "cores"
247295
fi
248296

249-
if [ "$1" != "--no-report" ]; then
297+
if [ "${REPORT}" = true ]; then
250298
# Packaging
251299
7zr a -mx=9 "${DIR}_$(date '+%Y-%m-%d_%H-%M-%S').7z" "${DIR}"
252300
echo "The report is ready."

0 commit comments

Comments
 (0)