Added support for getting drive SNs
[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                 disk_sn=`disk_serialno $dev`
16  
17                 echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
18                 echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
19                 echo "DISK_${DISK_COUNT}_MODEL=\"$model\""
20                 echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
21                 DISK_COUNT=`expr ${DISK_COUNT} + 1`
22         done
23
24         for i in `ls -1 /dev/sd* | grep "/dev/sd[a-z]$"`
25         do
26                 dev=`basename $i`
27                 exists=`cat /proc/partitions | awk '{print  $4}' | grep $dev`
28                 if [ "${exists}" != "" ]
29                 then
30                         size=`disk_size $dev`
31                         model=`cat /sys/block/$dev/device/model`
32                         vendor=`cat /sys/block/$dev/device/vendor`      
33                         disk_sn=`disk_serialno $dev`
34                         scsi="${scsi} ### $dev:$size:$vendor $model"
35
36                         echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
37                         echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
38                         echo "DISK_${DISK_COUNT}_MODEL=\"$vendor $model\""
39                         echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
40                         DISK_COUNT=`expr ${DISK_COUNT} + 1`
41                 fi
42         done
43
44         for i in `ls -1 /dev/nvme[0-9]+n[0-9]+$/"`
45         do
46                 dev=`basename $i`
47                 exists=`cat /proc/partitions | awk '{print  $4}' | grep $dev`
48                 if [ "${exists}" != "" ]
49                 then
50                         size=`disk_size $dev`
51                         model=`cat /sys/block/$dev/device/model`
52                         vendor=`cat /sys/block/$dev/device/vendor`      
53                         disk_sn=`disk_serialno $dev`
54                         scsi="${scsi} ### $dev:$size:$vendor $model"
55
56                         echo "DISK_${DISK_COUNT}_DEV=\"$dev\""
57                         echo "DISK_${DISK_COUNT}_SIZE=\"$size\""
58                         echo "DISK_${DISK_COUNT}_MODEL=\"$vendor $model\""
59                         echo "DISK_${DISK_COUNT}_SN=\"${disk_sn}\""
60                         DISK_COUNT=`expr ${DISK_COUNT} + 1`
61                 fi
62         done
63
64
65         echo "DISK_COUNT=\"${DISK_COUNT}\""
66 }
67
68 disk_serialno() {
69         dev=$1
70
71         sn=`hdparm -i /dev/${dev} | grep SerialNo | cut -d, -f3 | cut -d= -f2`
72         echo $sn
73 }
74
75 disk_size() {
76         dev=$1
77         
78         size=`cat /proc/partitions | awk '{ print $3, $4 }' | grep "${dev}$" | awk '{print $1}'`
79         echo $size
80 }
81
82 network_list() {
83
84         NIC_COUNT=0
85
86         for dev in `ls -1 /sys/class/net`
87         do
88                 driver=""
89                 pci_dev=""
90                 dev_vend=""
91                 dev_dev=""
92
93                 hwaddr=`cat /sys/class/net/${dev}/address`
94
95                 if [ "${dev}" = "lo" ]
96                 then
97                     continue
98                 fi
99                 echo "NIC_${NIC_COUNT}_DEV=\"${dev}\""
100                 echo "NIC_${NIC_COUNT}_HWADDR=\"${hwaddr}\""
101
102                 if [ -e /sys/class/net/${dev}/driver ]
103                 then
104                         driverlnk=`readlink /sys/class/net/${dev}/driver`
105                         driver=`basename $driverlnk`
106                 fi
107
108                 if [ -e /sys/class/net/${dev}/device ]
109                 then
110                         dev_vend=`cat /sys/class/net/${dev}/device/vendor`
111                         dev_dev=`cat /sys/class/net/${dev}/device/device`
112                 fi
113                 #driver=`basename ${driverlnk}`
114                 echo "NIC_${NIC_COUNT}_DRIVER=\"${driver}\""
115                 echo "NIC_${NIC_COUNT}_PCIDEV=\"${dev_dev}\""
116                 echo "NIC_${NIC_COUNT}_PCIVENDOR=\"${dev_vend}\""
117
118                 NIC_COUNT=`expr ${NIC_COUNT} + 1`
119         done
120
121         if [ -e /dev/ipmi0 ]
122         then
123                 for i in 1 2 3 4 5 6 7 8 9
124                 do
125                         ipmitool lan print $i > /tmp/ipmi.lan.out 2>&1
126                         IPMI_MAC=`grep ^MAC /tmp/ipmi.lan.out | awk '{print $4}'`
127         
128                         if [ "${IPMI_MAC}" != "" ]
129                         then
130                                 echo "NIC_${NIC_COUNT}_DEV=\"ipmi${i}\""
131                                 echo "NIC_${NIC_COUNT}_HWADDR=\"${IPMI_MAC}\""
132                                 echo "NIC_${NIC_COUNT}_DRIVER=\"ipmi\""
133                                 echo "NIC_${NIC_COUNT}_PCIDEV=\"ipmi\""
134                                 echo "NIC_${NIC_COUNT}_PCIVENDOR=\"ipmi\""
135                 
136                                 NIC_COUNT=`expr ${NIC_COUNT} + 1`
137                         fi
138                 done
139         fi
140         echo "NIC_COUNT=\"${NIC_COUNT}\""
141 }
142
143 pci_list() {
144         PCI_COUNT=0
145         for i in /sys/bus/pci/devices/*
146         do
147                 busid=`basename $i`
148                 device=`cat ${i}/device`
149                 vendor=`cat ${i}/vendor`
150                 irq=`cat ${i}/irq`
151                 class=`cat ${i}/class`
152
153                 echo "PCI_${PCI_COUNT}_BUSID=\"$busid\""
154                 echo "PCI_${PCI_COUNT}_DEVICE=\"$device\""
155                 echo "PCI_${PCI_COUNT}_VENDOR=\"$vendor\""
156                 echo "PCI_${PCI_COUNT}_CLASS=\"$class\""
157                 echo "PCI_${PCI_COUNT}_IRQ=\"$irq\""
158
159                 PCI_COUNT=`expr ${PCI_COUNT} + 1`
160         done
161
162         echo "PCI_COUNT=\"${PCI_COUNT}\""
163 }
164
165 /usr/bin/act_dmi        > /tmp/hardware.dat
166 disk_list               >> /tmp/hardware.dat
167 network_list    >> /tmp/hardware.dat
168 pci_list                >> /tmp/hardware.dat
169