First commit

This commit is contained in:
SPiNNiX 2020-06-30 23:38:58 +02:00
commit aac0c031f7

193
Serverdoku.bash Normal file
View file

@ -0,0 +1,193 @@
#!/bin/bash
TOOLS="dmidecode lshw bc"
for tool in ${TOOLS}
do
if ! which $tool > /dev/null
then
echo $tool fehlt.
exit 1
fi
done
HOSTNAME=$(hostname -f)
OUTFILE=$HOSTNAME-wikidoku.txt
echo "Achtung: Bitte die generierte Datei $OUTFILE überprüfen und anpassen!"
cat > $OUTFILE <<EOF
== Kurzinfo ==
* ...
EOF
MANUFACTURER=$(dmidecode | grep "System Information" -A 5 | grep Manufacturer | cut -d: -f2 | sed -e 's/^\ //')
PRODUCTNAME=$(dmidecode | grep "System Information" -A 5 | grep "Product Name" | cut -d: -f2 | sed -e 's/^\ //')
CPUCOUNT=$(lscpu | grep '^CPU(s):' | awk '{ print $2 }')
CPUMODEL=$(lscpu | grep 'Model name:' | sed -re 's/Model name:\s+//g')
MEMORY=$(lshw -C memory | grep -A10 '*-memory' | grep 'size:' | awk '{ print $2 }')
HDDSIZE=$(lsblk -b --output NAME,SIZE | grep -v '─' | grep -v NAME | awk '{print $2}' | sed ':a;N;$!ba;s/\n/+/g' | bc | awk '{ byte =$1 /1024/1024^2 ; print byte " GB" }')
cat >> $OUTFILE <<EOF
== Hardware ==
* ${MANUFACTURER} ${PRODUCTNAME}
* ${CPUCOUNT} x ${CPUMODEL}
* ${MEMORY} RAM
* ${HDDSIZE} HDD
EOF
cat >> $OUTFILE <<EOF
== Filesystem ==
{| class="wikitable"
! Device
! Mountpoint
! Grösse
! Beschreibung
EOF
df -h | grep -v tmpfs | grep -v udev | grep -v ^Filesystem | while read line
do
DEVICE=$(echo $line | awk '{print $1}')
SIZE=$(echo $line | awk '{print $2}')
MOUNTPOINT=$(echo $line | awk '{print $6}')
echo "|-" >> $OUTFILE
echo "| ${DEVICE}" >> $OUTFILE
echo "| ${MOUNTPOINT}" >> $OUTFILE
echo "| ${SIZE}" >> $OUTFILE
echo "| ..." >> $OUTFILE
done
SWAPDEV=$(grep SWAP /etc/fstab | awk '{print $1}')
SWAPDEVSIZE=$(free -m | grep ^Swap: | awk '{print $2}')
echo "|-" >> $OUTFILE
echo "| ${SWAPDEV}" >> $OUTFILE
echo "| none" >> $OUTFILE
echo "| ${SWAPDEVSIZE}M" >> $OUTFILE
echo "| Swap Space" >> $OUTFILE
cat >> $OUTFILE <<EOF
|-
|}
EOF
cat >> $OUTFILE <<EOF
== Netzwerk ==
{| class="wikitable"
! Device
! IP/Mask
! Hostname
! Beschreibung
EOF
for line in $(ip a s | grep '^[0-9]' | awk '{ print $2 }' | grep -v lo | sed -e 's/\:$//')
do
rows=$(ip a s $line | grep inet | sed -re 's/.*inet6?//' | awk '{ print $1 }' | grep -v '^fe80:' | wc -l)
if [[ "$rows" -eq 0 ]]; then
echo "|-" >> $OUTFILE
echo "| '''${line}'''" >> $OUTFILE
echo "| " >> $OUTFILE
echo "| " >> $OUTFILE
echo "| ..." >> $OUTFILE
continue
fi
echo "|-" >> $OUTFILE
echo "|rowspan="${rows}"| '''${line}'''" >> $OUTFILE
for inet in $(ip a s $line | grep inet | sed -re 's/.*inet6?//' | awk '{ print $1 }' | grep -v '^fe80:'); do
IFADDR=$(echo $inet | cut -d/ -f1)
IFCIDR=$(echo $inet | cut -d/ -f2)
IFHOSTNAME=$(getent hosts "${IFADDR}" | head -1 | awk '{ print $2 }')
echo "| ${IFADDR}/${IFCIDR}" >> $OUTFILE
echo "| ${IFHOSTNAME}" >> $OUTFILE
echo "| ..." >> $OUTFILE
echo "|-" >> $OUTFILE
done
done
cat >> $OUTFILE <<EOF
|}
EOF
DEFAULTGW=$(ip route show default | grep ^default | awk '{print $3}')
DEFAULTIF=$(ip route show default | grep ^default | awk '{print $5}')
DEFAULTIFIP=$(ip a s dev ${DEFAULTIF} | grep inet | head -n1 | awk '{print $2}' | cut -d"/" -f1)
echo "* '''Gateway:''' ${DEFAULTIF} ${DEFAULTGW}" >> $OUTFILE
cat >> $OUTFILE <<EOF
== User mit Login Shell ==
In folgender Tabelle alle User mit '''gültiger Loginshell''' (z.B. /bin/sh, /bin/bash, /bin/zsh) sowie '''gültigem Passwort''' (z.B. Eintrag in /etc/shadow) aufführen.
{| class="wikitable"
! Username
! Login Shell
! Zweck
EOF
grep -e "sh$" /etc/passwd | while read line
do
USRNAME=$(echo $line | cut -d: -f1)
USRSHELL=$(echo $line | cut -d: -f7)
USRSHADOW=$(grep ${USRNAME} /etc/shadow | cut -d: -f2)
if [[ ${USRSHADOW} = '!' ]]
then
continue
fi
echo "|-" >> $OUTFILE
echo "| ${USRNAME}" >> $OUTFILE
echo "| ${USRSHELL}" >> $OUTFILE
echo "| ..." >> $OUTFILE
done
cat >> $OUTFILE <<EOF
|-
|}
EOF
cat >> $OUTFILE <<EOF
== Sonstiges ==
* ...
=== Dienste ===
* SSH
== Backup ==
*
== Zugänge ==
* SSH
EOF
if [ -e /dev/ipmi0 -o -e /dev/ipmi/0 ]
then
ILOIP=$(ipmitool lan print | grep '^IP Address' | grep -v Source | awk '{print $4}')
cat >> $OUTFILE <<EOF
== Management Module ==
'''Zugangsmöglichkeiten:'''
* SSH (TCP Port 22): ssh root/Administrator@${ILOIP}
* Web (TCP Port 443): https://${ILOIP}
EOF
fi
OS=$(lsb_release -i | sed -re 's/Distributor ID:\s+//g')
OSCODENAME=$(lsb_release -c | sed -re 's/Codename:\s+//g')
echo "[[Category:Systemdokumentation]]" >> $OUTFILE
if [[ -z "${OSCODENAME}" || "${OSCODENAME}" == "n/a" ]]; then
echo "[[Category:${OS^}]]" >> $OUTFILE
else
echo "[[Category:${OS^}:${OSCODENAME^}]]" >> $OUTFILE
fi