#!/bin/bash
#
# make system documentation
#
## This version is intended to run on SLES8/9/10-systems (ia32/64+IA64) !!!
## see man page sysdoc(8) for more infos
#
# (cr) 2005 by csh @ FSC PS BLN
#
#
# Changelog of sysdoc. You will find the most recent version at the buttom of this list.
#
#  csh   0.1   (17.06.2005) Initial Version
#  csh   0.2   (21.06.2005) hostname in tar-filename
#                           + ddm, init.d, boot ... infos
#  csh   0.3   (21.06.2005) check if FSC-WS is installed w/ report
#  csh   0.4   (23.06.2005) corrected DDM, boot
#  csh   0.5   (23.06.2005) added PCL-PCS-output
#  csh   0.6   (25.06.2005) added "-V" version info parameter
#  csh   0.61  (25.06.2005) some systems have problems w/ >> &>1 :-(
#  csh   0.62  (25.06.2005) copy  complete /etc/PRIMECLUSTER 
#  csh   0.63  (12.09.2005) include ~/doc
#  csh   0.64  (12.09.2005) also copy hosts&fstab (no comments in sitar :-()
#  csh   0.65  (02.11.2005) for SIS: check -e against DIR not conf-file
#  csh   0.66  (08.11.2005) for some files in /etc copy history also (e.g: hosts*)
#  csh   0.67  (11.11.2005) do ..scan on LVM 
#  csh   0.68  (15.11.2005) incl. /etc/services
#  csh   0.70  (14.12.2005) first rel w/ kernel 2.6 support (lvm)
#  csh   0.71  (15.12.2005) sitar 2.4(file) & 2.6(dir) differ :-(
#  csh   0.80  (06.02.2006) whole job in one file w/ function core(=old mksysdok)
#                           some typos, also copy *omsg
#  csh   0.81  (17.02.2006) added infos about filesystems,issue,profile
#  csh   0.82  (13.04.2006) added tune2fs for LVM filesystems
#                           + report logfilename
#  csh   0.83  (08.05.2006) added tune2fs support for 2.4 systems (auto)
#  csh   0.90  (13.07.2006) added mount infos from proc (fs-type)
#                           added ifconfig,netstat,ethtool infos
#                           added /proc/scsi infos
#                           added lspci infos
#                           group most *txt-files under /doc
#  csh   0.91  (13.07.2006) added EMCpowerpath infos 
#                           also include errors messages of core function to log file
#  csh   0.92  (18.07.2006) added xientd configs; system infos (uname,uptime...)     
#  csh   0.930 (27.10.2006) added snmp retrieval (MIBII and SV) 
#                           added recent SV-logs
#                           version numbers 0.9xx (add. subnumber)
#  csh   0.940 (17.11.2006) from now on sysdoc is distributed as rpm-package 
#                           (incl. man page and doc's)
#  csh   0.941 (20.11.2006) corrected system section output
#  csh   0.942 (01.12.2006) corrected retrieving of community for smnp-output (\t := " ")
#                           (using "public" as last resort)
#  csh   0.950 (21.01.2007) new infos about system (lsdev, ps, sysconfig-files, proc/rd, SuSErelease)
#                           added some /proc infos
#                           added some infos specific to ia64 (IPF) architecture (parted)
#                           added next level of sitar-infos (which is not part of all distris)
#                           enhanced info about snmp fault
#  csh   0.951 (23.01.2007) new info about rpm-installed packages in doc/packages
#                           added infos form proc (cpu+mem)
#                           added infos from /etc (printcap;hosts;inittab;crontab,chkconfig)
#  csh   0.952 (28.01.2007) corrected partition info by parted if system ownes DAC960 controller(s)
#                           enhanced output of filesystem/partitions-info
#  csh   0.953 (20.02.2007) parted has Problems w/ multipaths (if hidden) -> drop code :-( (temp)
#                           enhanced output of lspci (now added -n)
#                           additional info about devices from /sys/class/scsi_host
#                           additional info about network devices (bonding + vlan from /proc)
#                           new section: /sys
#  csh   0.954 (24.02.2007) reactivated parted-code w/ ia64-test
#                           include /proc/config.gz
#                           added /sys/devices (for driver-info)
#                           added snmp-info from SVlist
#  csh   0.960 (05.03.2007) improved success at fsc-mib-retrieval
#                           added support for PRIMERGY BladeFrame cBlades
#  csh   0.961 (15.03.2007) copy README to tgz
#                           added all sys/* into sys.tgz (fc_... !)
#  csh   0.962 (20.03.2007) copy inittab to tgz
#                           output of system commands in doc-section (lvm,network,system...) is given to seperat files
#  csh   0.963 (09.04.2007) added new sys infos (sysctl, hwinfo, ulimit, pam.d) 
#                           test for existing /sys before retrieving from (otherwise it will tar / to tgz ;-)
#                           reduced hwinfo to "std"-devices (no braille, tv,.....)
#                           added iptables output to network section
#  csh   0.964 (09.04.2007) added further infos from cBlades on BladeFrame's
#  csh   0.965 (19.04.2007) corrected handling of /etc
#                           added FlexFrame depended configs /var/FlexFrame
#  csh   0.970 (25.04.2007) the ...log file is now put into the "tgz" - so there is only one file as result,
#                           which contains ALL information 
#                           sysdoc reports start-time (@begin) and used time (@end) for infomation (+time)
#                           separate files for LICENSE and COPYING, added download+license-info to help
#                           internal: packing+cleaning-code moved from core-function to body
#  csh   0.971 (02.05.2007) the run-time is also recorded in log-file (wraped core function due to internal time)
#                           copy all *conf* and *tab* files from /etc
#                           most infos in /proc (incl subdirs but w/o process-subtrees [1-9]*)
#                           nfs runtime infos (nfsstat;showmount in the system-section)
#                           analyse syslog-conf(s) for logfile to copy into "tgz"
#  csh   0.972 (02.05.2007) fixed logfiles-section (different handling for syslogd & syslogd-ng)
#                           +report syslog-conf-files
#                           fixed proc-section (exclude acpi/event....)
#  csh   0.973 (08.05.2007) some adoptions to SLES8 (correct handling /proc/partitions -> parted)
#                           excluded "event" from proc-file-collection
#                           added collection of sar-files (incl. bin-file) in new section
#                           added mpstat, vmstat, iostat (new parameter)
#                           added RELEASE-info to rpm_packages.txt
#  csh   0.974 (10.05.2007) improved pci-infos (+ -vvv and -t (treeview))
#                           added ntp-info + vmstat-info in system
#  csh   0.975 (21.05.2007) improved syslog handling (report found active syslog.conf and use this one only)
#                           added infos about multipathing (DM based) into separate doc/dm-multipath
#  csh   0.980 (11.09.2007) the sysdoc "executable" is now placed in /usr/sbin (better for FF-environments)
#                           rewriten the sections to functions (enable later use for -s (short))
#                           include install date into rpm-report
#  csh   0.981 (16.11.2007) enhancements to BF's (incl. dir /opt/egenera/install)
#                           corrected function calls (missed some ...hwinfo...)
#                           changed cp options to -a (to preserve mod-date)
#                           Architecture (platform) is "noarch" from now on
#  csh   0.982 (17.11.2007) added XEN related info support
#                           fixed proc info exclude (XEN related)
#  csh   0.983 (28.11.2007) fixed placing of xen-infos > /doc/xen 
#                           added Release-nr. to VERSION & man-page
#                           added xen-vm-config-dir to tgz
#                           reactivated /var/log/messages (for old syslog)
#                           fixed placeing PowerPath info > /doc/EMC
#  csh   0.984 (26.01.2008) fixed cBlade-info egenera props         
#                           put a txt-version of man page to /usr/.../doc...
#  csh   0.985 (07.07.2008) fixed sar-Infos (sa* | grep -v sar instead sa.*)
#                           exec sar/sa-collect before copying files
#                           collect last 3 sa*-files (not only last one)
#                           added QLA-infos (via scli)
#                           fixed pam-config collection (find type is now d (not f))
#                           added /etc/securtity
#                           added dmidecode to system
#                           added tmp-SVlist-dir w/ correct snmp-community
#                           added parameter "-c" (cleanup /tmp)
#                           added parameter "-x set,set,set..." (exclude info-sets)
#                           added /etc/SuSEconfig/ - files
#                           added info about calling parameters at start (log)
#                           fixed -c function (exclude actual log file)
#                           added report of deleted files by -c
#                           added SV-Raid infos (if installed)
#                           changed multipath -l to -ll
#  csh   0.986 (19.09.2008) fixed SVlist-handling again (due to hardcoding of .ini-file):
#                           added "patchstr" to patch SVlist-binary in /tmp
#                           added ServerView-status to snmp_info.txt
#                           added SVlist... community-check w/ warning if differs from snmp-system
#                           added /etc/udev 
#                           fixed patchstr binary type to static32 (was ..64) to be comatible w/ most systems
#                           (former substr is now: patchstr  ; "patch" matches function better then "substitute...")
#  csh   0.986 (21.09.2008) R7  added swapinfos (free,swap)
#                               added check for SVlist... (w/ info)
#  csh   0.986 (21.12.2008) R8  fixed snmp community search typo (now [:space:]) 
#                               fixed: exectuting SVlist... only one time    
#  csh   0.986 (22.12.2008) R9  fixed snmp community search typo (now [:space:]) 
#  csh   0.986 (22.12.2008) R8  fixed powerpath infos
#  csh   0.990-1 (01.01.2009) added powerpath registration info
#                             added san -A & showme -l to cBlade-info    
#                             added infos about install repositories (zypper only in this Rel.)
#                             mention Rel. in Version string (CHANGES only)
#                             improved lvm2 infos (added -o +devices & -m)
#                             added blkid info ( e.g. UUID of volume) to /doc/filesystems/volume_info.txt
#                             changed name of system-infos-dir to /doc/system-status (formerly ...system...)
#                             changed location of HW-relevant infos to an own dir (/doc/hw)
#                             changed location of pci infos to the HW-dir (/doc/hw)
#                             added who, pstree system-status info
#                             changed name of dm-multipath info to device-mapper
#                             added ../disk-by* and some other infos to device-mapper
#  csh   0.990-2 (02.01.2009) changed pstree from -U to -A (utf > ascii)
#                             added zypper sl & rug ca to repositories info
#                             changed "not installed" to "not available" in log-output
#  csh   0.991-1 (08.01.2009) added /etc/*.cf (spam&mailer-configs) 
#                             added /etc/postfix
#                             added YaST2logs
#                             added autofs-files
#                             changed location of BF-cblade info to /doc/BladeFrame_cblade
#                             added save-state to BF-cblade info
#  csh   0.991-2 (12.01.2009) added some esh commands to BF-cblade-infos
#  csh   0.991-3 (14.01.2009) added link (www.sysdoc.de) to 1st line of README          
#                             the README.* is also copied from sysdoc's run location (if file exists)
#  csh   0.992-1 (02.05.2009) resolve-links: make sure that files are copied even if they are links (if linked, copy target-dir or -file)
#                             added /etc/HOSTNAME,/etc/shadow
#                             some cosmetics (error-outputs suppressed)
#                             fixed some typos (snmp/SV)
#  csh   0.992-2 (02.05.2009) fixed SVlist...ini handling: be aware of DOS-type w/ ^R
#                             enabled /etc/primecluster in upper or lower cases
#  csh   0.992-3 (02.05.2009) fixed BF-cblade detection
#                             added pool-infos to BF-cblade
#  csh   0.992-4 (02.05.2009) added collection of files AND links in etc-set 
#                             changed filter from *tab* to *tab in etc-set
#  csh   0.992-5 (03.05.2009) fixed BF-cblade detection (typo)
#                             A codename is included w/in the VERSION (-V) : TFAX
#                             included copy of fc_* in sysfs-info
#  csh   0.992-6 (17.06.2009) sysstat: pay attention to x86_64 implementation (lib64)
#  csh   0.992-1st (-12.2010) prerelease: just for evaluation
#  csh   0.993-2 (17.12.2010) FATS : respect new versions of ServerView-RAID (/opt/fujitsu...)
#                             changed /etc/conf's to *conf* but --exclude="gconf" (files&dirs)
#                             changed filesystems: df + -a
#                             added "last"-output to system-status 
#                             fixed network typo "iip"
#                             added sg_map to device info
#                             changed snmpwalk: added -Cc (continue when not increasing)
#                             changed snmpwalk fsc:  >ServerView + complete 231-tree
#                             changed snmpd.conf retrievel from cut -f 9  to cut -d "/" (better for different date presentations)
#                             changes /sys collection: not collecting /sys/kernel (due to infinit time)
#  csh   0.993-3 (22.12.2010) changed sysstat-collect execution to be done w/in extra bash (due to complex cron-job lines)
#                             changed order of license + size in rpm-package info
#  csh   0.993-4 (27.12.2010) changed snmpcollection (-Cc dumps infinit w/ ServerView :-( )
#                             changes repository info to detailed (-d) for suse-zypper
#                             added info for loop-mounts in filesystem-section
#  csh   0.993-5 (16.01.2011) fixed sys-tgz-collection (echo * > ls -1) 
#  csh   0.993-6 (24.01.2011) fixed Repository-info (SLES does not know "zypper sl -d"
#                             added infos from sginfo, sg_scan, scsiinfo and scsi_id
#  csh   0.993-7 (24.01.2011) fixed sg_scan info
#                             added ServerView collection: 1st test if all agents are running; if not: start'em
#  csh   0.993-8 (12.10.2011) added list of available sysstat-files to info-file
#  csh   0.994-1 (02.01.2014) changed kernel version usage (SYSTYPE) to take care of 3.x.x (zero-padded based on x.y....= 0x0y (int))
#                             added gurb2 support (incl. /etc/default)
#                             added dev-mapper infos /dev /dev/block
#                             changed lvm-cmd-order
#                             changed dev-mapper-cmd-order
#                             changed output: no trailing ...'s
#                             added support for systemd
#  csh   0.994-2 (02.01.2014) changed disk collection (no /dev/mapper entries)
#  csh   0.994-3 (02.01.2014) added support for parted (GPT)
#  csh   0.994-4 (06.01.2014) changed boot-collection: base=/boot ; no lilo investigation any more
#  csh   0.994-5 (13.01.2014) added systemd-dirs
#  csh   0.994-6 (27.01.2014) added seperator in multi-info-files
#                             added (s)gdisk-infos
#  csh   0.994-7 (09.01.2015) added -s (script) to "parted"  due to stop-issues in some cases
#  csh   0.994-8 (22.09.2018) changed boot section to collect all grub*-files under /etc
#                             fixed and improved systemd infos

