-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS detection is wrong #38
Comments
Thanks for the feedback @moviuro! As replied on reddit, We're testing against the different platforms automatically via Travis CI and it seems we can get away without running any commands, which we felt was better. Are there clear disadvantages to the chosen route you feel? |
Yes, E.g.: Read the man pages of OpenBSD |
That makes sense. Ideally I'd like to try if we can keep using I think I'd like to dumb down the The My proposal hence would be to dumb this down to:
for now (even though OSX might technically belong to the BSD family) So how about something along the lines of: if [[ "${OSTYPE:-}" == "linux"* ]]; then
__os="Linux"
elif [[ "${OSTYPE:-}" == "darwin"* ]]; then
__os="OSX"
elif [[ "${OSTYPE:-}" == "msys" ]]; then
__os="Windows"
elif [[ "${OSTYPE:-}" == *"bsd"* ]]; then
__os="BSD"
else
__os="b3bp_unsupported"
fi ? |
Seems like we won't be able to have automated tests for FreeBSD for a while unfortunately travis-ci/travis-ci#1818 |
I've had my fair share of problems switching my workstation from ubuntu -> osx which also doesn't come with my beloved gnu sed :'(. We even have to do this sed dance to have something portable across those platforms: https://github.com/kvz/bash3boilerplate/blob/master/src/templater.sh#L41 while it might have been easier to not make any backups at all. vs doing it and then removing :) It's just that b3bp didn't support (OSX-less) BSD before, but I'm happy to change that. I'm fairly confident it will run if b3bp runs on OSX. |
Sounds good. However, there are still differences between OpenBSD and FreeBSD (I wouldn't know for NetBSD as I haven't used it that much yet). Here's another idea:
|
Yes. And of course there are plenty of differences between CentOS and Debian or instance. E.g. what package manager to use or the other things I mentioned like startup services. However, those even vary between Ubuntu releases (going from init.d -> upstart -> systemd). So you'd really need all the information, even the OS version if you're going to code around those parts. I'm not sure if b3bp should provide this as boilerplate or that this is a usecase specific enough that we should allow users to walk their own paths there. It might be hard to cover all the edge cases, increasing our boilerplate with 100 lines, and still missing a enough cases to not have a truly satisfactory os abstraction. Back to your proposal, what would |
For reference, if we want to introduce |
@moviuro You see how in trying to be correct and supporting all cases, we quickly become bloated and all about os detection, whereas our purpose is more generic. I made a proposal more inclined to the pragmatic side, keeping an eye on the compactness of b3bp, in #39. I think we should cherish this compactness. There are plenty of complete os detection libraries and guides online. For b3bp though I'm looking for something pragmatic that newcomers can apply while decreasing the likelihood of them hurting themselves, and without imposing a steep learning curve. I hope you'll agree #39 is already an improvement over what we had, since I agree that defaulting to Linux was a bit ridiculous. |
Another idea is just get rid of the __os magic variable... AFAICT, we don't need it anywhere, so the user could be left to deal with the OS detection if they require it... |
@kvz works for me 👍 |
I guess, alternatively, we could decide to do a monster project for detecting OS the right way, and put that as a separate function in |
I'm of the opinion that it is beyond the scope of At the end of the day, anyone who needs a really precise and accurate OS determination (because their code may run on tons of different systems) a) might not want a bash3-specific solution (they may only have sh, csh, etc.) b) probably has the experience and know how to code the OS detection themselves, c) can take a quick glance at what we provide (if anything) and determine if it fits their needs. So I'm more than happy to defer to your judgement. (With the caveat, that if you provide it, and it doesn't detect system xyz correctly, a user will probably come tell us about it... 😆 ) |
Yes this is very true... sed and friends can have very subtle annoying differences across OSes... I'm going to work to remove any reliance on sed and awk, etc. |
Going over this thread again after a good night's sleep, @zbeekman's arguments resonate more than they did yesterday, I think I had a bit of a hard time killing this darling because I had a personal use for it, but that's a really bad reason to keep it in a project used by many. I'll work around this on my end, let's remove it. Sorry for changing my mind like this in a day, I realize it must be very confusing to follow along. Will propose a new PR |
Up for review #41 |
PR LGTM. If it just comes down to parsing I think it might be wise to add a comment to main.sh about the existence of |
L12 handles making the user aware of |
You can't just assume
__os="Linux"
(bash3boilerplate/main.sh
Line 29 in 1f2e184
Suggestion: use
uname(1)
instead.The text was updated successfully, but these errors were encountered: