File: task_inventory

package info (click to toggle)
fai 6.5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: sh: 6,774; perl: 5,665; makefile: 138
file content (74 lines) | stat: -rwxr-xr-x 2,616 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /bin/bash

# This script is part of FAI (Fully Automatic Installation)
# Copyright (c) 2013-2021 by Thomas Lange, Universitaet zu Koeln

# Inventory function, print hardware inventory, without too much configuration information

# The format is "key: value", both key and value may contain space, value may also contain :


inventory() {

    # activate all software RAID arrays
    echo DEVICE partitions > /etc/mdadm/mdadm.conf
    udevadm trigger

    cd /sys/class/dmi/id
    grep . {board_,bios_,product_}* 2>/dev/null| sed -e 's/:/: /'| grep -E -iv 'board_version|System Product Name|System Version|System Serial Number|123456789|To Be Filled|: Not |N/A|:[[:blank:]]+$'

    lscpu | grep 'Hypervisor vendor:'

    # memory, RAM
    mem=$(/usr/sbin/dmidecode -t memory | awk '( /Size:.*MB/ ) { x+=$2 } END { print x/1024 " GB"}')
    if [ "$mem" = "0 GB" ]; then
    mem=$(/usr/sbin/dmidecode -t memory | awk '( /Size:.*GB/ ) { x+=$2 } END { print x " GB"}')
    fi
    echo "RAMSIZE: $mem"

    ncpu=$(grep "model name" /proc/cpuinfo | sed -e 's/model name.*://' -e 's/(R)//g' -e 's/(TM)//g' -e 's/^[[:blank:]]\+//'|wc -l)
    cpuname=$(grep "model name" /proc/cpuinfo | head -1 | sed -e 's/model name.*://' -e 's/(R)//g' -e 's/(TM)//g' -e 's/^[[:blank:]]\+//')
    echo "CPU: $cpuname"
    echo "Number of CPU/Cores: $ncpu"

    nic1=$(ip route | awk '/^default/ {print $5}'|head -1)
    mac1=$(< /sys/class/net/$nic1/address)
    echo "Network interface: $nic1"
    echo "MAC address: $mac1"

    # print disk infos
    # $disklist needs to be set, normally done in fai-disk-info
    local d=1
    local dev cap model
    for dev in $disklist; do
	cap=$(smartctl -i /dev/$dev | grep Capacity: | grep -Po '\[.+?\]')
	if [ -z "$cap" ]; then # virtio devices
	    cap=$(blockdev --getsize64 /dev/$dev | numfmt --to=iec | sed -e 's/\(.\)$/ \1/')
	    cap="[$cap]"
	fi
	model=$(smartctl -i /dev/$dev | grep -E 'Product:|Device Model:|Model Number:'|sed -e 's/^.*://' -e 's/^ *//')
	echo "disk$d: $dev $cap $model"
	(( d++ ))
    done
    nvme list

    vga=$(lspci|grep ' VGA '| sed -e 's/.*VGA compatible controller://')
    echo "VGA controller: $vga"

    if [ -d /sys/firmware/efi ]; then
	efibootmgr
    fi

    echo List serial numbers of devices
    cd /sys/class/dmi/id
    grep . *_serial 2>/dev/null| sed -e 's/:/: /'| egrep -iv 'serial: 0123456789|: Not |N/A|:[[:blank:]]+$'
    lsblk -dno name,serial
}

if [ X$verbose = X1 ]; then
    inventory |& tee $LOGDIR/inventory.log
    echo "Inventory data written to $LOGDIR/inventory.log"
else
    inventory > $LOGDIR/inventory.log 2>&1
fi
task_savelog