Script to determine if OS is Slackware and what version
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Script to determine if OS is Slackware and what version
Does anyone know a good solid way to automatically test if a Linux OS is Slackware and possibly (bonus) even determine the version?
I thought there was a command to do this but I cannot remember it. The only thing I can think of right now is to check the MACHTYPE env variable. This tells me I am running Slackware but not which version.
Yes, that's the best way, but there was a case recently here where it was missing (probably a system admin deleted the file). Then it would be much harder to tell. The other ways involve the kernel as stated before, but if it is custom, that won't help either. I'd say check for pkgtools (pkgtools-12.0.0-noarch-4 for 12.0), but those too can be uninstalled ... a bad idea, IMO. Then, you can check the xorg version and match it up:
Code:
X -version
X Window System Version 1.3.0
Release Date: 19 April 2007
X Protocol Version 11, Revision 0, Release 1.3
Build Operating System: Slackware 12.0 Slackware Linux Project
but then they could have built their own version. Check for glibc version ... but what if they don't have it installed ? ... and so on.
Conclusion: I think the best thing to do is test for all of these things in order with fallback tests in case previous ones fail. I mean test for /etc/slackware-version, then for kernel (uname -a), then for 'X -version', then for pkgtools, then for glibc, then for .... something else. You can change the order around to best fit your needs.
Works for Slackware (I guess, and unless the file is removed or altered), but not for all distributions. For some it may be missing, and for some it doesn't tell the whole truth - on Ubuntu, for example, the file is /etc/debian_version and on Gutsy it says lenny/sid. Ok, it's probably because Gutsy is based on that, but you can't really use it to determine your Ubuntu version..
Maybe the "fallback method" is the best there is, because as far as I can tell there is no solid solution. Each Linux operating system is built on a Linux kernel and a bunch of software, and none of them is branded to tell which distribution it is that they are on.
Other methods to add to the "test list" could be reading bootloader configuration (but it may need root privileges, and you'd need to know which bootloader is used, and the config could still be altered so it doesn't say "Slackware 12 kernel ....") or reading 'version' from proc:
Code:
cat /proc/version
Not sure how easily that information is changed by an admin, though.
Thanks for all the responses! /etc/slackware-version is the simple thing I couldn't remember. I had already tested uname and /proc/version, but they only give hints that it might be Slackware. "X -version" seems to work great as well.
I agree that the approach should have fallbacks. Probably the first three I would test for (in order) are
/etc/slackware-version
X -version
/var/log/packages/pkgtools-12.0.0-noarch-4 (and so on for each version)
This is what I use in my scripts to determine distribution, but as already mentioned, it won't always be 100% accurate.
Code:
if [ -f /etc/*release ]; then
DISTRO="$(cat /etc/*release)"
elif [ -f /etc/*version ]; then
DISTRO="$(cat /etc/*version)"
else
DISTRO="Unable to Determine"
fi
As far as I am aware, there is no way to tell what distribution your software is running on with perfect accuracy. The best you can do is little more than an educated guess.
Just a suggestion: get Webmin's source and look at the 'os_list.txt' file.
They have done a nice (in my oppinion) job to compile a list of ways to determine OSs versions.
Thanks again for the replies. I got webmin's list. It does seem to be a good reference, but it isn't a script itself. I can just pick and choose some of those references in the file to make a script I need.
As said before, however, I still think it is a good idea to have fallback checks, so I think the references in this text file should be combined with some of the previous suggestions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.