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
37if [ " ${EUID} " -eq 0 ]; then
48 echo " This script should not be run as root."
59 exit 1
610fi
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} " ) " ) "
1038export DIR=" ${SCRIPT_DIR} /report"
1139
1240if [ -z " ${DIR} " ]; then
1341 echo " Could not configure directory variable: ${DIR} "
1442 exit 1
1543fi
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
2650fi
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} "
4473fi
45- cd " ${OLDPWD} " || exit 1
4674
4775# Load kernel modules for decode-dimms
4876# https://superuser.com/a/1499521/
4977if 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
5587fi
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
6597fi
6698
99+ # Create the report directory
67100mkdir -p " ${DIR} "
68101# Remove old results
69102if [ " $( ls -A $DIR ) " ]; then
70103 rm -r " ${DIR:? } " /*
71104fi
72105mkdir -p " ${DIR} /hdparm" " ${DIR} /smartctl"
106+ cp " ${SCRIPT_PATH} " " ${DIR} "
73107
74108# Basic info
75109echo -n " Hostname: "
@@ -161,30 +195,44 @@ else
161195 echo " The command \" mdadm\" was not found."
162196fi
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-
175213cat " /proc/acpi/wakeup" > " ${DIR} /wakeup.txt"
176214cat " /proc/cpuinfo" > " ${DIR} /cpuinfo.txt"
177215cat " /proc/mdstat" > " ${DIR} /mdstat.txt"
178216cat " /sys/power/mem_sleep" > " ${DIR} /mem_sleep.txt"
179217cat " /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+
181229report_command acpi --everything --details
182230report_command arp
183231report_command clinfo
184232report_command decode-dimms
185233report_command df --human-readable
186234report_command dpkg --list
187- report_command fwupdmgr get-updates
235+ report_command fastfetch
188236report_command glxinfo -t
189237report_command intel_gpu_top -L
190238report_command lsblk
@@ -194,10 +242,9 @@ report_command lsmod
194242report_command lspci
195243report_command lsscsi
196244# lsusb seems to return 1 on virtual servers.
197- # set +e
245+ set +e
198246report_command lsusb
199- # set -e
200- report_command neofetch --stdout
247+ set -e
201248report_command numba --sysinfo
202249report_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"
233281else
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"
247295fi
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