#! /bin/sh
# /bin/sh (rather than bash) means things like "type -p" may fail, and {,} does not work
# $Header: /usr/groups/linux/ownfiles/RCS/CL-make-ownfiles,v 1.146 2024/06/13 09:25:26 pb22 Exp $
#
# sudo find . -type d ! -perm -020 -ls -exec chmod g+w {} \;
# sudo find . -type d ! -group sysadmin -ls -exec chgrp sysadmin {} \;
# This file is either copied over as a long argument to "ssh" if sucking
# from a trusted server, or is installed on a client and run as root at a
# suitable time, saving its output to a suitable directory so that it can be
# collected by ownfiles, e.g. if run with "-a"

# TODO: no modprobe /lib or /boot on macmino06

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/kerberos/bin:$PATH:/usr/StorMan
export PATH

# Find a group to use. "sysadmin" may not be available on non LDAP machines
groups="sysadmin"	# could try staff wheel
for g in $groups;
do	case "$group" in
	'')	getent group $g 2> /dev/null | grep -s $g > /dev/null && group=$g;
	esac
done
case "$group" in '') group=1000;; esac

rmdiropt=--ignore-fail-on-non-empty
 cpp="cp -p"
 cpf="$cpp --parents"
 lastopt=-x
 dfofts="-x none -x nfs -T"
 libboot="/lib /boot"

timeout="timeout-fork 15"
type timeout-fork > /dev/null 2>&1 || timeout=
type timeout > /dev/null 2>&1 && timeout="timeout -k 1 10"

# Decide whether to use rpm or dpkg (or both!)
# Some systems may cross build, e.g. debian systems with alien
pkg=
test -r /etc/issue && case "`cat /etc/issue`" in
*CentOS*|*Fedora*|*S[uU]SE*)	pkg=rpm;;
*Ubuntu*|*Debian*)		pkg=dpkg;;
*)	if type dpkg-query > /dev/null 2>&1; then pkg=dpkg; fi
	if type rpm > /dev/null 2>&1; then pkg="rpm$pkg"; fi
	;;
esac
proc=proc
# test -d /compat/linux/$proc -a ! -d /$proc/net && proc=compat/linux/$proc
test -d /compat/linux/$proc && proc=compat/linux/$proc
test ! -r /etc/issue -a -r /etc/motd && case "`cat /etc/motd`" in
*FreeBSD*|*FREEBSD*)
	# FreeBSD?
	rmdiropt=
	cpf="$cpp"
	lastopt=
	dfopts="-t nonfs"
	# find --printf needs to be HACKed
	nofindprintf=y
	# fix: /$proc/{meminfo,modules,interrupts,partitions}
	freebsdfdisk=y
esac
if test ! -r /etc/issue -a ! -r /etc/motd -a \( -r /private/etc/launchd.conf -o  -r /private/etc/com.apple.screensharing.agent.launchd \)
then	# Mac OSX
	# find --printf needs to be HACKed
        nofindprintf=y
	rmdiropt=
	cpf="$cpp"
	lastopt=
	dfopts="-t nonfs"
	libboot=
fi

case "$1" in
"-")	: use STDOUT;;
*)	f=/var/log/cl-make-ownfiles
	touch $f; chmod o= $f; chgrp $group $f; chown root $f
	exec > $f
esac

sorte=LANG=C

XE=/opt/xensource/bin/xe
IPTABLESTABLES="filter nat mangle raw security"
# Different per dom0
xerawops="host-cpu-info task-list"
# Just do next 3 on pool masters
xeuuidops="host-param-list cd-list"
xexmlops=pool-dump-database
xexmrawops="host-list host-license-view vm-list#params=all vm-vif-list cd-list console-list host-cpu-list host-crashdump-list vm-list network-list pbd-list pif-list pool-list sm-list sr-list template-list vbd-list#params=all vdi-list#params=all vif-list vlan-list host-get-system-status-capabilities#--multiple vm-cd-list#--multiple vm-crashdump-list#--multiple vm-disk-list#--multiple vm-disk-list#--multiple#vdi-params"

cd /
# Use "/bin/ls" in case "ls" is an alias.
# Use ls to select just the files which actually exist.
FILES=`/bin/ls -d boot/grub/menu.lst boot/grub/grub.cfg* boot/grub/device.map var/log/yum-sudo var/log/mcelog* var/log/svn.log var/arpwatch/arp*.dat var/lib/arpwatch/arp*.dat var/lib/ndpmon/*.xml var/spool/cron 2> /dev/null`

EXCLUDE="--exclude=etc/sane.d --exclude=etc/puppet/.git --exclude=etc/puppet/modules"
getfacl=`/bin/ls -d etc/user-config/bundles etc/user-config/patches etc/user-config/hostid 2> /dev/null`
Files=`/bin/ls -d etc/passwd etc/shadow etc/sudoers etc/hosts etc/group etc/.aumixrc etc/cron* etc/anacrontab etc/yum* etc/*.conf* etc/*/*.conf* run/*.conf* run/*/*.conf* boot/*.conf boot/*/*.conf etc/*.pool etc/initiatorname.iscsi etc/iscsi/initiatorname.iscsi etc/HOSTNAME etc/X11/XF86Config etc/X11/XF86Config-DS etc/X11/xorg.conf etc/XF86Config etc/XF86Config.ed etc/XF86Config.samp etc/XF86Config.auto etc/auto.* etc/devfsd.local etc/iptables.obj etc/exports etc/fstab etc/hdparm.samp etc/initdefault etc/inittab etc/init/ etc/issue* etc/*allow etc/aliases etc/motd etc/motd.tail samp/mbr-hda samp/mbr-hdc samp/mbr-hde samp/mbr-hdg samp/mbr-sda samp/mbr-sdb etc/ntp.drift var/run/dmesg.boot var/lib/ntp/drift var/lib/ntp/ntp.drift etc/ntp.keys etc/ntp/drift etc/ntp/keys etc/pcmcia/config.opts etc/pcmcia/network.opts etc/pnpdump.samp etc/ppp/config etc/ppp/options etc/printers.local etc/raidtab etc/raidtab.full etc/raidtab.nofsb etc/raidtab.dontcare etc/raidtab.nopsb etc/raidtab.nopsb2 etc/raidtab.samp etc/raidtab.normal etc/raidtab.failed etc/raidtab.devfs etc/raidtab.devfs.failed etc/rc.local etc/rc.d/rc.local etc/*.d etc/*/*.d usr/share/pam-configs etc/ssh/ssh_config etc/ssh/sshd*_config etc/ssh/ssh_host_*pub etc/user-config etc/vmware/config etc/vmware/locations etc/iwconfig.128.232.96.111 etc/iwconfig.128.232.12.15 etc/config-info/private/attrs etc/devperms.login etc/devperms.logout etc/xfs.config etc/anaconda-ks.cfg etc/securetty etc/lvm/backup etc/lvm/archive etc/lvm/.cache etc/bluetooth/pin etc/sysconfig etc/sysconfig/networking/devices/ etc/sysconfig/networking/profiles/default/ etc/httpd/conf* etc/xen selinux-cl/ opt/condor*/LOCAL/condor_config.local var/lib/condor/condor_config.local etc/condor/condor_config etc/selinux/*conf* etc/selinux/targeted/contexts/files/file_contexts.local etc/my.cnf etc/log.d/conf/logwatch.conf etc/xensource-inventory etc/xensource var/named/chroot/etc etc/phpMyAdmin/config.inc.php etc/php5/apache2/*php* etc/network etc/netplan etc/firestarter var/lib/exim4/ etc/postfix/ etc/apache2/auth/*password* usr/share/libnss-ldap/ldap.conf etc/ldap usr/wiki/*wiki/cgi-bin etc/hostname etc/mailname etc/default etc/ufw lib/ufw var/lib/ufw etc/apache2 usr/lib/cgi-bin var/lib/alternatives var/log/cl-pam_ssh var/log/fail2ban.log var/log/cl-isidle.log var/log/pm-suspend.log var/log/Xorg.0.log etc/update-manager/release-upgrades root/.ssh/authorized_keys root/anaconda-ks.cfg root/install.log* etc/apt etc/apparmor* usr/share/X11/xorg.conf.d etc/alternatives etc/dhcp/dhclient.conf etc/puppet etc/autofs/include var/log/HOSTS lib/udev/rules.d etc/resolvconf/resolv.conf.d/base etc/centos-release-upstream boot/efi/EFI/*/*.cfg boot/efi/ADD boot/efc/EFI/*/*.CSV usr/local/lib/mgls*/licenses/*license.dat* var/lib/hotcrp/conf/options.php var/lib/logrotate/status var/lib/hotcrp-options-* etc/rsyslog.d  etc/letsencrypt/renewal/ etc/*/*.cfg etc/systemd/system/*/override.conf etc/machine-id etc/bind/named.conf.local etc/bind/named.conf.options etc/request-tracker5/RT_SiteConfig.d/*.pm etc/exim4/conf.d/*/*_rt  2> /dev/null | sort -u`

# If a "real" CUPS server, dump /etc/cups
test -s /etc/cups/printers.conf && Files="$Files etc/cups"
case "$Files" in
*" etc/cups")	test -d etc/cups/ssl && EXCLUDE="$EXCLUDE --exclude=etc/cups/ssl";;
esac

Symb=`/bin/ls 2> /dev/null etc/X11/X`

 MISC7=anaconda-ks.cfg
 MISC8=quotas.dat

 samp=samp

 FDISKS=`/bin/ls -d /dev/hd[abcdefgh] /dev/sd[abcdefghijklmnopqrst] /dev/xvd[abcdef] /dev/da? 2> /dev/null`
 NVMES="nvme0 nvme1"
 PROCS=`/bin/ls -d dev/sndstat $proc/chkconfig $proc/sysconfigs $proc/sensors $proc/bus/usb/devices $proc/cmdline $proc/cpuinfo $proc/devices $proc/dma $proc/driver/nvram $proc/glxinfo $proc/ide-cs Xproc/ide/hda/media Xproc/ide/hda/model Xproc/ide/hda/settings Xproc/ide/hdb/media Xproc/ide/hdb/model Xproc/ide/hdb/settings Xproc/ide/hdc/media Xproc/ide/hdc/model Xproc/ide/hdc/settings Xproc/ide/hdd/media Xproc/ide/hdd/model Xproc/ide/hdd/settings $proc/ide/hde/media $proc/ide/hde/settings $proc/ide/hdf/media $proc/ide/hdf/model $proc/ide/hdf/settings $proc/ide/hdg/media $proc/ide/hdg/model $proc/ide/hdg/settings $proc/ide/hdh/media $proc/ide/hdh/model $proc/ide/hdh/settings $proc/ide/hdr/model $proc/ioports $proc/iptables $proc/ip6tables $proc/isapnp $proc/lvms $proc/mdstat $proc/misc $proc/mtrr $proc/partitions $proc/pci $proc/ldap-state $proc/xm-dmesg $proc/xm-info $proc/xm-list $proc/xm-log $proc/xm-vnet-list $proc/scsi/FastTraks $proc/scsi/aic7xxxs $proc/scsi/scsi $proc/smart-log $proc/version $proc/xinetds2 $proc/bus/usb/drivers $proc/swaps $proc/net/ipt_recent/* $proc/acpi/battery/BAT*/info $proc/acpi/battery/BAT*/state $proc/mounts $proc/sys/xen/* 2> /dev/null`
 PROCSC=`/bin/ls -d $proc/scsi/aic7xxx/0 $proc/scsi/aic7xxx/1 $proc/scsi/ncr53c8xx/0 $proc/scsi/ncr53c8xx/1 $proc/scsi/BusLogic/0 $proc/scsi/BusLogic/1 $proc/scsi/aha1542/0 $proc/scsi/aha1542/1 $proc/scsi/ide-scsi/0 $proc/scsi/ide-scsi/1 2> /dev/null`
 PREPS=`find /etc -name \*-preP`
 IDES=`/bin/ls /dev/null /$proc/ide/via /$proc/ide/piix 2> /dev/null`

 # echo FILES is $FILES, Files is $Files, getfacl is $getfacl, PROCS is $PROCS, PROCSC is $PROCSC, PREPS is $PREPS. 1>&2
 basedir=${BASEDIR-/var/ownfiles}
 umask 2
 rm -rf $basedir
 mkdir -p $basedir || exit
   cd $basedir || exit
   mkdir -p $proc
   case "$proc" in comp*) mkdir -p proc; rmdir $proc; ln -s ../../proc $proc;; esac
   mkdir -p $proc/scsi/{aic7xxx,aha1542,BusLogic,ncr53c8xx} $proc/ide/hd{a,b,c,d} $proc/bus/usb $proc/driver $proc/asound dev etc $samp

   # /sys reports all file sizes padded to block boundaries: tar and cpio pad with nulls, so use cp
   $cpf -r /sys/block/*/md . 2> /dev/null
   $cpf -r /sys/power . 2> /dev/null
   $cpf -r /sys/block/*/alignment_offset /sys/block/*/queue/logical_block_size  /sys/block/*/queue/physical_block_size . 2> /dev/null
   # Proc
   test -e /$proc/asound/sndstat && $cpf /$proc/asound/sndstat .;\
   test -e /$proc/asound/oss/sndstat && $cpf /$proc/asound/oss/sndstat .;\
   # SIGH! As of F7, cp (like tar) uses stat to find the file size (0 for proc)
   f=`echo $PROCS $PROCSC $PREPS | sed 's/ .*//'`
   case "$f" in ?*) test -r /$f && $cpf /$f .;; esac
   if test -s $f
   then for f in $PROCS $PROCSC $PREPS; do test -r /$f && $cpf /$f .; done
   else for f in $PROCS $PROCSC $PREPS; do test -r /$f && d=`echo ./$f | sed 's/\/[^\/]*$//'` && mkdir -p $d && cat /$f > $f; done
   fi
   (cd proc
      test -e /$proc/meminfo && grep Total /$proc/meminfo > meminfo
      test -x /homes/pb/pl/ldap-state.pl && perl /homes/pb/pl/ldap-state.pl > ldap-stat
      test -x /usr/sbin/3c59x && /usr/sbin/3c59x  -sq > 3c59x
      test ! -s 3c59x && rm -f 3c59x
      test -e /$proc/rtc && cat /$proc/rtc | sed '/rtc_d/d;/rtc_t/d;' > rtc
      test -e /$proc/modules && grep -v autoclean /$proc/modules > modules
      test -r /dev/audio && touch /dev/audio
      test -e /$proc/interrupts && cat /$proc/interrupts | sed 's/:[ 0-9]* /:   /;s/   + / + /;s/XT-PIC/       &/;s/IO-APIC-edge/ &/;/CPU0/d' > interrupts
      cat $IDES > ide-cs
      case "`echo ide/*/settings`" in *"*"*) : OK;; *) chmod a+r ide/*/settings; esac
      test -r /$proc/scsi/aic7xxx/0 -a -r /homes/pb/pl/aic7xxx.pl && /homes/pb/pl/aic7xxx.pl > scsi/aic7xxxs
      test -e /$proc/partitions && sed 's/ [0-9][0-9]* [0-9][0-9]* [0-9][0-9]* [0-9][0-9]* .*//' < /$proc/partitions >| partitions
      test -x /sbin/iptables  && for tab in $IPTABLESTABLES; do echo "# Table $tab"; /sbin/iptables -t $tab -L -n -v | sed 's/^ *[0-9][0-9]*[KMG]* *[0-9][0-9]*[KMG]* //;s/ [0-9]*[KMG]* packets*, [0-9]*[KMG]* bytes*//'; done > iptables 2>&1
      test -x /sbin/ip6tables && /sbin/ip6tables -L -n -v | sed 's/^ *[0-9][0-9]*[KMG]* *[0-9][0-9]*[KMG]* //;s/ [0-9]*[KMG]* packets*, [0-9]*[KMG]* bytes*//' > ip6tables
      test -d /$proc/scsi/FastTrak && cat /$proc/scsi/FastTrak/* > FastTraks
      test -r aic7xxx/0 && (echo /Interrupts:/d; echo w) | ed - aic7xxx/0
   cd ..
   test -d compat && rm -rf compat
   )

   # samp
   # using shell redirection, it fails, so use dd

   # https://confluence.clazzes.org/display/KH/SSHFP+records%3A+DNS+providing+public+ssh+host+keys
   ( type ssh-keygen > /dev/null 2>&1 && ssh-keygen -r '' < /dev/null 2> /dev/null; # dom0 asks for key
     I="1"; for ALGO in _rsa _dsa _ecdsa _ed25519 ;
     do if [ -f /etc/ssh/ssh_host${ALGO}_key ] ; then echo " IN SSHFP $I 1" $(awk '{print $2}' /etc/ssh/ssh_host${ALGO}_key.pub | openssl base64 -d -A | openssl sha1   |cut -f2 -d' '); 
           echo | openssl sha256 2>&1 | grep 'openssl:Error' > /dev/null || echo " IN SSHFP $I 2" $(awk '{print $2}' /etc/ssh/ssh_host${ALGO}_key.pub | openssl base64 -d -A | openssl sha256 |cut -f2 -d' ');
	 fi; I=$(($I+1)); done) 2>&1 | sort -u > $samp/ssh-keygen-r 2>&1 &
   case "$freebsdfdisk" in
   '') fdisk -l -u $FDISKS 2> /dev/null | dd of=$samp/fdisk.dat 2> /dev/null;;
   *) for f in $FDISKS; do echo == $f ==;fdisk $f;done >>$samp/fdisk.dat 2>&1;;
   esac
   type aa-status>/dev/null 2>&1 && aa-status > $samp/aa-status 2>&1 &
   type apt	> /dev/null 2>&1 && apt list --upgradable > $samp/apt-list--upgradable 2>&1 &
   type boot_info_script > /dev/null 2>&1 && boot_info_script $samp/boot_info_script > $samp/boot_info_script-log 2>&1 &
   type bootinfoscript   > /dev/null 2>&1 && bootinfoscript   $samp/bootinfoscript   > $samp/bootinfoscript-log   2>&1 &
   type brctl	> /dev/null 2>&1 && brctl show > $samp/brctl-show &
   type cl-isidle>/dev/null 2>&1 && (cl-isidle --set; cl-isidle --run;cat /etc/cron.d/cl-isidle-halt) > $samp/cl-isidle 2>&1 &
   type efibootmgr>/dev/null 2>&1 && efibootmgr -v > $samp/efibootmgr 2>&1 &
   type ethtool	> /dev/null 2>&1 && ethtool eth0 > $samp/ethtool-eth0 2>&1 &
   type gdisk	> /dev/null 2>&1 && for f in $FDISKS; do gdisk -l $f 2>&1 < /dev/null; done 2>&1 | dd > $samp/gdisk.dat 2> /dev/null
   type hdparm	> /dev/null 2>&1 && for f in $FDISKS; do hdparm -I $f 2>&1; done 2>&1 | dd > $samp/hdparm-I 2> /dev/null
   type lpstat	> /dev/null 2>&1 && lpstat -a 2>&1 | sed 's/ accepting requests since .*//' | eval $sorte sort -o $samp/lpstat-a &
   type lpstat	> /dev/null 2>&1 && lpstat -h localhost -a 2>&1 | sed 's/ accepting requests since .*//' | eval $sorte sort -o $samp/lpstat-a-local &
   type lsb_release>/dev/null 2>&1&&lsb_release -a > $samp/lsb_release-a 2>&1 &
   type lsof	> /dev/null 2>&1 && $timeout lsof 2>&1 | grep LIST > $samp/lsof &
   type ntpdc	> /dev/null 2>&1 && ntpdc -p > $samp/ntpdc-p &
   type ntpq 	> /dev/null 2>&1 && ntpq  -p > $samp/ntpq-p  &
   type nvme	> /dev/null 2>&1 && for f in $NVMES; do test -e /dev/$f && nvme error-log /dev/$f log > $samp/nvme-error-log-$f 2>&1; done
   type racadm	> /dev/null 2>&1 && racadm getconfig -f $samp/racadm-conf > $samp/racadm-conf.out 2>&1 &
   type service	> /dev/null 2>&1 && service --status-all > $samp/service--status-all 2>&1
   type sysctl	> /dev/null 2>&1 && (sysctl hw.machine hw.model hw.ncpu machdep.cpu.vendor machdep.cpu.brand_string machdep.cpu.features machdep.cpu.extfeatures)  2>&1 | grep -v 'is an unknown key' > $samp/sysctl-cpu 2>&1
   type sysctl	> /dev/null 2>&1 && (sysctl hw.physmem hw.usermem hw.memsize) 2>&1 | grep -v 'is an unknown key' > $samp/sysctl-mem 2>&1
   type sysctl	> /dev/null 2>&1 && (sysctl kern.ostype kern.osrelease kern.osrevision kern.version kern.osversion) 2>&1 | grep -v 'is an unknown key' > $samp/sysctl-os 2>&1
   type tasksel	> /dev/null 2>&1 && tasksel --list-tasks > $samp/tasksel--list-tasks 2>&1 &
   type hostnamectl>/dev/null 2>&1 && hostnamectl > $samp/hostnamectl 2>&1 &

   c=ua;	type $c > /dev/null 2>&1 && $c status > $samp/$c-status 2>&1
   c=ua;	type $c > /dev/null 2>&1 && $c status --format=json > $samp/$c-status.json 2>&1
   c=fail2ban-client; type $c > /dev/null 2>&1 && $c status sshd > $samp/fail2ban-status-sshd 2>&1
   c=netplan;	type $c > /dev/null 2>&1 && $c get > $samp/$c-get 2>&1
   c=cl-add-rpms;type $c> /dev/null 2>&1 && $c -a -n> $samp/$c 2> /dev/null
   c=cl-flatten F=/named.conf d=/var/named/chroot/etc/named.d D=/var/named/chroot/etc s=-s
   		type $c > /dev/null 2>&1 && test -r $d$F && $c    $d$F > $samp$F 2>&1
   		type $c > /dev/null 2>&1 && test -r $D$F && $c    $D$F > $samp$F 2>&1
   		type $c > /dev/null 2>&1 && test -r $d$F && $c $s $d$F > $samp$F$s 2>&1
   		type $c > /dev/null 2>&1 && test -r $D$F && $c $s $D$F > $samp$F$s 2>&1
   c=lspci;	type $c > /dev/null 2>&1 && test -r /$proc/bus/pci -o -r /sys/bus/pci && for o in '' -n -v -vt -vv -mm; do $c $o>$samp/$c$o; done
   c=lscpu;	type $c > /dev/null 2>&1 && $c > $samp/$c
   c=uptime;	type $c > /dev/null 2>&1 && $c > $samp/$c
   c=pciconf;	type $c > /dev/null 2>&1 && for o in -lv -lc; do $c $o>$samp/$c$o; done
   c=ufw;	type $c > /dev/null 2>&1 && $c show added> $samp/$c-show-added 2> /dev/null
   c=ufw;	type $c > /dev/null 2>&1 && $c status verbose>        $samp/$c 2> /dev/null
   # type sysctl && sysctl -a > $samp/sysctl-a &
   # (netstat -lt; netstat -lu) > $samp/netstat-l 2>&1 &
   # (netstat -ltn; netstat -lun) > $samp/netstat-ln 2>&1 &
   # (netstat -l  -f inet; netstat -l  -f inet6) > $samp/netstat-l 2>&1 &
   # (netstat -ln -f inet; netstat -ln -f inet6) > $samp/netstat-ln 2>&1 &
   (netstat -l  -A inet; netstat -l  -A inet6) > $samp/netstat-l 2>&1 &
   (netstat -ln -A inet; netstat -ln -A inet6) > $samp/netstat-ln 2>&1 &
   case `echo  /sys/block/md*/md/mismatch_cnt` in *md[0-9]*) more /sys/block/md*/md/mismatch_cnt > $samp/md-mismatch_cnt;; esac &
   test -e /var/log/apache2 && for h in server-info ldap-status server-status; do wget -O $samp/apache-$h -o $samp/apache-$h-err --no-check-certificate https://127.0.0.1/$h & done
   df $dfopts    > $samp/df 2>&1 &
   df $dfopts -i > $samp/df-i 2>&1 &
   df $dfopts -T > $samp/df-T 2>&1 &
   test -r /etc/krb5.keytab && (klist -ketK 2> /dev/null  | grep . || ktutil -k /etc/krb5.keytab list) > $samp/klist-ketK 2>&1 &
   last $lastopt | egrep '^reboot|^runlevel' > $samp/last-r &
   for o in i a; do last -$o > $samp/last-$o; done &
   ls -l /core* > $samp/ls-core 2> /dev/null &
   # Expected only on omnipotent servers
   test -e /a/eldo-voln && ls -sR1 /a/eldo-voln/xene-SR-* /a/eldo-volp/xene-SR-* /a/echo-volt/xene-SR-*  > $samp/ls-filer-vol-xene-SR 2> /dev/null &
   # FreeBSD does not have printf
   case "$nofindprintf" in
   '') find /etc /var /usr /sbin /bin $libboot -xdev -type l -printf '%TY-%Tm-%Td+%TH:%TM %p %l\n' | egrep -v ' (/etc/ssl/certs|/usr/lib.*/mono|/usr/lib.*/openoffice|/usr/lib.*/python|/usr/lib.*/sane|/usr/share|/usr/src|/var/lib.*/defoma/gs.d/dirs/fonts|/var/lib.*/python)' | eval $sorte sort -k 2 > $samp/ln-s 2>&1 &
   ;;
   *) find /etc /var /usr /sbin /lib /bin /boot -xdev -type l -ls | egrep -v ' (/etc/ssl/certs|/usr/lib.*/mono|/usr/lib.*/openoffice|/usr/lib.*/python|/usr/lib.*/sane|/usr/share|/usr/src|/var/lib.*/defoma/gs.d/dirs/fonts|/var/lib.*/python)' | eval $sorte sort -k 9 > $samp/ln-s 2>&1 &
   esac
   find /usr/local/bin /usr/bin /bin /usr/sbin /sbin -perm -4000 -ls > $samp/setuid 2>&1 &
   # FC:
   test -f /var/lib/ntp/drift && $cpp /var/lib/ntp/drift $samp/ntp-drift-x && mv $samp/ntp-drift-x $samp/ntp-drift
   # SUSE:
   test -f /var/lib/ntp/drift/ntp.drift && $cpp /var/lib/ntp/drift/ntp.drift $samp/ntp-drift-x && mv $samp/ntp-drift-x $samp/ntp-drift
   f=/usr/share/logwatch/default.conf/logwatch.conf
     test -r $f && $cpp $f $samp/.
   f=/var/cache/cups/remote.cache
     test -r $f && $cpp $f $samp/cups-remote.cache
   type dmidecode > /dev/null 2>&1 && dmidecode > $samp/dmidecode 2>&1 &
   f=/global/src/etc/amd.conf/autofs-type.pl
     test -r $f && $f > $samp/autofs-type &
   type docker > /dev/null 2>&1 && (
   	for c in ps;
	do cmd=$(echo $c | tr '_' ' '); eval docker $cmd > $samp/docker-$c 2>&1;
	done
   ) &
   type zpool > /dev/null 2>&1 && (
   	for c in  list history_-il iostat_-v status status_-v get_-p_-H_all events_-v_-H;
	do cmd=$(echo $c | tr '_' ' '); eval zpool $cmd > $samp/zpool-$c 2>&1;
	done
   ) &
   type nvidia-smi > /dev/null 2>&1 && (
   	for c in -q;
	do cmd=$(echo $c | tr '_' ' '); eval nvidia-smi $cmd > $samp/nvidia-smi-$c 2>&1;
	done
   ) &
   type ipmitool > /dev/null 2>&1 && (
 	test -e /dev/ipmi0 -o -e /dev/ipmi/0 || modprobe ipmi_devintf 
 	test -e /dev/ipmi0 -o -e /dev/ipmi/0 || modprobe ipmi_si > /dev/null 2>&1
 	test -e /dev/ipmi0 -o -e /dev/ipmi/0 && (
		for T in lan-print lan6-print chassis-status mc-info mc-getenables session-info-all fru sel-elist; do
			ipmitool $(echo $T | sed 's/-/ /g') > $samp/ipmi-$T 2>&1 &
		done
		for C in user sensor;
		do (O=$samp/ipmi-$C; ipmitool $C list > $O 2>&1 || 
		        (read a; read a; read a) < $O || rm -f $O) &
		done
		for c in 0 1 2 3 4 5 6 7 8 9 10 11 14 15 # 12 and 13 are reserved
		do (O=$samp/ipmi-lan-$c; ipmitool lan print $c > $O 2>&1 ||
		        (read a; read a; read a) < $O || rm -f $O) &
		   (O=$samp/ipmi-lan6-$c; ipmitool lan6 print $c > $O 2>&1 ||
		        (read a; read a; read a) < $O || rm -f $O) &
		   (O=$samp/ipmi-chan-$c; ipmitool channel info $c > $O 2>&1 ||
		        (read a; read a; read a) < $O || rm -f $O) &
		   (O=$samp/ipmi-channel-getaccess-$c; ipmitool channel getaccess $c > $O 2>&1 ||
		        (read a; read a; read a) < $O || rm -f $O) &
		   for C in user;
		   do (O=$samp/ipmi-$C-list-$c; ipmitool $C list $c > $O 2>&1 ||
		        (read a; read a; read a) < $O || rm -f $O) &
		   done
		done
		wait
	)
   ) &
   type tw_cli > /dev/null 2>&1 && (
 	tw_cli show > $samp/3ware
	for c in c0 c1;
	do grep -w ^$c $samp/3ware > /dev/null && tw_cli /$c show all > $samp/3ware-$c &
	done
   )
   test -r /var/log/cron && grep -w MAIL /var/log/cron	    > $samp/cron-MAIL 2>&1 &
   type smoltSendProfile > /dev/null 2>&1 && smoltSendProfile -p > $samp/smolt 2>&1 &
   type blkid	> /dev/null 2>&1&&blkid 2>&1|eval $sorte sort>$samp/blkid &
   type lshw	> /dev/null 2>&1 && lshw		    > $samp/lshw 2>&1 &	# lshw -C display 
   type lsblk	> /dev/null 2>&1 && lsblk		    > $samp/lsblk 2>&1 &
   type racadm	> /dev/null 2>&1 && racadm getsysinfo	    > $samp/racadm-sysinfo 2>&1 &
   type getsebool>/dev/null 2>&1 && getsebool -a	    > $samp/sebool-a 2>&1 &
   type semodule> /dev/null 2>&1 && semodule -l 2>&1	|cat> $samp/semodule-l &
   type ifconfig> /dev/null 2>&1 && ifconfig -a 2>&1	|cat> $samp/ifconfig-a &
   type ip	> /dev/null 2>&1 && ip address 2>&1	|cat> $samp/ip-address &
   type ip	> /dev/null 2>&1 && ip -brief address 2>&1|cat>$samp/ip-brief-address &
   type arcconf > /dev/null 2>&1 && for X in "GETSTATUS 1" "GETCONFIG 1" "GETLOGS 1 stats tabular" "GETLOGS 1 events tabular"; do echo ====== $X; arcconf $X; done 2>&1 |cat> $samp/arcconf-1 &
   type semanage > /dev/null 2>&1 && for X in login user port interface translation node fcontext; do echo ====== $X; semanage $X -l; done 2>&1 |cat> $samp/semanage-l &
   # SIGH ! Loading eeprom on swarm and ziggy (FC5 and F8) kills the machine.  HACK!
   test ! -e /opt/dell/srvadmin/omsa/bin/dcicfg32 && test ! -e /opt/dell/srvadmin/omil/ &&
        type decode-dimms.pl > /dev/null 2>&1 && (test -e /sys/module/eeprom || modprobe eeprom) && decode-dimms.pl > $samp/decode-dimms.pl &
        type decode-dimms > /dev/null 2>&1 && (test -e /sys/module/eeprom || modprobe eeprom) && decode-dimms > $samp/decode-dimms &
   # Should yield a result when first file found.
   if (test -e /$proc/xen/capabilities && grep control_d /$proc/xen/capabilities > /dev/null) ||
      (test -e /$proc/xen -a -f /$proc/xen && grep control_d /$proc/xen > /dev/null)
   then
     test -x /usr/sbin/xm && /usr/sbin/xm info  > $samp/xm-info
     test -x /usr/sbin/xm && /usr/sbin/xm list  > $samp/xm-list
     test -x /usr/sbin/xm && /usr/sbin/xm dmesg > $samp/xm-dmesg
     test -x /usr/sbin/xm && /usr/sbin/xm log   > $samp/xm-log
     test -x /usr/sbin/xm && /usr/sbin/xm vnet-list > $samp/xm-vnet-list 2>&1
   fi
   if test -e $XE
   then
     H=$($XE host-list | grep ^uuid | sed 's/.* //')
     for op in $xerawops;  do $XE $(echo $op|sed 's/#/ /g')> $samp/xe-$op; done
     if test -e /XE_MASTER
     then	for op in $xexmlops;  do $XE $op file-name=$samp/xe-T-$op; <$samp/xe-T-$op sed 's/>/>#/g' | tr '#' '\12' > $samp/xe-$op; rm -f $samp/xe-T-$op; done
		# Backup metadata to /a/eldo-volp/xene-SR-1/87654321-4321-1234-000$n-0123456789ab/METADATA/metadata
		f=/usr/bin/cl-xe-backup-metadata; test -e $f&& SUDO= $f -a>$samp/xe-backup-metadata 2>&1 &
     		for op in $xexmrawops;  do $XE $(echo $op|sed 's/#/ /g')> $samp/xe-$op; done
     		for op in $xeuuidops;do for u in $H;do $XE $op uuid=$u;done>$samp/xe-$op;done
     elif test ! -e /XE_SLAVE
     then	for op in $xexmlops; do echo neither /XE_MASTER nor /XE_SLAVE >  $samp/xe-$op; done
     fi
   fi
   test -x /etc/rc.scripts/smart-log.pl && /etc/rc.scripts/smart-log.pl > $samp/smart-log &
   # Next line's "|cat" is for SELinux
   test ! -x /etc/rc.scripts/smart-log.pl && type cl-admin >/dev/null 2>&1 && type smartctl >/dev/null 2>&1 && cl-admin smart-log 2>&1 | cat> $samp/smart-log &
   test -r /root/$MISC7 && $cpp /root/$MISC7 $samp/$MISC7
   test -r /etc/rc.scripts/quota.sum && grep quota /etc/fstab > /dev/null && repquota -a -F vfsv0 | /etc/rc.scripts/quota.sum > $samp/$MISC8
   test -r /usr/X11R6/lib/X11/fs/config && $cpp /usr/X11R6/lib/X11/fs/config $samp/xfs.config
   test -e /sbin/chkconfig&&/sbin/chkconfig --list| eval $sorte sort> $samp/chkconfig
   test -e /usr/bin/sensors && LANG=C sensors > $samp/sensors 2>& 1 &
   test -e /usr/bin/cpuid && cpuid > $samp/cpuid 2>& 1 &
   test -e /usr/bin/synclient && synclient -l > $samp/synclient 2>& 1 &
   # Only FC5 and later support: status=noxfer
   type uuencode > /dev/null 2>&1 && for f in hda hdb hde hdg sda sdb; do grep -w $f /$proc/partitions > /dev/null 2>&1 && (dd if=/dev/$f bs=512 count=63 | bzip2 -9 |  uuencode $f > $samp/mbr-$f) 2>&1 | sed '/ records /d;/ copied, /d' 1>&2 ; done
   # FC6 Xsessions terminate: XAUTHORITY=`ls -t /var/gdm/:0.Xauth /var/run/xauth/* /etc/X11/xdm/authdir/authfiles/* /var/lib/kdm/authfiles/* /etc/X11/xdm-auth._* 2> /dev/null | head -1` DISPLAY=:0 $timeout glxinfo > $samp/glxinfo &
   # Next line's "|cat" is for SELinux
   test -e /$proc/partitions && sed '/^major/d;s/ [0-9][0-9 -]*$//;s/.* //;/[0-9]$/d;/md/d;/^lvm/d;/^$/d' < /$proc/partitions | while read d; do test -b /dev/$d && /sbin/sfdisk -d /dev/$d; done 2>&1 |cat> $samp/sfdisk.dat &
   if test -x /etc/rc.scripts/dump2fs.pl; then /etc/rc.scripts/dump2fs.pl> $samp/dump2fs.dat 2>&1; fi &
   case "$pkg" in *rpm*)
      #if test -r /var/log/rpmpkgs; then  eval $sorte sort /var/log/rpmpkgs > $samp/rpm.dat; else rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n' |  eval $sorte sort > $samp/rpm.dat; fi &
      rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n' |  eval $sorte sort > $samp/rpm.dat &
      rpm -qa --qf '%{NAME}.%{ARCH}\n' | eval $sorte sort > $samp/rpm.datn &
   esac
   case "$pkg" in *dpkg*)
 	 ( COLUMNS=200 dpkg-query  -l > $samp/dpkg-l
	   <$samp/dpkg-l sed -n 's/^ii *//p' | sed 's/ .*//' > $samp/dpkg-l-ii) &
   esac
   type debsums  > /dev/null 2>&1 && debsums > $samp/debsums &
   type pkg_info > /dev/null 2>&1 && pkg_info -acdDijkoprRs > $samp/pkg_info &
   type pkg      > /dev/null 2>&1 && pkg  info> $samp/pkg_info &
   type apt-mark > /dev/null 2>&1 && apt-mark showhold > $samp/apt-mark_showhold &
   # more /etc/sysconfig/* > $samp/sysconfigs < /dev/null
   type getfacl > /dev/null 2>&1 && case "$getfacl" in ?*) (cd / && getfacl $getfacl) > $samp/getfacl;; esac
   type lsmod  > /dev/null 2>&1 && lsmod > $samp/lsmod

   test -e /$proc/lvm && ls -f /dev/vg??* > /dev/null 2>&1 && (/usr/opt/etc/lv-pe; echo ==============; /usr/opt/etc/vg-pv; more `find /$proc/lvm -type f`) | sed 's+Global.*\\(IOP version: [0-9]*\\) .*+\\1+;s/::::::::::::::/==============/' > proc/lvms
   test -r dev/nvram && (od -x dev/nvram > dev/nvram-x 2> /dev/null && mv dev/nvram-x dev/nvram)

   find proc -group daemon -exec chgrp $group {} \; 1>&2 &
   find . -depth -type d ! -name . ! -name proc ! -name dev ! -name samp -exec rmdir $rmdiropt {} \; & 1>&2

   # Various bits done in the background, so check they've all finished.
   wait
   tar czf - $EXCLUDE . -C / $FILES $Files $lattr $Sym
   cd ..
 rm -rf $basedir
 exit 0
