#!/usr/bin/perl -w
# Copyright (c) 2003 International Business Machines
# Common Public License Version 0.5 (see COPYRIGHT)

# Snapshot system config
# Note: for now we honor but ignore most of the following options since
# we grab everything we can all the time.  These options really have meaning:
#
# -c		Create a compressed tar file snap.tar.gz from /tmp/ibmsupt
# -d dir	Identifies the optional output dir (/tmp/ibmsupt is the default)
# -o device	Write compressed image to this device (default ./snap.tar.gz)
# -r		Remove snap output from /tmp/ibmsupt
#
# These are accepted but ignored:
#
# -a		Gather all system config
# -A		Gather tty info
# -b		Gather SSA info
# -D		Gather saved dump information
# -f		Gather file system information
# -g		Gather lslpp -hBc output (installed packages?)
# -G		Include predefined ODM files with -g
# -i		Gather installation debug VPD
# -k		Gather kernel info
# -l		Gather programming language info
# -L		Gather LVM info
# -n		Gather NFS info
# -N		Suppress check for free space
# -p		Gathers printer information
# -s		Gathers SNA info
# -S		Includes sec files in general information collected with -g
# -t		Gathers TCP/IP information
# -v component	Be verbose
#
#
$::me = "snap";

$< == 0 or die "$::me: snap must be executed as root\n";

# $::outdir = "/tmp/ibmsupt";   No use for this yet.
$::outfile = "snap.tar.gz";	# in the working dir.

@::snap_paths = (
  "var/log/messages",
  "var/log/scanoutlog.*",
  "proc/bus/pci",
  "proc/cmdline",
  "proc/cpuinfo",
  "proc/device-tree",
  "proc/devices",
  "proc/dma",
  "proc/filesystems",
  "proc/fs",
  "proc/ide",
  "proc/interrupts",
  "proc/iomem",
  "proc/ioports",
  "proc/loadavg",
  "proc/locks",
  "proc/meminfo",
  "proc/misc",
  "proc/modules",
  "proc/mounts",
  "proc/net",
  "proc/partitions",
  "proc/pci",
  "proc/ppc64",
  "proc/scsi",
  "proc/slabinfo",
  "proc/stat",
  "proc/swaps",
  "proc/sys",
  "proc/sysvipc",
  "proc/uptime",
  "proc/version",
  "dev/nvram",
  "etc/yaboot.conf",
);

sub snap_all_paths {
    my ($outfile) = @_;
    open(TAR, "| tar -C / -T - -c -v -z -f " . $outfile) or die "$::me: cannot run tar: $!\n";
    foreach my $path (@::snap_paths) {
	print TAR $path, "\n" if -r '/' . $path;
    }
    close(TAR);
}

snap_all_paths($::outfile);
print "$me: output written to $::outfile\n";
