Mins / TuxLite

A complete LAMP and LNMP setup script for Debian or Ubuntu
http://tuxlite.com
253 stars 112 forks source link

Automatic Distro & Release detection #1

Closed stefancrain closed 12 years ago

stefancrain commented 12 years ago

Here's code to use the lsb_release command to automatically detect what Distro OS and Release the script is being run on,

Tested and working on: Debian 6.0.5 live, Ubuntu 12.04 server.

Mins commented 12 years ago

Thanks for your work! However, the detection will only work if the "lsb-release" package is installed. I checked randomly with 3 different Debian/Ubuntu minimal templates and neither has that package pre-installed.

Can you add "aptitude -y install lsb-release" to the start of the "setup_apt" function. Also, can you kindly revert "$R" to "$RELEASE". It makes code reading easier when using meaningful variables. Similarly, I believe that "$DISTRO" is a more accurate term than "$OS" in this context of but I'm okay with it regardless.

stefancrain commented 12 years ago

That's very interesting that the package wasn't installed by default. If you don't mind me asking, where / how can I access similar minimal installs for testing?

I've been doing local testing with Ubuntu/Debian but I imagine that doesn't necessarily reflect what mini VPS providers offer. My Rackspace Servers have "aptitude -y install lsb-release" pre-installed on 12.04, but these are in no way mini.

Mins commented 12 years ago

The templates I tested on was with various budget providers. One of them is a VPS sponsored by vooservers.com. I'm actually surprised that the Rackspace OS templates aren't minimal. Typically only the core packages like sshd, cron and syslog etc are included for a server install.

If Rackspace is using Xen HVM or KVM, you can install using Debian's netinstall, which will result in a similar minimal OS template.

stefancrain commented 12 years ago

Thanks for the info on hosting providers, You've obviously done way more testing then me :-)

I've pushed an update with changes to address your first comment, because the use of the $RELEASE var in 2 functions, i had to run the install at the beginning of the script, as those are "global" vars.

https://github.com/stefancrain/TuxLite/commit/31cd30af8352e1679a841f5685e951fe7942ef04

I'll try to load the netinstall distro tonight to test against that from now on. www.debian.org/CD/netinst/#netinst-stable

Mins commented 12 years ago

Ah ! You raised an important one there with it being a global variable. Placing the "aptitude -y install lsb-release" in the main code will solve the issue but it's going to be executed each time setup.sh is invoked.

I'm thinking lsb-released should be installed by the install.sh script along with the line that installs nano, since it'll only be performed once. What do you think?

stefancrain commented 12 years ago

Good point, I forgot that it could get called multiple times by a user calling the different functions of the script individually. Here's the commit for that. https://github.com/stefancrain/TuxLite/commit/2eba57afe9dd9bf8cf2900a0f205375a00f28c1f

I've tested it, we should be good to go :-) For testing I built two 256MB vm's on rackspace: debian 6 & ubuntu 11.10.

Ubuntu 11.10: lsb_release was installed

Debian 6: lsb_release not installed

Interesting right?

Mins commented 12 years ago

Awesome! Thanks again for your work. I'll probably remove the DISTRO and RELEASE variables completely from options.sh before packaging the code for download.

And yeah, not sure why some templates have it installed and some don't. Either way, this should account for both cases :)