#! /bin/bash
# ARG @mac file


# format
# cf bootinventory.py
# here are the regex
# MACADDR_RE  = re.compile("^MAC Address:(.+)$") # MAC Address
# IPADDR_RE   = re.compile("^IP Address:(.+):([0-9]+)$") # IP Address:port
# MEM_INFO_RE = re.compile("^M:([0-9a-f]+),U:([0-9a-f]+)$") # lower / upper mem
# BUS_INFO_RE = re.compile("^B:([0-9A-Fa-f]+),f:([0-9A-Fa-f]+),v:([0-9A-Fa-f]+),d:([0-9A-Fa-f]+),c:([0-9A-Fa-f]+),s:([0-9A-Fa-f]+)$") # bus, dev, vendor, device, class, subclass
# DISKINFO_RE = re.compile("^D:\(hd([0-9]+)\):CHS\(([0-9]+),([0-9]+),([0-9]+)\)=([0-9]+)$") # number, CHS, size
# PARTINFO_RE = re.compile("^P:([0-9]+),t:([0-9a-f]+),s:([0-9]+),l:([0-9]+)$") # number, type, start, len
# BIOSINFO_RE = re.compile("^S0:([^\|]*)\|([^\|]*)\|([^\|]*)$") # 3 components : vendor, version, date
# SYSINFO_RE  = re.compile("^S1:([^\|]*)\|([^\|]*)\|([^\|]*)\|([^\|]*)\|([0-9A-F]{32})$") # 5 components : vendor, desc, ??, ??, UUID (16 hex chars)
# ENCLOS_RE   = re.compile("^S3:([^\|]*)\|([0-9]+)$") # vendor, type
# MEMSLOT_RE  = re.compile("^SM:([0-9]+):([0-9]+):([^:]*):([0-9]+):([0-9]+)$") # Size in MB, Form factor, Location, Type, Speed in MHZ
# NUMCPU_RE   = re.compile("^S4:([0-9]+)$") # CPU number
# FEATCPU_RE  = re.compile("^C:(.*)$") # CPU features, comma-separated
# FREQCPU_RE  = re.compile("^F:([0-9]+)$") # CPU frequency

# exemple
# IP Address:192.168.1.1:1001
# MAC Address:08:00:27:56:CE:93
# M:27f,U:7fbc0
# B:0,f:9,v:8086,d:269e,c:1,s:1
# B:0,f:10,v:80ee,d:beef,c:3,s:0
# B:0,f:18,v:8086,d:100e,c:2,s:0
# B:0,f:20,v:80ee,d:cafe,c:8,s:80
# B:0,f:28,v:8086,d:2668,c:4,s:3
# B:0,f:a0,v:1000,d:30,c:1,s:0
# D:(hd0):CHS(1024,255,63)=67108863
# P:0,t:7,s:2048,l:204800
# P:1,t:7,s:206848,l:66899968
# S0:innotek GmbH|VirtualBox|12/01/2006
# S1:innotek GmbH|VirtualBox|1.2|0|B6AA9DE902924638A95CAF0E26DEA5FA
# S3:innotek GmbH|86
# S4:1
# C:6,7,a,0,5,0,0,0,ff,fb,8b,7,47,65,6e,75,69,6e,65,49,6e,74,65,6c
# F:2498680

# note businfo cf http://prefetch.net/articles/linuxpci.html

. /usr/lib/pulse2/imaging-server/hooks/libkwartz-deploy

# supprime : de @mac
FILE=${1//:/};
cp $2 "$TFTPDIR/inventories/$FILE"
