Re: install script for custom moodle install

Skip to first unread message

Rory McCann

Apr 24, 2009, 6:29:05 AM4/24/09
to Paul O'Rourke, Camara Linux, Camara Linux, Camara Linux 09
On 22/04/09 00:42, Paul O'Rourke wrote:
> Hi Rory,
> Following on from our brief conversation on Saturday.
> I've loaded up a virtual pc using one of the workshop install discs
> (edubuntu 6.10). Even if we wanted to use the apt repositories to put
> on apache, mysql, php and moodle (all of which are available), they
> don't work any more - and I can't be bothered trying to figure out where
> the correct locations are, and then loading them in. The error message is:

Ah yes, I remember this. This annoyed me. It's cause 6.10, edgy is no
longer being maintained. You can still get the various debs from FYI. This was annoying when i trying to
install MP3 support on various camara machines in Kenya.

> The packages needed for moodle (the php, apache and mysql packages, and
> moodle itself) are missing from the list of packages on the pc. And the
> cd is pretty much 700MB right now.

Yeah the age old problem of not enough space on the CD. I did see
something about being able to have a multi CD installer, but I haven't
checked up on that in about a year. Also it's not readily available for
older ubuntu releases.

> The installer file is about 70MB and it'll run on pretty much any linux.

Even mac hardware (ie powerpc)? :) There are a tiny amount of camara
linux machines running on old donated iMacs somewhere in ethiopia. But
you can probably forget about them, I'm just being pedantic. :P

> The shell command for the installer can take a whole range of options -
> either in a file full of options or on the command line itself. See below.
> My current options file (using only some of the options) looks like this:
> prefix=/opt/afrimoodle/
> base_user=moodle
> base_password=notpassword
> base_user_name=Camara Admin
> apache_server_port=50100
> web_server_domain=
> mysql_database_name=afrimoodledb
> mysql_database_username=afrimoodle
> mysql_password=notpassword
> phpmyadmin_password=notpassword
> moodle_site=
> If any of the ports is already bound it'll prompt you for a different port.

It is possible to check for open ports (using lsof and grepping for
'LISTEN'), but it's unlikely to be a problem.

> My current install script looks like this:
> #!/bin/bash
> # script to install moodle and set up
> # move to package folder
> cd ~/Desktop/afrimoodle/
> # make package an exe
> sudo chmod 755 afrimoodle.bin
> #install using options file in same folder
> sudo ./afrimoodle.bin --optionfile optsfile
> #copy scripts to boot time
> sudo cp /opt/afrimoodle/ /etc/init.d/afrimoodlesh
> sudo update-rc.d -f afrimoodlesh start 80 2 3 4 5 . stop 30 0 1 6 .
> # copy from desktop to moodledata folder
> cp -R ~/Desktop/afrimoodle/moodledata /opt/afrimoodle/apps/moodle/
> # make everything belong to daemon in daemon group
> sudo chown daemon:daemon -R /opt/afrimoodle/apps/moodle/moodledata
> # make main folder belong to daemon in root group
> sudo chown daemon:root /opt/afrimoodle/apps/moodle/moodledata
> # run mysql to import existing mysql data
> cd /opt/afrimoodle/mysql/bin/
> sudo ./mysql -uroot -pnotpassword -vvvv bitnami_moodle <
> ~/Desktop/afrimoodle/bitnami_moodle.sql
> # end of script
> The line
> sudo ./afrimoodle.bin --optionfile optsfile
> can have the ip address on the command line along with the rest of the
> options (remember to remove the ip address from the optionfile), like this:
> sudo ./afrimoodle.bin --optionfile optsfile --moodle_site
> Could we construct a piece of script that would sub in the actual IP
> address of the PC?

Try this.

sudo ./afrimoodle.bin --optionfile optsfile --moodle_site $( ifconfig
eth0 | grep "inet addr:" | sed 's/^.*inet addr:\([^ ]*\) .*$/\1/' )

(all one line)

$(...) is used in the bash command line to 'run this command
and substitue the results in here. This assumes that eth0, i.e. the
first ethernet device is set up as working.

> Also my script as it is is pretty handy to run right now: drag folder to
> Desktop; change permission on script to executable (right click); double
> click on script file; allow to run in terminal; enter user password
> [camara for the camara pcs].
> My problem is that if you cancel the bitnami installation (runs in a
> separate window), it will attempt to run the rest of the stuff in the
> script (copying and stuff).

You could try changing the first line of the script to "#! /bin/bash
-x". The -x says "if any step fails, then abort the whole script. The
unix way to say that a programme/script has failed is to return a
non-zero result code form the programme/script. They may or may not have
done that.

> Do you think it would be better to have users run two scripts (one to
> install and one to post install), or can we build in a bit of interactivity?

I'd think one script would be best. Just incase someone forgets to rerun
the 2nd, or runs the 2nd one again, etc.

What sort of interaction? command line interaction is easy.

echo -n "What's your name "; read NAME ; echo "Hi $NAME"

If you want GUIs you could use zenity, but that's a problem of a
programme that you'd need to install.

> My installer loads my moodle into or
> PhpMyAdmin can be got at from
> I would expect users of other PCs to
> bookmark the ip address in their browsers.
> Presumably you would use something like grep to extract the relevant info.
> If we need to change the ip address after the software has loaded i
> think we need to build some sort of custom script that users can run
> that will edit the wwwroot line in the relevant php config file.


> We had discussed the idea of having something run at boot time, but can
> you set it so that the script runs after the ip address has been obtained?

Recent versions of ubuntu have done a cool thing called 'upstart', which
controls how and when programmes are started when you start the
computer. You could set up our moodle server using upstart, and then say
"we need networking to start this", and then it would automatically do that.

I'm not 100% sure when upstart was included. I think it was included in
edgy (6.10). However I don't think we can rely on having it there. Also
I don't know anything about upstart.

I'm not sure how the networking will be set up

> I think I'm going to need a similar script to hack a couple of config /
> ini files to change upload limits (the default in the php.ini file as
> given here is something like 1M). To change the max upload limits in
> Moodle you need to change a bunch of stuff in the file, an apache
> httpd file (or .htaccess) and a load of places in the Moodle gui (mysql
> db). This step would need to happen after we install Moodle but before
> we do any mysql. And it needs that the services affected be restarted.

fun fun. I'm not sure if there's any nice adnd easy way to do it....
Maybe just modify the bitnami file, repackage it, and include that? That
way you're only doing it once?

> Also I know that sometimes you can get away with using the pc hostname
> instead of the ip address, but this assumes that the hostname is unique
> on the network. It appears that the hostname loaded by default with the
> camara workshop cd is camarabuntu.

Yeah. the hostname is 'camarabuntu'. In the install script you could
change the name (using the /etc/hostname file) to "moodle" or something
similar. Then people know to go to "http://moodle".

> And the ip address set by default is static and (see below).
> If Windows is any sort of a guidethen changing the hostname can be a
> bit awkward, especially if you're not confident about what you're doing

You can change it in System → Administration → Network. You have to log
out and log in again afterwards. That's about it. The contents of the
file /etc/hostname

> So that users can access the moodle pc easily, the moodle pc is going to
> need a static ip address. Otherwise users will need to change their
> bookmarks regularly.
> I've also got an uninstall script that removes the moodle services from
> runtime and from the init.d folder.
> Let me know if you need any more files / info.
> Would I be better off posting this onto the camara google groups area
> somewhere?

Ah there's nothing wrong with CCing a bunch of lists (see above) :)

> Thanks in advance for your help
> Kind Regards,
> Paul.

Hope that helps.

twitter: @lalonde


Paul O'Rourke

Apr 24, 2009, 8:16:00 PM4/24/09
to Rory McCann, Camara Linux, Camara Linux, Camara Linux 09
Hi Rory,
Thanks for your reply.
There are separate bitnami moodle (and other application) files available for Windows, Mac PPC, Mac x86 and Linux.  They don't appear to distinguish between the underlying architecture (except Macs).
The -x and grep / sed strings pretty much do the job.
My script now looks like this:
#!/bin/bash -x

# script to install moodle and set up
# move to package folder
cd ~/Desktop/afrimoodle/
# make package an exe
sudo chmod 755 afrimoodle.bin
#install using options file in same folder
#sudo ./afrimoodle.bin --optionfile optsfile --moodle_site

sudo ./afrimoodle.bin --optionfile optsfile --moodle_site $( ifconfig eth0 | grep "inet addr:" | sed 's/^.*inet addr:\([^ ]*\) .*$/\1/' )
#copy scripts to boot time
sudo cp /opt/afrimoodle/ /etc/init.d/afrimoodlesh
sudo update-rc.d -f afrimoodlesh start 80 2 3 4 5 . stop 30 0 1 6 .
# copy from desktop to moodledata folder
cp -R ~/Desktop/afrimoodle/moodledata /opt/afrimoodle/apps/moodle/
# make everything belong to daemon in daemon group
sudo chown daemon:daemon -R /opt/afrimoodle/apps/moodle/moodledata
# make main folder belong to daemon in root group
sudo chown daemon:root /opt/afrimoodle/apps/moodle/moodledata
#Code needed here to hack php.ini and httpd.conf files
#Code needed here to restart server once hack is complete
#sudo /etc/init.d/afrimoodlesh restart
# run mysql to import existing mysql data
cd /opt/afrimoodle/mysql/bin/
sudo ./mysql -uroot -pnotpassword -vvvv bitnami_moodle < ~/Desktop/afrimoodle/bitnami_moodle.sql
echo 'Job Done'
# end of script

I put a 'read' command in at the end to stop the terminal shutting down at the end.  The installer may attempt to open the newly created Moodle site in Firefox once it installs (you have to uncheck a box to stop it happening).  Then once the script completes the Firefox session terminates along with the terminal.

I found that if you cancel the installation while it's running then the -x option prevents the rest of the script running.  But this doesn't always work - especially if you decide to run the installation on top of an existing install (the installer prompts for a different folder but if you decide to cancel the install here it doesn't appear to return the fail code).  I think I'll need to do something like checking for the absence of the afrimoodlesh file in /etc/init.d [if there hasn't been a successful install then that file won't be there?].  If the file is present then exit script?
  I'll look at this over the next few days.
If users need to change the ip address of the machine after installation, they need to edit the wwwroot line in the Moodle config.php file (below)
<?php  /// Moodle Configuration File
$CFG->dbtype    = 'mysql';
$CFG->dbhost    = 'localhost:50200';
$CFG->dbname    = 'bitnami_moodle';
$CFG->dbuser    = 'afrimoodle';
$CFG->dbpass    = '66975a146c';
$CFG->dbpersist =  false;
$CFG->prefix    = 'mdl_';
$CFG->wwwroot   = '';
$CFG->dirroot   = '/opt/afrimoodle/apps/moodle/htdocs';
$CFG->dataroot  = '/opt/afrimoodle/apps/moodle/moodledata';
$CFG->admin     = 'admin';
$CFG->directorypermissions = 00777;  // try 02777 on a server in Safe Mode
I'm thinking we could possibly use a combination of sed and grep (as with the ip address) to hack this then stick it in a script.  I'll also look at this over the next few days.
Kirsty wanted to increase the max upload size (limiting the size of attached files you can have in Moodle.  This is controlled in a number of places - within Moodle itself (stored in the mysql database - fine because we'll set up one that we can just load in), and in the 'server' php.ini file.  Most servers also need the apache2 conf file changed as well.
The php.ini file is pretty huge as files go, and it appears to be fairly customised to the install (I had been thinking of just copying the file from cd).  The following elements need changing:
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
Presumably the sed and grep combination could be used to do the editing to a new temporary file and then copy the temporary file back over.
One reason I don't want to change the hostname is that I want to avoid a system restart if I can.  Another reason is that I don't know if we can guarantee that there will be only one 'moodle server' on the network.  In any case, it's fairly easy for users to store a bookmark for e.g.  Otherwise the script looks like:
  • Change host name
  • Restart
  • Check host name has stuck (maybe this is just a Windows thing!)
  • Install Moodle
Instead of
  • Set static ip address
  • Check ip address on eth0 (ifconfig)
  • Install moodle
Actually this is one for the networkers / sysadmins to think about: better to use the ip address or the hostname.
In terms of user interaction I was thinking along the lines of
  • Are you sure you want to install Moodle (y/n)?
  • ...
  • Moodle has finished installing
I think the only problem we have now is that we're currently a bit short on content, and there isn't all that much time left!
Again, thanks for your help with this.
Kind Regards,

--- On Fri, 24/4/09, Rory McCann <> wrote:

From: Rory McCann <>
Subject: Re: install script for custom moodle install
To: "Paul O'Rourke" <>
Cc: "Camara Linux" <>, "Camara Linux" <>, "Camara Linux 09" <>
Date: Friday, 24 April, 2009, 11:29 AM

Reply all
Reply to author
0 new messages