#!/bin/sh

# physical processors
# logical processors
# model/family/stepping + name
# OC status

export LC_ALL=C

MACHINE=$(uname -m)
KERNEL=$(uname -r)
PHYSCPUS=$(($(cat /proc/cpuinfo | grep physical\ id[^a-z]*: | tail -1 | cut -f 2 -d :)+1))
CPUS=$(($(cat /proc/cpuinfo | grep processor[^a-z]*: | tail -1 | cut -f 2 -d :)+1))
NAME=$(cat /proc/cpuinfo | grep model\ name[^a-z]*: | tail -1 | cut -f 2 -d : | sed -e s/.//)
FAMILY=$(cat /proc/cpuinfo | grep cpu\ family[^a-z]*: | tail -1 | cut -f 2 -d : | sed -e s/.//)
MODEL=$(cat /proc/cpuinfo | grep model[^a-z]*: | tail -1 | cut -f 2 -d : | sed -e s/.//)
STEPPING=$(cat /proc/cpuinfo | grep stepping[^a-z]*: | tail -1 | cut -f 2 -d : | sed -e s/.//)
CLOCK=$(cat /proc/cpuinfo | grep cpu\ MHz[^a-z]*: | tail -1 | cut -f 2 -d :)

DISTRO=$(cat /etc/fedora-release 2> /dev/null)
GLIBC=$(rpm -q glibc 2> /dev/null | head -1)
BUILDER=$(cat /proc/version | sed -e "s/^[^(]*(//" | sed -e "s/).*//")
if [ -z "$DISTRO" ]; then
DISTRO=$(cat /etc/redhat-release 2> /dev/null)
fi
if [ -z "$DISTRO" ]; then
DISTRO=$(cat /etc/debian_version 2> /dev/null)
GLIBC=$(dpkg -l libc6 2>/dev/null | awk '/^ii/ { print $2 "-" $3 }')
BUILDER=$(cat /proc/version  | sed -e "s/^[^(]*([^(]*(//" | sed -e "s/).*//")
fi
if [ -z "$DISTRO" ]; then
DISTRO=$(cat /etc/arch-release 2> /dev/null)
BUILDER=$(cat /proc/version | sed -e "s/^[^(]*(//" | sed -e "s/).*//")
GLIBC=$(ls /lib/libc-*.so |  sed -e s/...\$// | cut -f 2 -d -)
fi
if [ -z "$DISTRO" ]; then
DISTRO=unknown linux distribution
fi

echo $MACHINE\; Linux $KERNEL by $BUILDER
echo $PHYSCPUS\; $FAMILY:$MODEL:$STEPPING\; \"$NAME\" processor\(s\)\; $CPUS logical processor\(s\)\; $CLOCK MHz
echo $DISTRO
echo $GLIBC

