e8b6c5e1ac1a49220c80b3a7665bfb4ddd0f8384
[bootimage-initfs.git] / etc / hardware_output.sh
1 #!/bin/ash
2
3 . /etc/library.sh
4
5
6 disk_list() {
7
8         DISK_COUNT=0
9
10         for i in `ls -1 /proc/ide/hd* | grep "/proc/ide/hd[a-z]$" 2>> /tmp/stderr.log`
11         do
12                 dev=`basename $i`
13                 size=`disk_size $dev`
14                 model=`cat /proc/ide/$dev/model | head -1`
15                 echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
16                 echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
17                 echo "DISK_${DISK_COUNT}_MODEL=\"$model\""
18                 DISK_COUNT=`expr ${DISK_COUNT} + 1`
19         done
20
21         for i in `ls -1 /dev/sd* | grep "/dev/sd[a-z]$"`
22         do
23                 dev=`basename $i`
24                 exists=`cat /proc/partitions | awk '{print  $4}' | grep $dev`
25                 if [ "${exists}" != "" ]
26                 then
27                         size=`disk_size $dev`
28                         model=`cat /sys/block/$dev/device/model`
29                         vendor=`cat /sys/block/$dev/device/vendor`      
30                         scsi="${scsi} ### $dev:$size:$vendor $model"
31
32                         echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
33                         echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
34                         echo "DISK_${DISK_COUNT}_MODEL=\"$vendor $model\""
35                         DISK_COUNT=`expr ${DISK_COUNT} + 1`
36                 fi
37         done
38         echo "DISK_COUNT=\"${DISK_COUNT}\""
39 }
40
41 disk_size() {
42         dev=$1
43         
44         size=`cat /proc/partitions | awk '{ print $3, $4 }' | grep "${dev}$" | awk '{print $1}'`
45         echo $size
46 }
47
48 network_list() {
49
50         NIC_COUNT=0
51
52         for dev in `ls -1 /sys/class/net`
53         do
54                 driver=""
55                 pci_dev=""
56                 dev_vend=""
57                 dev_dev=""
58
59                 hwaddr=`cat /sys/class/net/${dev}/address`
60
61                 if [ "${dev}" = "lo" ]
62                 then
63                     continue
64                 fi
65                 echo "NIC_${NIC_COUNT}_DEV=\"${dev}\""
66                 echo "NIC_${NIC_COUNT}_HWADDR=\"${hwaddr}\""
67
68                 if [ -e /sys/class/net/${dev}/driver ]
69                 then
70                         driverlnk=`readlink /sys/class/net/${dev}/driver`
71                         driver=`basename $driverlnk`
72                 fi
73
74                 if [ -e /sys/class/net/${dev}/device ]
75                 then
76                         dev_vend=`cat /sys/class/net/${dev}/device/vendor`
77                         dev_dev=`cat /sys/class/net/${dev}/device/device`
78                 fi
79                 #driver=`basename ${driverlnk}`
80                 echo "NIC_${NIC_COUNT}_DRIVER=\"${driver}\""
81                 echo "NIC_${NIC_COUNT}_PCIDEV=\"${dev_dev}\""
82                 echo "NIC_${NIC_COUNT}_PCIVENDOR=\"${dev_vend}\""
83
84                 NIC_COUNT=`expr ${NIC_COUNT} + 1`
85         done
86
87         if [ -e /dev/ipmi0 ]
88         then
89                 for i in 1 2 3 4 5 6 7 8 9
90                 do
91                         ipmitool lan print $i > /tmp/ipmi.lan.out 2>&1
92                         IPMI_MAC=`grep ^MAC /tmp/ipmi.lan.out | awk '{print $4}'`
93         
94                         if [ "${IPMI_MAC}" != "" ]
95                         then
96                                 echo "NIC_${NIC_COUNT}_DEV=\"ipmi${i}\""
97                                 echo "NIC_${NIC_COUNT}_HWADDR=\"${IPMI_MAC}\""
98                                 echo "NIC_${NIC_COUNT}_DRIVER=\"ipmi\""
99                                 echo "NIC_${NIC_COUNT}_PCIDEV=\"ipmi\""
100                                 echo "NIC_${NIC_COUNT}_PCIVENDOR=\"ipmi\""
101                 
102                                 NIC_COUNT=`expr ${NIC_COUNT} + 1`
103                         fi
104                 done
105         fi
106         echo "NIC_COUNT=\"${NIC_COUNT}\""
107 }
108
109 pci_list() {
110         PCI_COUNT=0
111         for i in /sys/bus/pci/devices/*
112         do
113                 busid=`basename $i`
114                 device=`cat ${i}/device`
115                 vendor=`cat ${i}/vendor`
116                 irq=`cat ${i}/irq`
117                 class=`cat ${i}/class`
118
119                 echo "PCI_${PCI_COUNT}_BUSID=\"$busid\""
120                 echo "PCI_${PCI_COUNT}_DEVICE=\"$device\""
121                 echo "PCI_${PCI_COUNT}_VENDOR=\"$vendor\""
122                 echo "PCI_${PCI_COUNT}_CLASS=\"$class\""
123                 echo "PCI_${PCI_COUNT}_IRQ=\"$irq\""
124
125                 PCI_COUNT=`expr ${PCI_COUNT} + 1`
126         done
127
128         echo "PCI_COUNT=\"${PCI_COUNT}\""
129 }
130
131 /usr/bin/act_dmi        > /tmp/hardware.dat
132 disk_list               >> /tmp/hardware.dat
133 network_list    >> /tmp/hardware.dat
134 pci_list                >> /tmp/hardware.dat
135