Identifying Distro Data
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
We've hit this issue in inxi, and now I'm hitting it again in sgfxi as I add Ubuntu / Arch support: how to get tight identification of distros.

Following is the data I've collected so far. Note that default system settings are more important than possible extra data that does not come with the default system setup.

Arch Linux
Defaults:
/etc/issue
:: Code ::

/etc/arch-release
:: Code ::

Optional:
/etc/lsb-release
:: Code ::


Debian Sid / Testing
Defaults:
/etc/issue
:: Code ::
Debian GNU/Linux squeeze/sid \n \l

/etc/debian_version
:: Code ::
squeeze/sid

Optional:
/etc/lsb-release
:: Code ::
N/A


Debian Stable / Lenny
Defaults:
/etc/issue
:: Code ::
Debian GNU/Linux 5.0 \n \l

/etc/debian_version
:: Code ::
5.0

Optional:
/etc/lsb-release
:: Code ::
N/A


Debian Stable / Etch
Defaults:
/etc/issue
:: Code ::
 \n \l

/etc/debian_version
:: Code ::

Optional:
/etc/lsb-release
:: Code ::
N/A



Mepis
Notes: Mepis is now built on a Debian Stable base, with extra packages added in from Testing/Sid, and Mepis repos.
Defaults:
/etc/issue
:: Code ::
Debian GNU/Linux 5.0 \n \l

/etc/debian_version
:: Code ::
5.0.3

/etc/lsb-release
:: Code ::
DISTRIB_ID=MEPIS
DISTRIB_RELEASE=8.0
DISTRIB_CODENAME=lenny
DISTRIB_DESCRIPTION="MEPIS 8.0 (upgradable from Debian etch)"


Ubuntu
Note: thankfully this information is the same for Kubuntu, and I assume the other *buntus, but that needs to be confirmed, since it's different for Linux Mint.
Defaults:
/etc/issue
:: Code ::
Ubuntu 9.10 \n \l

/etc/debian_version
:: Code ::
squeeze/sid

/etc/lsb-release
:: Code ::
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"


Linux Mint
Note: Linux Mint tracks current Ubuntus, so the Release and Codename have to be handled explicitly t o match to ubuntu release handling.
Defaults:
/etc/issue
:: Code ::
Linux Mint 8 Helena - Main Edition \n \l

/etc/debian_version
:: Code ::
squeeze/sid

/etc/lsb-release
:: Code ::
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=8
RELEASE_NOTES_URL=http://www.linuxmint.com/rel_helena.php
DISTRIB_CODENAME=helena
DISTRIB_DESCRIPTION="Linux Mint 8 Helena - Main Edition"

Back to top
aus9
Status: Assistant
Joined: 21 Sep 2008
Posts: 358
Location: Australia
Reply Quote
hi

I am not a programmer but line 5198 onwards may be of interest?

rkhunter.cvs.sourceforge.net/viewvc/rkhunter/rkhunter/files/rkhunter?revision=1.384&view=markup

:: Quote ::
rkh_dat_get_os_info() {

#
# This function obtains information about the local computer
# system. This is then written into the rkhunter.dat file
# using a simple 'keyword:<value>' format. The OSNAME and
# ARCH values are not important, but are simply used to check
# whether they have changed since RKH was last run.
#
# Obtaining the OSNAME is somewhat tricky. There is no sure
# way of finding the information, so we have to use some tricks
# to locate the correct file. First we look for certain specific
# O/S release files, and then at the /etc/release file, but not
# if it is a link. Next we look for a generic /etc/*-release
# file, again not as a link. This should find most O/S versions.
# Overall this should also save users having to ask us to support
# their O/S. In other cases, we will have to ask what file does
# contain their O/S release information.
#

ARCH=""
OSNAME=""
RELEASE=""

if [ -n "${OS_VERSION_FILE}" ]; then
REL_FILES="${RKHROOTDIR}${OS_VERSION_FILE}"
else
REL_FILES="${RKHROOTDIR}/etc/system-release ${RKHROOTDIR}/etc/lsb-release ${RKHROOTDIR}/etc/debian_version ${RKHROOTDIR}/etc/slackware-version ${RKHROOTDIR}/var/ipcop/general-functions.pl ${RKHROOTDIR}/etc/lunar.release ${RKHROOTDIR}/etc/ROCK-VERSION ${RKHROOTDIR}/etc/GoboLinuxVersion ${RKHROOTDIR}/etc/kanotix-version ${RKHROOTDIR}/etc/sidux-version ${RKHROOTDIR}/etc/knoppix-version ${RKHROOTDIR}/etc/zenwalk-version ${RKHROOTDIR}/etc/release ${RKHROOTDIR}/etc/*-release"
fi

RKH_LSB_SEEN=0

for FNAME in ${REL_FILES}; do
test ! -f "${FNAME}" && continue

if [ "${FNAME}" = "${RKHROOTDIR}/etc/system-release" ]; then
RKH_IN_LSB=0
RELEASE=$FNAME
OSNAME=`cat ${FNAME}`
break
elif [ ! -h "${FNAME}" ]; then
RELEASE=$FNAME

RKH_IN_LSB=0

case "${RELEASE}" in
${RKHROOTDIR}/etc/lsb-release)
RKH_IN_LSB=1
RKH_LSB_SEEN=1
OSNAME=`grep '^DISTRIB_DESCRIPTION=' ${RELEASE} | sed -e 's/DISTRIB_DESCRIPTION=//' | tr -d '"'`
;;
${RKHROOTDIR}/etc/gentoo-release)
if [ -h ${RKHROOTDIR}/etc/make.profile ]; then
OSNAME="Gentoo `ls -l ${RKHROOTDIR}/etc/make.profile 2>/dev/null | sed -e 's;^.*/\([^/]*/[^/]*\)$;\1;' | tr '/' ' '`"
else
OSNAME="Gentoo"
fi
;;
${RKHROOTDIR}/var/ipcop/general-functions.pl)
OSNAME=`grep 'version *=' ${RELEASE} | head -n 1`
;;
${RKHROOTDIR}/etc/debian_version)
OSNAME="Debian `cat ${RELEASE}`"
;;
${RKHROOTDIR}/etc/GoboLinuxVersion)
OSNAME="GoboLinux `cat ${RELEASE}`"
;;
${RKHROOTDIR}/etc/knoppix-version)
OSNAME="Knoppix `cat ${RELEASE}`"
;;
${RKHROOTDIR}/etc/zenwalk-version)
OSNAME="Zenwalk `cat ${RELEASE}`"
;;
*)
OSNAME=`awk '/^[ ]*[^ ]/ { print $0 }' ${RELEASE} | head -n 1`
;;
esac


#
# Strip out any leading blanks and tabs from the O/S version.
#

test -n "${OSNAME}" && OSNAME=`echo ${OSNAME}`


#
# If we have a release file but it seems to be blank,
# and we are not looking at the LSB release file, then
# we take a look for the first non-blank line. We
# then, again, strip out any leading blanks and tabs.
#

if [ $RKH_IN_LSB -eq 0 -a -z "${OSNAME}" ]; then
OSNAME=`awk '/^[ ]*[^ ]/ { print $0 }' ${RELEASE} | head -n 1`
OSNAME=`echo ${OSNAME}`
fi

test -n "${OSNAME}" && break
fi
done


if [ -z "${OSNAME}" ]; then
RELEASE=""

if [ -d "${RKHROOTDIR}/var/smoothwall" ]; then
OSNAME="Smoothwall Linux"
RELEASE="${RKHROOTDIR}/var/smoothwall"
elif [ -n "`which sorcery 2>/dev/null | grep -v ' '`" -a -n "`which gaze 2>/dev/null | grep -v ' '`" ]; then
OSNAME="Source Mage Linux"
fi
fi

case "${OPERATING_SYSTEM}" in
SunOS)
ARCH=`uname -p 2>/dev/null`
;;
FreeBSD|DragonFly)
ARCH=`sysctl -n hw.machine_arch 2>/dev/null`
OSNAME=`uname -v 2>/dev/null | cut -d' ' -f1,2`
;;
OpenBSD)
OSNAME="OpenBSD `uname -r 2>/dev/null`"
;;
Darwin)
OSNAME=`sw_vers 2>/dev/null | grep '^ProductName:' | sed -e 's/ProductName:[ ]*//'`
OSNAME="${OSNAME} `sw_vers 2>/dev/null | grep '^ProductVersion:' | sed -e 's/ProductVersion:[ ]*//'`"
# OSNAME="${OSNAME} `sysctl kern.version 2>/dev/null | sed -e 's/^kern.version = //' | cut -d: -f1`"

if [ -n "`sysctl -a 2>/dev/null | egrep '^(hw\.optional\.x86_64|hw\.optional\.64bitops|hw\.cpu64bit_capable).*1$'`" ]; then
OSNAME="${OSNAME} (64-bit capable)"
fi
;;
AIX)
ARCH=`uname -p 2>/dev/null`
OSNAME="IBM AIX `oslevel 2>/dev/null`"
;;
IRIX*)
OSNAME="${OPERATING_SYSTEM} `uname -r 2>/dev/null`"
;;
esac


#
# If we still have no O/S version information, then as a last
# resort we will look to see if an 'issue' file exists or use
# whatever is in the LSB release file. We test these last because
# they are not necessarily reliable in providing the O/S version.
#
# However, if an O/S has been found, but it seems to be just a
# version number, then we look for the first word in the 'issue'
# file and prepend that. Hopefully, it will make sense!
#

if [ -z "${OSNAME}" ]; then
if [ -f "${RKHROOTDIR}/etc/issue" ]; then
OSNAME=`awk '/^[ ]*[^ ]/ { print $0 }' ${RKHROOTDIR}/etc/issue | head -n 1`
OSNAME=`echo ${OSNAME}`
test -n "${OSNAME}" && RELEASE="${RKHROOTDIR}/etc/issue"
fi

if [ $RKH_LSB_SEEN -eq 1 -a -z "${OSNAME}" ]; then
OSNAME=`awk '/^[ ]*[^ ]/ { print $0 }' ${RKHROOTDIR}/etc/lsb-release | head -n 1`
OSNAME=`echo ${OSNAME}`
test -n "${OSNAME}" && RELEASE="${RKHROOTDIR}/etc/lsb-release"
fi
elif [ -n "`echo \"${OSNAME}\" | grep '^[0-9.][0-9.]*$'`" ]; then
if [ -f "${RKHROOTDIR}/etc/issue" ]; then
RKHTMPVAR=`awk '/^[ ]*[^ ]/ { print $1 }' ${RKHROOTDIR}/etc/issue | head -n 1`

test -n "${RKHTMPVAR}" && OSNAME="${RKHTMPVAR} ${OSNAME}"
fi
fi


#
# If some things have still not been set, then set them now.
#

test -z "${ARCH}" && ARCH=`uname -m 2>/dev/null`
test -z "${OSNAME}" && OSNAME="`uname` `uname -r 2>/dev/null`"


return
}

Back to top
Display posts from previous:   

All times are GMT - 8 Hours