#!/bin/bash # Author : Dave Levy (cc) BY-SA # Program : showdistro Version 1.1 USAGE="$0 [-?|-h|help|--help]" case $1 in -?|-h|help|--help) echo $USAGE ; exit ;; esac # Maybe needs a version flag # This program displays distro/release facts. It has been tested for # RHES, SUSE, Fedora and Ubuntu 10. It ends with status 0 if it works # OK and 1 for a universal error i.e. if it cannot detect and parse # the *-release files. It replies status 10 if neither lsb-release nor # system-release files are present, and status 255 if it is not Linux if [ $(uname) != "Linux" ] then echo this version only works for Linux, and Red Hat at that! exit 255 fi # We have four OS's that we've tested. Fedora, RHES, SUSE & Ububtu # Ubuntu 10.10 uses /etc/lsb-release, the others best use /etc/system-release # Assume Not Ubuntu if [ ! -r /etc/lsb-release ] then if [ ! -r /etc/system-release ] then echo Error /etc/system-release does not exist exit 10 fi RELEASE=$( cat /etc/system-release | head -1 ) echo $RELEASE exit fi # Assume Ubuntu if [ $( grep DISTRIB_ID /etc/*-release | cut -f2 -d"=") == "Ubuntu" ] then RELEASE=$( cat /etc/*-release | grep DISTRIB_DESCRIPTION | cut -f2 -d"=") RELEASE="${RELEASE} ($(grep DISTRIB_CODENAME /etc/*-release | cut -f2 -d"="))" echo $RELEASE | tr -d '"' exit fi # BOth assumptions fail echo Error $0 cannot determine the distro / release exit 1