This issue seems to arise on many pages, and there are hints around that it may have a "stock" solution, but I haven't seen an actual solution posted.

Problem: I'm setting up a production machine install script. This is a server environment where no X11 support is installed and there is no server-side installation of any web browser. Because of this, connecting over 127.0.0.1 to set up the Drupal SuperUser is a serious pain in the neck.

Once I have the install debugged (i.e. database setup works and so forth), is there any way to do a minimal drupal database install and then initialize the drupal superuser account from inside a batch-mode install script? I'm looking for something very simple here -- I can copy an existing database dump if I have to, but that doesn't satisfy any sensible definition of "simple" that I understand. :-)

Thanks!

Comments

cog.rusty’s picture

Do you mean something like

db_query("INSERT INTO users (uid, name, pass, mail, status) VALUES(1, 'admin', md5('thepass'), 'admin@example.com', 1)");

User 1 does not need any roles or permissions, so this should be probably enough (with some caution for non-english Unicode characters in strings).

shap’s picture

That's pretty close, but there is the problem that I'm running this from a system-wide install shell-script, and the baseline drupal database hasn't been loaded yet. If I can work out how to get the baseline database loaded, I can probably stuff the update you suggest into the drupal database using the mysql interface directly from the system install script.

So now the question is how to get the baseline database install done. I'm wondering if I can get away with something truly icky like starting mysql and httpd, using elinks to pull the first page (for the sake of the db load side effect), shutting it all down, and then running the SQL insert you propose.

Surely there is a better way to get the baseline DB loaded without firing up a browser! Do you happen to know of one?

pbarnett’s picture

Hi.

Well, all the database initialisation gets done in yoursite/modules/system/system.install in the system_install() function (oddly enough :-)

The function is mostly a sequence of db_query calls consisting of the SQL statements required to create the required tables, indices, keys, etc.

Should be pretty portable... let me know how you get on!

Pete.

shap’s picture

Yes, I agree. However, that code seems to be intended to run in the context of CGI execution. It does not appear to be intended to run interactively from a shell prompt (which is, in essence, what I need to do). I don't want to re-work that code. The goal is to use the existing mechanism rather than re-invent the wheel.

Any thoughts on how to run that stuff without doing a web page load?

pbarnett’s picture

Hi!

There should be an easy way to do this; when I first installed Drupal 4.7.x a year or so ago, the process involved running the appropriate database setup script which invoked the database engine to create the core database.

It would be (fairly) straightforward to extract the SQL commands from the source file and then run them as a script, but having a script that does it all from a shell prompt must exist somewhere...

Pete.

...you know you've been running Linux too long when you can remember interactive setup scripts ;-)

shap’s picture

Indeed. For me, the classic has to be Larry Wall's original Perl config script, which was very chatty. Long ago, it used to mutter things like:

Hmm, this looks ilke a System V system,...
Congratulations, you aren't running Eunice!
...
Perl comes with no warranty. If it breaks, you get to keep both pieces.

There were people who actually re-ran the (lengthy) configure step because the darn thing was that funny.

shap’s picture

Back on topic...

The overwhelming majority of what I (seem to) need to do is going to require SQL-level updates in any case. Perhaps I'm fighting city hall, and I should just consider doing all of the preconfiguration somewhere else and preloading the database. I don't really want to do that, because it isn't real robust against version updates.

Let me try the hack of using elinks to poll drupal. Looking at the initialization script, it does appear that doing that might work.

What a kludge!

shap’s picture

The following, thoroughly disgusting bit of python code did the trick:

#!/usr/bin/python
import sys
import urllib2
import urllib

from urllib2 import build_opener, HTTPCookieProcessor, Request
from urllib import urlencode

opener = build_opener(HTTPCookieProcessor)

def urlopen2(url, data=None, user_agent='urlopen2'): 
     """Can be used to retrieve cookie-enabled Web pages (when 'data' is
     None) and to post Web forms (when 'data' is a list, tuple or dictionary
     containing the parameters of the form).
     """
     if hasattr(data, "__iter__"):
          data = urllib.urlencode(data)
     headers = {'User-Agent' : user_agent}
     return opener.open(urllib2.Request(url, data, headers))

print "Initializing to %s://%s:%s@localhost/%s" % (sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

reply = dict(db_type=sys.argv[1],
             db_path=sys.argv[2],
             db_user=sys.argv[3],
             db_pass=sys.argv[4],
             op="Save Configuration",
             form_id="install_settings_form")

#print urlencode(reply)

urlopen2("http://localhost/drupal/install.php?profile=default", reply)

It is invoked as

initdrupal.py mysql dbname user password

Just goes to show that what can be done by one programmer can be reversed by another.

Obviously, this can be improved on quite a bit, but it isn't a bad start.

-- shap (who is old enough to remember rogue-o-matic and sesruc)

pbarnett’s picture

Hi.

I'm simultaneously appalled and impressed :-)

Let's hear it for the command line!

-- Pete. (whose first programming language was PDP-11 macro assembler)

shap’s picture

you should see the installation profile that I have mostly built. This was all so incredibly painful that I am going to write it up in detail once I finish getting it debugged.