Commit a13479c2 authored by Vitaly Lipatov's avatar Vitaly Lipatov

distr_info: add support for get info about arch, bus size, memory size, base os name

parent b266ad97
......@@ -329,6 +329,112 @@ elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
esac
fi
get_base_os_name()
{
local DIST_OS
# Resolve the os
DIST_OS=`uname -s | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_OS" in
'sunos')
DIST_OS="solaris"
;;
'hp-ux' | 'hp-ux64')
DIST_OS="hpux"
;;
'darwin' | 'oarwin')
DIST_OS="macosx"
;;
'unix_sv')
DIST_OS="unixware"
;;
'freebsd' | 'openbsd' | 'netbsd')
DIST_OS="freebsd"
;;
esac
echo "$DIST_OS"
}
get_arch()
{
local DIST_ARCH
# Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_ARCH" in
'amd64' | 'ia32' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64')
DIST_ARCH="x86"
;;
'ia64' | 'ia-64')
DIST_ARCH="ia64"
;;
'ip27' | 'mips')
DIST_ARCH="mips"
;;
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
DIST_ARCH="ppc"
;;
'pa_risc' | 'pa-risc')
DIST_ARCH="parisc"
;;
'sun4u' | 'sparcv9')
DIST_ARCH="sparc"
;;
'9000/800')
DIST_ARCH="parisc"
;;
armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then
DIST_ARCH="armel"
else
DIST_ARCH="armhf"
fi
;;
esac
echo "$DIST_ARCH"
}
get_bit_size()
{
local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now...
DIST_BIT=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64"
;;
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
# BIT="64"
# ;;
'sun4u' | 'sparcv9') # Are all sparcs 64?
DIST_BIT="64"
;;
# '9000/800')
# DIST_BIT="64"
# ;;
*) # In any other case default to 32
DIST_BIT="32"
;;
esac
echo "$DIST_BIT"
}
get_memory_size() {
local detected=0
local DIST_OS=$(get_base_os_name)
if [ $DIST_OS = "macosx" ]
then
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ]
then
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ]
then
detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected
}
case $1 in
-p)
# override DISTRIB_ID
......@@ -341,6 +447,10 @@ case $1 in
echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name"
echo "-a - print hardware architecture"
echo "-b - print size of arch bit (32/64)"
echo "-m - print system memory size (in MB)"
echo "-o - print base os name"
echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)"
echo "-s [SystemName] - print name of distro for build system (like in the package release name)"
......@@ -352,6 +462,18 @@ case $1 in
-d)
echo $DISTRIB_ID
;;
-a)
get_arch
;;
-b)
get_bit_size
;;
-m)
get_memory_size
;;
-o)
get_base_os_name
;;
-v)
echo $DISTRIB_RELEASE
;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment