Skip to content
Snippets Groups Projects
Verified Commit 6861eba3 authored by Štěpán Henek's avatar Štěpán Henek :bear:
Browse files

new module format

parent 9a6f1cf5
No related branches found
No related tags found
1 merge request!9Resolve "Add script(s) for generating diagnostics"
Showing
with 78 additions and 47 deletions
......@@ -2,22 +2,17 @@
MAX_LINES_PER_MODULE=${MAX_LINES_PER_MODULE:-10000}
# enter the script directory
cd "$(dirname $0)"
# read modules and load help
modules=""
for mod_file in $(dirname $0)/modules/*.module ; do
for mod_file in modules/*.module ; do
# load help
. "$mod_file"
module=$(basename "$mod_file" .module)
modules="$modules $module"
# remove first and last newline
newline="
"
help=${help##$newline}
help=${help%%$newline}
# store variable
eval help_${module}="\${help}"
done
is_in_list() {
......@@ -34,7 +29,7 @@ is_in_list() {
module_help() {
for module in $modules ; do
echo ' '${module}
eval echo \"\$help_$module\" | sed 's/^/ /'
./modules/"$module".module help | sed 's/^/ /'
echo
done
}
......@@ -48,7 +43,7 @@ print_help() {
module_run() {
local module="$1"
printf "############## %s\n" $module
sh "$(dirname $0)"/modules/"$module".module run 2>&1 | tail -n "$MAX_LINES_PER_MODULE"
./modules/"$module".module run 2>&1 | tail -n "$MAX_LINES_PER_MODULE"
printf "************** %s\n" $module
}
......
......@@ -3,10 +3,12 @@ Each now module should look like this:
It should contain:
#!modules/module.sh
help="
some brief description of the module
"
if [ "$1" = "run" ] ; then
run () {
# the actual code with prints something into stdout/stderr
fi
}
#!modules/module.sh
help="
try to get serial number from atsha
"
if [ "$1" = "run" ] ; then
run () {
atsha204cmd serial-number
fi
}
#!modules/module.sh
help="
print info regarding certificates
"
if [ "$1" = "run" ] ; then
run () {
# print cz nic certificates
opkg info cznic-cacert-bundle
md5sum $(opkg files cznic-cacert-bundle | sed -n '1!p')
......@@ -19,4 +20,4 @@ if [ "$1" = "run" ] ; then
find /etc/ssl/certs/*.crt | xargs -n1 basename | sort > /tmp/diagnostics-certs-crts
diff /tmp/diagnostics-certs-links /tmp/diagnostics-certs-crts | grep '^>\|^<'
rm /tmp/diagnostics-certs-links /tmp/diagnostics-certs-crts
fi
}
#!modules/module.sh
help="
info about about the cron
"
if [ "$1" = "run" ] ; then
run () {
# is running
sh modules/processes.module run | grep cron | grep -v 'grep\|cron\.module\|diagnostics'
echo
......@@ -17,4 +19,4 @@ if [ "$1" = "run" ] ; then
# is cron enabled
find /etc/init.d/*cron* -exec md5sum {} \;
find /etc/rc.d/*cron* -exec md5sum {} \;
fi
}
#!modules/module.sh
help="
identify which devices are mounted
"
if [ "$1" = "run" ] ; then
run () {
df -h
fi
}
#!modules/module.sh
help="
display output of dmesg
"
if [ "$1" = "run" ] ; then
run () {
dmesg
fi
}
#!modules/module.sh
help="
gather dns related informations
"
if [ "$1" = "run" ] ; then
run () {
# resolver config
uci -q show resolver
uci -q show unbound
......@@ -30,4 +31,4 @@ if [ "$1" = "run" ] ; then
dig @localhost www.wilda.nsec.0skar.cz # should pass
dig @localhost www.wilda.0skar.cz # should pass
dig @localhost *.wilda.rhybar.ecdsa.0skar.cz # should fail
fi
}
#!modules/module.sh
help="
list turris firewall settings
"
if [ "$1" = "run" ] ; then
run () {
cat /etc/config/firewall-turris
echo
md5sum /usr/share/firewall/*
fi
}
#!modules/module.sh
help="
get uci firewall config
"
if [ "$1" = "run" ] ; then
run () {
cat /etc/config/firewall
fi
}
#!modules/module.sh
help="
list installed packages
"
if [ "$1" = "run" ] ; then
run () {
opkg list-installed
fi
}
#!modules/module.sh
help="
list current ip addressed
"
if [ "$1" = "run" ] ; then
run () {
echo ipv4:
ip -4 address
echo ipv6:
ip -6 address
fi
}
#!modules/module.sh
help="
list current iptables
"
if [ "$1" = "run" ] ; then
run () {
iptables-save
fi
}
#!modules/module.sh
help="
read /var/log/messages
"
if [ "$1" = "run" ] ; then
run () {
ls /var/log/messages* | sort -r | while read path; do
echo "$path"
if [ "${path:$((${#path} - 2))}" = "gz" ] ; then
......@@ -12,4 +13,4 @@ if [ "$1" = "run" ] ; then
cat "$path"
fi
done
fi
}
#!/bin/sh
. "$1"
case "$2" in
help)
# remove first and last newline
newline="
"
help=${help##$newline}
help=${help%%$newline}
echo "$help"
;;
run)
run
;;
esac
#!modules/module.sh
help="
try to send firewall logs to the server
"
if [ "$1" = "run" ] ; then
run () {
/usr/share/nikola/bin/nikola.sh
fi
}
#!modules/module.sh
help="
list running processes
"
if [ "$1" = "run" ] ; then
run () {
busybox ps w
fi
}
#!modules/module.sh
help="
show current routes
"
if [ "$1" = "run" ] ; then
run () {
echo ipv4:
ip -4 route
echo ipv6:
ip -6 route
fi
}
#!modules/module.sh
help="
show info about linux kernel
"
if [ "$1" = "run" ] ; then
run () {
uname -a
fi
}
#!modules/module.sh
help="
try to run updater
"
if [ "$1" = "run" ] ; then
run () {
updater.sh -n
fi
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment