Support x86info
[grml-hwinfo.git] / grml-hwinfo
1 #!/bin/sh
2 # Filename:      grml-hwinfo
3 # Purpose:       get hardware information
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Die Jun 12 18:44:00 CEST 2007 [mika]
8 ################################################################################
9 # Notice: Some ideas have been taken from
10 # http://club.black.co.at/david/hwdb/infodump
11 # by David Schmitt <david@schmitt.edv-bus.at>
12 ################################################################################
13
14 # variables
15 UNAME="$(uname -r)"
16 PN="$(basename $0)"
17 VERSION='0.3'
18
19 [ -n "$INFOFILE" ] || INFOFILE='info.tar.bz2'
20
21
22 if [ "$(id -u)" != 0 ] ; then
23    NOTROOT=1
24    echo "Notice: you are running $PN without root permissions. Not all information will be collected."
25    echo
26 fi
27
28 # check whether a binary is available and executable
29 exectest() {
30 if [ -z "$1" ] ; then
31    echo 'Usage: exectest <binary>'>&2
32    return 1
33 else 
34    test -e "$(which $1)" && return 0 || return 1
35 fi
36 }
37
38 # echo a list of all disks and their size
39 # taken from http://cvs.debian.org/fai/lib/disk-info
40 diskandsize() {
41     local isdisk major minor blocks device suffix
42     while read major minor blocks device suffix; do
43         isdisk=1
44         # skip ide cdrom
45         [ -f /proc/ide/$device/media ] && grep -q cdrom /proc/ide/$device/media && isdisk=0
46         [ "$isdisk" -eq 1 ] && echo "$device $blocks"
47     done
48 }
49
50 list_disks() {
51 # print only every second entry; used by disk_info
52 i=0
53 for ent in $@; do
54     if [ "$i" -eq 0 ]; then
55         echo $ent
56         i=1
57     else
58         i=0
59     fi
60 done
61 }
62
63 disk_info() {
64     # the variable holds a space separated list of devices and their block size
65     device_size=`grep -E ' cciss/c.d.$| ida/c.d.$| rd/c.d.$| hd.$| sd.$|/disc$' /proc/partitions | diskandsize`
66     # a list of all local disks, without size
67     disklist=`list_disks $device_size`
68 }
69
70 echo "Running grml-hwinfo ${VERSION} - collecting hardware information."
71 echo "Please send feedback, bugreports, feature requests to Michael Prokop <mika@grml.org>."
72 echo ""
73
74 mkdir info || exit -1
75 (
76   cd info
77
78   echo "Generating hardware information report using file $INFOFILE."
79   echo "This might take a few seconds/minutes. Please be patient..."
80
81 # some sysinfo
82   date > date
83   if [ -r /etc/grml_version ] ; then
84      cat /etc/grml_version > grml_version
85   fi
86   if [ -r /etc/debian_version ] ; then
87      cat /etc/debian_version > debian_version
88   fi
89   uname -a > uname
90
91 # disks / devices
92   [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi > scsi
93   (lspci; lspci -n) | sort > lspci
94   [ -r /proc/bus/pnp ] && lspnp > lspnp
95   [ -r /proc/bus/usb ] && lsusb > lsusb
96   cat /proc/partitions > partitions
97   find /proc/ide/ -name geometry -exec grep . {} \; > proc_ide 2>/dev/null
98   df -h > df 2>/dev/null
99   for i in free lsmod mount lsdev ; do
100       exectest $i  && $i > $i
101   done
102
103 # proc stuff
104   for i in cpuinfo interrupts cmdline devices dma fb iomem ioports \
105     mdstat meminfo modules mtrr pci version ; do
106     [ -r /proc/$i ] && cat /proc/$i > proc_$i
107   done
108   exectest sysdump  && sysdump > sysdump 2>sysdump.error
109 # for sysnet in `find /proc/sys/net/*/ -type f | grep -v flush`; do cat $sysnet >> sysnet ; done
110
111 # log
112   dmesg > dmesg.cur
113
114 # hwinfo
115   exectest discover && discover -v --type-summary --enable-bus all > discover 2> discover.2
116   exectest hwinfo   && hwinfo log=hwinfo
117   exectest x86info  && x86info > x86info 2>x86info.2
118
119 # net stuff
120   exectest ifconfig  && ifconfig -v -a  > ifconfig
121   exectest ip        && ip route show   > ip_route
122   exectest ip        && ip link show    > ip_link
123   exectest route     && route -n        > route
124
125 # software
126   if exectest dpkg ; then
127      dpkg --get-selections   > dpkg_get_selections
128      COLUMNS=300 dpkg --list > dpkg_list
129      COLUMNS=1000 dpkg -l linux-image-$UNAME | grep linux-image-$UNAME | tr -s ' ' > running_kernel
130   fi
131
132 # powermanagement
133   exectest laptop-detect  && laptop-detect 1>/dev/null 2>/dev/null && echo "0" > laptop_detected
134   exectest acpi_available && acpi_available && cat /proc/acpi/info > acpi_info
135   exectest acpi && acpi > acpi 2> acpi.error && acpi -v > acpi.version
136   [ -r /proc/apm/ ] && apm > apm
137
138 # kernel stuff
139   if [ -r /proc/config.gz ] ; then
140      zcat /proc/config.gz > kernelconfig
141   else
142      [ -r /boot/config-$UNAME ] && cat /boot/config-$UNAME > kernelconfig
143   fi
144
145 # X stuff
146   if [ -n "${DISPLAY}" ] ; then
147      exectest xviddetect  && xviddetect         > xviddetect
148      exectest xvidtune    && xvidtune -show     > xdivtune
149      exectest xrandr      && xrandr             > xrandr
150      exectest xdpyinfo    && xdpyinfo           > xdpyinfo
151      X -version        1> x_version 2>&1
152   fi
153
154   for i in Xorg.0.log Xorg.7.log Xorg.8.log XFree86.0.log XFree86.7.log XFree86.8.log dmesg ; do
155       cp /var/log/$i log_$i 2>/dev/null
156   done
157
158   cp /etc/X11/xorg.conf    xorg.conf    2>/dev/null
159   cp /etc/modules          modules      2>/dev/null
160   cp /etc/X11/XF86Config-4 XF86Config-4 2>/dev/null
161
162 # not available:
163 # sysinfo -class device -level all
164
165 # as root:
166 if [ -n "$NOTROOT" ] ; then
167    echo "not running as root" > root
168 else
169    echo "running as root" > root
170    disk_info
171    exectest sfdisk     && sfdisk -d > sfdisk 2>sfdisk.error
172    exectest ddcprobe   && ddcprobe  > ddcprobe
173    exectest dmidecode  && dmidecode > dmidecode
174    for disk in $disklist; do
175       exectest smartctl  && smartctl -i /dev/$disk >> smartctl
176       exectest hdparm    && hdparm -iv /dev/$disk  >> hdparm
177       exectest fdisk     && fdisk -lu /dev/$disk   >> fdisk 2>>fdisk.error
178       exectest parted    && parted -s /dev/$disk print >> parted
179       LC_ALL=C file -s /dev/$disk?* | grep -v ": empty" >> file_disk
180    done
181 fi
182 )
183
184 # finally create the tarball
185 if [ -f "$INFOFILE" ] ; then
186    DATE="$(date +%Y%m%d_%H%M%S)"
187    NEW_INFOFILE="info_$DATE.tar.bz2"
188    echo
189    echo "Warning:  $INFOFILE exists already, using $NEW_INFOFILE instead.">&2
190    tar jcf $NEW_INFOFILE info/ && rm -Rf info/
191    INFOFILE="$NEW_INFOFILE" # adjust variable for final info message
192 else
193    tar jcf $INFOFILE info/ && rm -Rf info/
194 fi
195
196 echo
197 [ -r "$INFOFILE" ] && echo "$INFOFILE ($(ls -ahl $INFOFILE | awk '{print $5}')) has been generated."
198 echo
199
200 ## END OF FILE##################################################################