JP Vossen on 29 Mar 2009 22:16:14 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Determining Debian/Ubuntu distro and release?

JP Vossen wrote:
> Does anyone have a better method for determining the distro and release 
> for Debian/Ubuntu?  /etc/issue isn't always consistent, 
> /etc/debian-release doesn't help for Ubuntu, /etc/lsb-release isn't 
> always there.
> So far I have:
> # Release code name (should be 5 lines)
> codename=$(perl -ne 'print qq($1\n) if 
> m!^deb .*?(?:debian|ubuntu)/\s+(\w+)\s+main!;' /etc/apt/sources.list)
> [ -n "$codename" ] || {
>     echo "Release codename not set, 'export codename=name' before 
> running..."
>     exit 2
> }
> # Debian or Ubuntu
>     if   grep -q '' /etc/apt/sources.list; then
>         # Do something
>     elif grep -q '' /etc/apt/sources.list; then
>         # Do something
>     else
>         echo "/etc/apt/sources.list doesn't look like Debian or Ubuntu, 
> skipping..."
>         exit 3
>     fi

BUGFIX, need a space after ^deb ":
perl -ne 'print qq($1\n) if m!^deb 
.*?(?:debian|ubuntu)/\s+(\w+)\s+main!;' /etc/apt/sources.list

I always remove deb-src from my sources.list since I *never* care about 
the source on production machines and I see no reason to download twice 
as much header info.  But when "deb-src" is present it was also 
matching, thus $codename would be set to, e.g., "jaunty

Casey, yeah I know about uname but as you noted it doesn't help here.

Sean, as Brent said, and as I thought I'd remembered, lsb_release isn't 
always there.  Not on my Etch and 1 Lenny, but is on another Lenny, not 
sure why; seems to be there for Ubuntu.

Jim, I get very odd & ugly results from your quick and dirty line, 
probably because I use a "simplified" format in my file.  Also, I'd 
remove the "useless use of cat," like so:
	cut -f5 -d '/' /etc/apt/sources.list

Sorry about the bug and thanks for the thoughts,
JP Vossen, CISSP            |:::======|
My Account, My Opinions     |=========|
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
Philadelphia Linux Users Group         --
Announcements -
General Discussion  --