I just needed to test something so I mounted the filesystem of one of my Xen domains in the Dom0 and chroot’d into it (I didn’t need the overhead of running a DomU for a quick test). Then strangely I found that my chroot environment had no apt-get and no dpkg installed.
After a small amount of thought I realised that I had accidentally mounted the filesystem for a Fedora image instead of a Debian image.
It seems to me that it might be a good idea for distributions to have shell scripts replacing the package tools for other distributions. For example dpkg on a Fedora box could be a shell script that runs echo “This system is running Fedora, you want to use rpm instead of dpkg”. Such a command would have saved me a couple of minutes of thinking.
This may sound trivial, but if you consider the number of people who make such mistakes (and the even larger number of people who don’t realise that there is even more than one package tool in existence) then wasting a few K of disk space on every system to help them seems like a good idea.
The minimum size of new hard drives that you can purchase seems to be 36G nowadays. So it’s not as if this would really cost anything.
Please leave comments to tell me if I’m being sensible or silly. If the idea is regarded as good I’ll start filing bug reports.
I tend to install lsb-release on all my machines, then I can run `lsb_release -a` to find out what I’m running.
An alternative might be to run
ls -d /etc/*release /etc/*version
as the RPM-based distros I’ve seen tend to have a file matching *release and dpkg-based distros match *version.
I think last time I ran “rpm -i” on a Debian machine I was warned that it was probably not what I really wanted to do.
I think simply writing the distribution name from the .profile would be enough, wouldn’t it?
Or maybe even have a wrapper that causes apt commands to be optionally executed in rpm? First showing a [Continue: Yes/No] terminal dialog.
uname -a usually does the trick if they have a stock kernel, but failing that:
cat /etc/*release almost never fails unless they’ve removed it, in which case they probably removed your dpkg wrapper too. :-)
Unfortunately, I don’t think this is a good idea. Package management tools have other uses besides simply installing a particular package on your system. Perhaps you want to install to a chroot, or just unpack the files, or examine some metadata in the package.
Instead, I would recommend looking at some of the lsb tools. For example, on my system:
$ lsb_release -i
Distributor ID: Debian
And the -a flag gives more information. Unfortunately, these tools seem to be handled differently in Debian, Ubuntu, and Fedora. *Sigh* I thought that was the entire point. So for now, when I need to do distro checking, I end up examining /etc/issue, and checking for the presence of /etc/lsb-release, /etc/debian_version, and /etc/redhat-release.
I vote for silly.
apt-get is available for Fedora, and Yum is available for Debian. You can’t tell people which package management system they should be using. And a one-line “use rpm instead of dpkg” really doesn’t help when you don’t know how to use rpm.
On the other hand, I’m pretty sure there are scripts out there already which will detect what distro you are using by the existence of certain files – that should be enough for geeks. If you’re running X then it’s likely to tell you on the login screen – that should be enough for non-geeks.
One of the methods I usually use to identify fairly fast which distro I’m on is to look at /etc/issue
The only one I’m come across without it is Trustix where I have to look at /etc/release
Niall.
I would bet there are literally millions of people in this constituency. Why, just yesterday, my little sister mounted the filesystem of one of her Xen domains in the Dom0 and chrooted into it. And, erm, could remember what OS was installed on it.
Isn’t this what uname is for?
– Chris
And what do you do about Debian’s rpm package? Truth is, apt/dpkg/rpm/yum whatever do not determine what distro you are using. Plus, if you mounted the wrong partition, then you should be glad you didn’t mount an unrelated Debian partition.
I think that the combination of /etc/issue, /etc/issue.net, and /etc/motd should be sufficient to identify an installed operating system.
Failing that looking for programs won’t necessarily help. Consider the case of a Debian installation which has RPM installed for alien to use – you’ll type “rpm” and it will not say “Hey! I’m Debian really!”, so you’ve not gained anything.
Personally, I am still waiting for a /etc/OS_information or some such that is well-defined, has several lines like
Distribution: Debian
Version: 9999.0
Codename: Sid
Kernel: Linux
Userspace: GNU
etc etc
I think thats good idea. I do not do an experiments such as you described, but i think it will be very helpful and people will avoid the same thing what you have done:-)
Please don’t. I’m all in favour of making life easier for your mistakes, but I’m quite convinced there are many scripts and tools in existence that test for [ -x /usr/bin/dpkg ] and variants. I’m not saying they are considering the existence of such a binary as proof of Debianness of the system (anthough I don’t doubt some do), but they will generally assume that if there’s a /usr/bin/dpkg, then it’s going to be dpkg and not a very small shell script.
Debian already provides (original) RPM binary. IIRC apt-rpm sometimes found in rpm-based distros provide apt-get binary too…
Maybe just introduce (LSB-mandated) /etc/operating-system instead of /etc/-release?
From the debian lsb-release package description:
“The lsb-release command is a simple tool to help identify the Linux
distribution being used and its compliance with the Linux Standard Base.”
scott@resa:~$ [0] lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu gutsy (development branch)
Release: 7.10
Codename: gutsy
[scott@sa8169024 ~]$ lsb_release -a
LSB Version: 1.3
Distributor ID: FedoraCore
Description: Fedora Core release 3 (Heidelberg)
Release: 3
Codename: Heidelberg
scott@steak:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 4.0r1 (etch)
Release: 4.0r1
Codename: etch
On desktop machines can we have menu item for MS Office apps which simply use the following scripts:
#!/bin/bash
# word.exe
zenity –error –text “This is computer is running Linux, please use OpenOffice.org Writer”
#!/bin/bash
# excel.exe
zenity –error –text “This is computer is running Linux, please use OpenOffice.org Calc”
#!/bin/bash
# outlook.exe
zenity –error –text “This is computer is running Linux, please use Evolution”
etc etc
Sorry I couldn’t resist :)
OK, you have convinced me to use lsb_release. Thanks for the comments!
doesn’t Ubuntu have something similiar for commands that are available in not installed packages? (i.e. you type “vim” and bash says something like: ,,”vim” not found. Maybe you want to install the “vim-tiny” package that contains this program?´´)
Identifying the Distribution of a Linux System…
So Russel is wondering how to figure out what platform you are on by adding a script or so that will tell you you are on a RPM based machine when trying to run dpkg or tell you you need to use rpm.
Imvho that system is broken .. as everybody with som…
more /etc/issue
Has worked for me for ages…
But then again, if [ -x /usr/bin/dpkg ]; then dpkg -i something.deb; elif [ -x /usr/bin/rpm ]; then rpm -i something.rpm; else tar xvzf something.tar.gz; fi would break horribly…
Dave Hall:
Don’t use “#!/bin/bash” if you want portability use “#!/bin/sh”
when we press tab with ‘re’ and when you get commands of redhat like
———————————————
———————————————
redhat-cdinstall-helper redhat-config-nfs redhat-config-services
redhat-config-authentication redhat-config-packages redhat-config-soundcard
redhat-config-bind redhat-config-printer redhat-config-time
redhat-config-date redhat-config-printer-gui redhat-config-users
redhat-config-keyboard redhat-config-printer-tui redhat-control-network
redhat-config-language redhat-config-proc redhat-install-packages
redhat-config-mouse redhat-config-rootpassword redhat-logviewer
redhat-config-network redhat-config-samba redhat-switch-mail
redhat-config-network-cmd redhat-config-securitylevel redhat-switch-mail-nox
———————————————–
———————————————–
then I hope I can be sure it is some version of redhat release.
Also
when I ran lsb_release all I got is this
——————-
——————-
LSB Version: n/a
Distributor ID: n/a
Description: (none)
Release: n/a
Codename: n/a
——————-
——————-
Finally I figured out from the kernel version is redhat kernel 2.4.21-37.ELsmp is a kernel for RHEL 3…
……. there are ways to get there :)