{"id":574,"date":"2010-06-14T17:57:57","date_gmt":"2010-06-14T17:57:57","guid":{"rendered":"https:\/\/copyright.lboro.ac.uk\/lorls\/?p=574"},"modified":"2010-06-14T17:57:57","modified_gmt":"2010-06-14T17:57:57","slug":"lorlss-installer","status":"publish","type":"post","link":"https:\/\/blog.lboro.ac.uk\/lorls\/lorls\/lump\/lorlss-installer","title":{"rendered":"LORLS&#8217;s Installer"},"content":{"rendered":"<p>We&#8217;re getting to the point with LUMP and CLUMP where Jason and I are thinking about installers. \u00a0If we were just going to use the code at Loughborough this would be a moot point &#8211; we&#8217;d just copy the various directories around and tweak under the hood to get the thing to work as we want, just as we have done during development.<\/p>\n<p>However its not going to just be us that use it (or at least hopefully it won&#8217;t be!) so we need to think of a nice way for people to install it. \u00a0The previous versions of LORLS have a Perl command line script that I wrote years ago that asks lots of questions and then does its funky thang. \u00a0It works, but it could be friendlier, especially for the newbie admins. \u00a0I&#8217;ve also seen a number of PHP based packages that allow you to do most of the installation via a web browser which is rather nice for the new admins, so I thought, &#8220;Hey, why not make an installer CGI script that knows very little about the system other than there is Perl there, a MySQL database server is running, the CGI.pm module (which has been part of the Perl distribution since 5.4 so should be there already on most machines installed in the 21st century) and is an executable CGI script?&#8221; \u00a0Why not indeed&#8230;<\/p>\n<p>Obviously the prospective LUMP admin needs to install (or have installed for him) Perl, MySQL and a webserver configured to execute CGI scripts in the directory that we tell them to unpack LUMP into, but once that&#8217;s done surely we can then check to make sure that all the other modules are present, install them if they aren&#8217;t, set up the MySQL database ready for LUMP to use and then configure all the LUMP scripts so that they are ready to go, all with a nice point and drool web interface?<\/p>\n<p>Checking if a Perl module is available is relatively easy, thanks to the eval { } function in Perl. \u00a0For example, say we want to check if Data::Dumper is installed. \u00a0That can be done using some code such as:<\/p>\n<pre>eval { use Data::Dumper; };<\/pre>\n<pre>if($@) {<\/pre>\n<pre>\u00a0\u00a0# Module missing<\/pre>\n<pre>} else {<\/pre>\n<pre>\u00a0\u00a0# Module present, and available for use<\/pre>\n<pre>}<\/pre>\n<p>Shimples!<\/p>\n<p>However things start to get &#8220;interesting&#8221; if the module isn&#8217;t installed. \u00a0I thought this would be easy, as the Comprehensive Perl Archive Network (CPAN) has a nice module that I&#8217;ve used for years to interactively install and update Perl modules with &#8211; things like:<\/p>\n<pre>perl -MCPAN -e install Data::Dumper<\/pre>\n<p>It has a programmatic option as well as an interactive side, so we&#8217;re sorted right? \u00a0Well no, we&#8217;re not. \u00a0Unfortunately the programmatic side really just generates the stream of stuff you see when you run the interactive side. \u00a0If you include something like:<\/p>\n<pre>my $result = CPAN::Shell-&gt;install('Data::Dumper');<\/pre>\n<p>in your CGI script, eventually you&#8217;ll get a result in the web browser of a load of unformated raw text from this command interspersed with your active HTML. \u00a0The $result variable on the other hand will stay completely empty, with no indication as to whether the installation has worked or not. \u00a0 Pants &#8211; not what we want here.<\/p>\n<p>The long and short of it is, to get round this &#8220;feature&#8221; in CPAN::Shell it seems that you have to do a bit of fork() action. \u00a0In other words folk off a child process to run the CPAN::Shell method in and then, back in the parent, capture its STDOUT stream into a variable which can then be scanned with a regexp or two looking for signs of success in the output text. \u00a0Not terribly clean but it works.<\/p>\n<p>There&#8217;s another &#8220;gotcha&#8221; as well: the web server is unlikely to be running as root (or at least it shouldn&#8217;t be!) and so the CGI script can&#8217;t install Perl modules into the system library directories. \u00a0This is a more minor pain: you can tell CPAN::Shell that it should do a local installation to a place that the user executing it can write to. \u00a0So that&#8217;s another requirement for running this CGI script: create a directory that&#8217;s readable and writable by the user running the web server (usually called something like apache or http) but which isn&#8217;t part of the web server document root. \u00a0In other words, if the web server document root is \/var\/www\/html, we might want to put this LUMP specific CPAN directory tree in \/var\/ww\/LUMPCPAN where it can&#8217;t be seen by web browsers. \u00a0You have to hack up a MyConfig.pm to put in this directory and then point @INC and $ENV{&#8216;PERL5LIBS&#8217;} towards it, but that can be done automagically by the CGI installer script once the directory exists.<\/p>\n<p>Now some readers (we do have readers, right?) might be wondering why I don&#8217;t use one of the fancy pants CPAN modules such local::libs or Module::Install to do this rather than tackling CPAN::Shell head on. \u00a0Well its a chicken and egg problem really: I wanted to have the minimum requirements for the installer script to run and, if I&#8217;d have asked the user to install a load of libraries and modules to make using CPAN easier I might as well have just given them a list of modules to install. \u00a0Which actually I have done anyway, just in case they want to install them system wide and\/or not trut my installer script to get them right. \u00a0But nevertheless I&#8217;d like to give the newbies (and also folk who have sluggish server admins if they don&#8217;t run their own boxes) the option of installing via the CGI installer script. \u00a0More work for me, but hopefully less for them.<\/p>\n<p>So, its a bit of kludge at the moment but it seems to be the way to go unless anyone else can come up with a better scheme. \u00a0Once I&#8217;m happy it can get the required modules in place, my next trick will be to ask for database server details (database name, username, password, server, port) and then check if the database already exists, or create a fresh one. \u00a0In the former case I&#8217;m also planning on checking the schema in the database against the one in this LUMP distribution and then offer to update it if needs be, and allow fresh databases to either be empty, have some simple test data in them or copy data from another database. \u00a0Hopefully I can also bolt the importer from older LORLS versions in here so that there&#8217;s no command line interaction required at all. \u00a0With a bit of luck all of those should be alot less hassle than CPAN::Shell has proved to be.<\/p>\n<p>I hope&#8230; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;re getting to the point with LUMP and CLUMP where Jason and I are thinking about installers. \u00a0If we were just going to use the code at Loughborough this would be a moot point &#8211; we&#8217;d just copy the various directories around and tweak under the hood to get the thing to work as we [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[4],"tags":[22,38,62],"class_list":["post-574","post","type-post","status-publish","format-standard","hentry","category-lump","tag-cpan","tag-installation","tag-perl","count-0","even alt","author-cojpk","last"],"_links":{"self":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":0,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lboro.ac.uk\/lorls\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}