Command-line installation script
From Dokeos
Contents |
Why is this useful?
A script like this would allow better packaging for any platform by ensuring there is no need of a web interface to create the database and configuration files (because that is opposed to most complete-package-installation systems).
It can also help develoment by providing an easy way to re-install from CVS with some default options.
Last but not least, many people use providers that impose severe restrictions. For example, one user noted not being able to chmod the Dokeos files and folders to 777, which is temporarily necessary to do a web install.
Howto
The most important thing is the database creation (and update). If this could be done via a shell script, by sharing a database definition file with the Dokeos PHP install script for example, everything would be a lot easier when installing the Dokeos package on Linux distributions (because mainly you wouldn't have to "fake install" first and then start a browser to do the rest).
The dokeos main tables and content are now contained inside a dokeos_main.sql file. The other tables (for statistics, scorm, special user data..) will soon follow. So you could
- create a dokeos database
- execute the sql instructions of the dokeos_main.sql file to create the tables and content
However, there are several settings you need to personalize to let this work for you. There are some parameters in the dokeos_main.sql that you first have to fill in, you can use a standard search-replace for this:
- {ORGANISATIONNAME}
- {ORGANISATIONURL}
- {CAMPUSNAME}
- {PLATFORMLANGUAGE} -- e.g. english (see lang folder for complete list)
- {ALLOWSELFREGISTRATION} -- the string 'true' or 'false'
- {ALLOWTEACHERSELFREGISTRATION} -- the string 'true' or 'false'
- {ADMINLASTNAME} -- text, e.g. Imple
- {ADMINFIRSTNAME} -- text, e.g. Sally
- {ADMINLOGIN} -- e.g. simple (no special charcters here please)
- {ADMINPASSWORD} -- a string, probably md5 encrypted
- {ADMINEMAIL} -- e.g. sally_imple@somewhere.net
- {PLATFORM_AUTH_SOURCE} -- the string 'platform'
So the procedure becomes
- create a dokeos database
- search-replace the parameters in the dokeos_main.sql file
example: sed "s/{ORGANISATIONNAME}/My Real Organisation/" dokeos_main.sql > dokeos_main2.sql
- execute the sql instructions of the dokeos_main.sql file to create the tables and content
Implementation
Here's a first version of the script used to update the test campus on Dokeos.com. This script uses a local working copy of the SVN-repository. This code gets updated by the script. Once the update is done, the script will remove all files in the portal installation directory and copy the updated code in there. After this, the database is loaded and the config file is written.
###############################################################################
# DOKEOS INSTALL
# Using this script, you can install Dokeos from the unix
# command line.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# See the GNU General Public License for more details.
#
###############################################################################
###############################################################################
# SETTINGS
# Modify these settings to your needs.
###############################################################################
# MySQL Settings
mysqlHost=localhost
mysqlUser=user
mysqlPassword=pasword
mysqlPrefix=dokeos_svn_
# Working dir
baseDir=/home/dokeos/www/demos/dokeos_svn
# Dokeos Settings
organisationName=Dokeos
organisationUrl=www.dokeos.com
rootWeb=http://www.dokeos.com/demos/dokeos_svn/portal/
rootSys=/home/dokeos/www/demos/dokeos_svn/portal/
urlAppendPath=/demos/dokeos_svn/portal/
garbageDir=/home/dokeos/www/demos/dokeos_svn/portal/garbage/
campusName="Dokeos 1.8 alpha Test Campus"
adminEmail=info@dokeos.com
adminLastName=Team
adminFirstName=Development
adminLogin=admin
adminPassword=password
platformAuthSource=platform
platformLanguage=english
allowSelfRegistration=1
allowTeacherSelfRegistration=1
securityKey=3f21aqdsdqeqedqd8989hhdekjde03
###############################################################################
# No need to change anything below this line...
###############################################################################
# Update code from SVN repository
svn update $baseDir/install/dokeos/.
# And remove all files there
rm -rf $baseDir/portal/*
# Copy updated code to portal directory
cp -r $baseDir/install/dokeos/* $baseDir/portal
# Copy dokeos_main.sql file from updated code to install dir
cp $baseDir/install/dokeos/main/install/dokeos_main.sql $baseDir/install/dokeos_main.sql
# Creating a single SQL file with all SQL-commands to create the neede databases and tables
sed -e "s/{DOKEOS_USER_DATABASE}/${mysqlPrefix}dokeos_user/g" \
-e "s/{DOKEOS_STATS_DATABASE}/${mysqlPrefix}dokeos_stats/g" \
-e "s/{DOKEOS_SCORM_DATABASE}/${mysqlPrefix}dokeos_scorm/g" \
-e "s/{DOKEOS_MAIN_DATABASE}/${mysqlPrefix}dokeos_main/g" < $baseDir/install/dokeos_database.sql > $baseDir/install/database.sql;
sed -e "s/{ORGANISATIONNAME}/$organisationName/g" \
-e "s/{ORGANISATIONURL}/$organisationUrl/g" \
-e "s/{CAMPUSNAME}/$campusName/g" \
-e "s/{ADMINEMAIL}/$adminEmail/g" \
-e "s/{ADMINLASTNAME}/$adminLastName/g" \
-e "s/{ADMINFIRSTNAME}/$adminFirstName/g" \
-e "s/'{ADMINPASSWORD}'/MD5('$adminPassword')/g" \
-e "s/{PLATFORM_AUTH_SOURCE}/$platformAuthSource/g" \
-e "s/{PLATFORMLANGUAGE}/$platformLanguage/g" \
-e "s/{ALLOWSELFREGISTRATION}/$allowSelfRegistration/g" \
-e "s/{ALLOWTEACHERREGISTRATION}/$allowTeacherRegistration/g" \
-e "s/{ADMINLOGIN}/$adminLogin/g" < $baseDir/install/dokeos_main.sql >> $baseDir/install/database.sql
# Load the generated SQL-file
mysql -h${mysqlHost} -u${mysqlUser} -p${mysqlPassword} < $baseDir/install/database.sql
# Create the config file
sed -e "s/{DATABASE_HOST}/${mysqlHost}/g" \
-e "s/{DATABASE_USER}/${mysqlUser}/g" \
-e "s/{DATABASE_PASSWORD}/${mysqlPassword}/g" \
-e "s/{TRACKING_ENABLED}/true/g" \
-e "s/{SINGLE_DATABASE}/false/g" \
-e "s/{COURSE_TABLE_PREFIX}//g" \
-e "s/{DATABASE_GLUE}/\`\.\`/g" \
-e "s/{DATABASE_PREFIX}/${mysqlPrefix}/g" \
-e "s/{DATABASE_MAIN}/${mysqlPrefix}dokeos_main/g" \
-e "s/{DATABASE_STATS}/${mysqlPrefix}dokeos_stats/g" \
-e "s/{DATABASE_SCORM}/${mysqlPrefix}dokeos_scorm/g" \
-e "s/{DATABASE_PERSONAL}/${mysqlPrefix}dokeos_user/g" \
-e "s/{PLATFORM_LANGUAGE}/${platformLanguage}/g" \
-e "s|{ROOT_WEB}|${rootWeb}|g" \
-e "s|{ROOT_SYS}|${rootSys}|g" \
-e "s|{URL_APPEND_PATH}|${urlAppendPath}|g" \
-e "s|{GARBAGE_DIR}|${garbageDir}|g" \
-e "s/{SECURITY_KEY}/${securityKey}/g" \
-e "s/{ENCRYPT_PASSWORD}/true/g" < $baseDir/portal/main/install/configuration.dist.php > $baseDir/portal/main/inc/conf/claro_main.conf.php
# Create the .htaccess file in the course directory
sed "s|{DOKEOS_URL_APPEND_PATH}/|${urlAppendPath}|g" < $baseDir/portal/main/install/htaccess.dist > $baseDir/portal/courses/.htaccess
# Add a message in the notice box on the campus homepage
echo "<b>Important notice</b><br />" > $baseDir/portal/home/home_top.html
echo "This demo portal will be reinstalled automatically. Last reinstall: " >> $baseDir/portal/home/home_top.html
date >> $baseDir/portal/home/home_top.html
# Remove some temporary files from the install dir
rm $baseDir/install/database.sql
rm $baseDir/install/dokeos_main.sql
# Set permissions on folders
chmod 777 $baseDir/portal/courses
rm -rf $baseDir/portal/main/install

