On Wed, 2007-05-30 at 22:12 +0100, Stephen Gran wrote:
> This one time, at band camp, Kris Deugau said:
> > On RHEL and derived distros, there's usually a file /etc/redhat-release
> > (sometimes renamed, but usually trivially enough that it can be found
> > with little trouble) containing both the distro code name and the
> > version number.
>
> The closest we ship is /etc/debian_version. I use it for several
> similar tests at work, you just need to keep a mental map between the
> number and the version string. If you can count lsb-release being
> installed, that will give you more information, or you could just look
> at the tests it performs to get an idea of how it distinguishes
> releases.
The command name is "lsb_release". Its implementation is
distribution-specific. Debian's reads APT policy and then
debian_version:
> def guess_debian_release():
> distinfo = {'ID' : 'Debian'}
>
> kern = os.uname()[0]
> if kern in ('Linux', 'Hurd', 'NetBSD'):
> distinfo['OS'] = 'GNU/'+kern
> elif kern == 'FreeBSD':
> distinfo['OS'] = 'GNU/k'+kern
> else:
> distinfo['OS'] = 'GNU'
>
> distinfo['DESCRIPTION'] = '%(ID)s %(OS)s' % distinfo
>
> rinfo = guess_release_from_apt()
> if rinfo:
> release = rinfo.get('version')
> if release:
> codename = lookup_codename(release, 'n/a')
> else:
> release = rinfo.get('suite', 'unstable')
> if release == 'testing':
> # Would be nice if I didn't have to hardcode this.
> codename = TESTING_CODENAME
> else:
> codename = 'sid'
> distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
> elif os.path.exists('/etc/debian_version'):
> release = open('/etc/debian_version').read().strip()
> if not release[0:1].isalpha():
> # /etc/debian_version should be numeric
> codename = lookup_codename(release, 'n/a')
> distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
> else:
> distinfo['RELEASE'] = release
>
> if 'RELEASE' in distinfo:
> distinfo['DESCRIPTION'] += ' %(RELEASE)s' % distinfo
> if 'CODENAME' in distinfo:
> distinfo['DESCRIPTION'] += ' (%(CODENAME)s)' % distinfo
>
> return distinfo
lsb-release has Priority: extra so it's not that likely to be installed.
I've still doing distribution recognition by grepping
/etc/*-release /etc/release /etc/debian_version.
Ben.
--
Ben Hutchings
The generation of random numbers is too important to be left to chance.
- Robert Coveyou
Attachment:
signature.asc
Description: This is a digitally signed message part