forked from nyrahul/linux-kernel-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lk-config-get.sh
executable file
·140 lines (127 loc) · 2.81 KB
/
lk-config-get.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
statusline()
{
ORANGE="\033[0;33m"
RED="\033[0;31m"
GREEN="\033[0;32m"
CYAN="\033[0;36m"
NC="\033[0m" # No Color
status=$1
shift
[[ $status == AOK ]] || [[ $status == "0" ]] &&
{
printf "[${GREEN}OK${NC}] $*\n"
return
}
[[ $status == WARN ]] &&
{
printf "[${ORANGE}WARN${NC}] $*\n"
return
}
[[ $status == WAIT ]] &&
{
printf "[${CYAN}..${NC}] $*\r"
return
}
printf "[${RED}FAIL${NC}] $*\n"
exit 1
}
OSREL="/etc/os-release"
getOStype()
{
if [ -f $OSREL ]; then
. $OSREL
DIRNAME="$PRETTY_NAME"
else
command -v hostnamectl >/dev/null 2>&1 || { echo "hostnamectl not found."; return 1; }
os=`sh -c "hostnamectl" | grep "Operating System:"`
DIRNAME=`echo "$os" | sed 's/.*: //g'`
fi
DIRNAME="${DIRNAME/\//_}"
}
dump_lsmlist()
{
MD="$DIRNAME/lsm.md"
cmd2use="cat /sys/kernel/security/lsm"
cat > "$MD" <<-EOF
# Boot Config
Command used: \`$cmd2use\`
\`\`\`
`$cmd2use`
\`\`\`
EOF
statusline AOK "dumped lsm config to [$MD] ... used cmd:[$cmd2use]"
}
dump_bootconfig()
{
MD="$DIRNAME/bootconfig.md"
if [ -f /proc/config.gz ]; then
cmd2use="zcat /proc/config.gz"
elif [ -f /boot/config-$(uname -r) ]; then
cmd2use="cat /boot/config-$(uname -r)"
elif [ -f /boot/config ]; then
cmd2use="cat /boot/config"
elif [ -f "/usr/src/linux-headers-$(uname -r)/.config" ]; then
cmd2use="cat /usr/src/linux-headers-$(uname -r)/.config"
elif [ -f "/lib/modules/$(uname -r)/config" ]; then
cmd2use="cat /lib/modules/$(uname -r)/config"
else
cat <<-EOF
Could not find kernel config! Few things you can do:
1. Some platforms (such as Raspberry PI) keep their keep configs as part of configs.ko. Use "sudo modprobe configs" to load it and then run this command again.
2. If you find any other way to identify kernel config, please let us know.
EOF
statusline ERR "no way to get kernel config"
fi
cat > "$MD" <<-EOF
# Boot Config
Command used: \`$cmd2use\`
\`\`\`
`$cmd2use`
\`\`\`
EOF
statusline AOK "dumped boot config to [$MD] ... used cmd:[$cmd2use]"
}
dump_hostnamectl()
{
MD="$DIRNAME/hostnamectl.md"
command -v hostnamectl >/dev/null 2>&1
[[ $? -ne 0 ]] && statusline WARN "hostnamectl cmd not found" && return 1
cat > "$MD" <<-EOF
# hostnamectl
\`\`\`
`hostnamectl`
\`\`\`
EOF
statusline AOK "dumped hostnamectl to [$MD]"
}
dump_os_release()
{
MD="$DIRNAME/os-release.md"
[[ ! -f "$OSREL" ]] && statusline WARN "file $OSREL not found" && return 1
cat > "$MD" <<-EOF
# /etc/os-release
\`\`\`
`cat /etc/os-release`
\`\`\`
EOF
statusline AOK "dumped $OSREL to [$MD]"
}
getDirname()
{
DIRNAME=${1:-unknownLINUX}
[[ "$1" == "" ]] && getOStype
DIRNAME="$DIRNAME/$(uname -r)"
mkdir -p "$DIRNAME"
statusline AOK "using [$DIRNAME] for keeping records"
}
main()
{
dump_bootconfig
dump_lsmlist
dump_hostnamectl
dump_os_release
}
# Processing starts here
getDirname "$1"
main