#!/bin/bash # # File: llxcfg-init-moodle # Description: Program to initialize the moodle course management system # Author: Fco Javier Lopez Perez # Copyright: (C) 2006 Fco Javier Lopez Perez # # 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. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA #set -e # ----------- # INIT SCRIPT # ----------- # Load functions and set up defaults if [ -z "`which ssft.sh`" ]; then # If 'ssft.sh' is not available on the current PATH, add # standard PATH components to this script PATH="$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" fi . ssft.sh || exit 1 # Set textdomain export TEXTDOMAIN="llxcfg-moodle" # Set frontend variable [ -z ${SSFT_FRONTEND} ] && SSFT_FRONTEND="`ssft_choose_frontend`" # --------- # VARIABLES # --------- # Variables of the files/directories to check moodle. MOODLE_APACHE_CONF_FILE="/etc/apache2/conf.d/moodle" MOODLE_LLIUREX_SITE="/var/www/lliurex/moodle" ROOTLLIUREXMOODLE='/usr/share/lliurex-moodle2/src/moodle/' LLIUREXMOODLEEXTRAS='/usr/share/lliurex-moodle2/data/' MOODLE_DEFAULT_DIR="/usr/share/moodle2/" MOODLEDATA="/var/lib/moodle2/" MOODLE_ADMIN_USER="admin" MOODLE_ADMIN_PASSWD="" MOODLE_ADMIN_EMAIL="" MOODLE_ADMIN_CITY="" MYSQL_PASSWD_FILE="/root/.my.cnf" MYSQL_PASSWD="" TMP_COOKIES_FILE="/tmp/cookie" TMP_PARAM_FILE="/tmp/res" eval $(llxcfg-showvars LDAP_BASE_DN) # --------- # FUNCTIONS # --------- # Function: show_user_cancel_msg # # Description: Show a common "Cancelled by user" informational message. show_user_cancel_msg() { TIT="`gettext "Cancelled by user"`" MSG="`gettext "The program was cancelled by the user"`" ssft_display_message "$TIT" "$MSG" exit 1 } # Function: show_error_msg # # Description: Show a message when an error occurs. show_error_msg() { TIT="`gettext "Error"`" MSG="`gettext "An error has occurred during post-configuration of moodle"`" ssft_display_message "$TIT" "$MSG" exit 1 } # Function: do_sanity_check # # Description: Perform some basic sanity checks to see if the # Moodle configuration files, sites and databases are ok. do_sanity_check() { # check if you are root local uid=$(id -u) if [ $uid -ne 0 ] ; then TIT="`gettext "You are not root"`" MSG="`gettext "You must be root user to make this work."`" ssft_display_error "$TIT" "$MSG" exit 1 fi if [ "$LDAP_BASE_DN" = "" ]; then TIT="`gettext "You are not initialized server"`" MSG="`gettext "You must be initialize server way zero-server-wizard."`" ssft_display_error "$TIT" "$MSG" exit 1 fi # // check if you are root export HOME="/root" # get root mysql password if [ -f "$MYSQL_PASSWD_FILE" ] ; then MYSQL_PASSWD=`sed -ne "/^\[mysql\]/,/^\[/s%^password[^=]\+=[[:space:]]\+%%p" "$MYSQL_PASSWD_FILE"` fi if [ -z "$MYSQL_PASSWD" ] ; then TIT="`gettext "MySQL password is not present"`" MSG="`gettext "MySQL password file is not present."`" ssft_display_error "$TIT" "$MSG" exit 1 fi # // get root mysql password if [ -z "`which md5-encode`" ]; then TIT="`gettext "Password encrypt is not available."`" MSG="`gettext "It's not possible to change the Moodle admin password. Some needed program is not present in the system."`" ssft_display_error "$TIT" "$MSG" exit 1 fi local ret ret=0 mysqladmin -p"$MYSQL_PASSWD" ping > /dev/null || ret=$? if [ "$ret" -ne "0" ]; then TIT="`gettext "MySQL is not running."`" MSG="`gettext "MySQL is not running. MySQL have to be running to the correct Moodle work."`" ssft_display_error "$TIT" "$MSG" exit 1 fi # Testing for a moodle database. If not present then we create it. # If moodle seems to be post-configured, question for a new postconfiguration of script execution # Now we synchronize password in config.php and moodle database always. MSG_TITLE="$(gettext "Prepare Moodle")" MSG_DATABASE_ERROR="$(gettext "Moodle database cannot be created")" MSG_MOODLE_QUESTION="$(gettext "Moodle seems to be postconfigured. Do you want to postconfigure moodle again?")" OK="1" mysql_moodle check_tables ; OK=$? if [ "$OK" = "0" ]; then if ! ssft_yesno "$MSG_TITLE" "$MSG_MOODLE_QUESTION" ; then show_user_cancel_msg fi fi mysql_moodle delete MSG="`gettext "There is a previous configuration of moodle. Want to delete?:"`" TIT="`gettext "Moodle old config"`" REMOVEFILE="" if [ -e "${MOODLE_DEFAULT_DIR}/config.php" ]; then zenity --question --text="$MSG" --title="$TIT" && REMOVEFILE=1 if [ "$REMOVEFILE" = "1" ]; then rm -rf "/usr/share/moodle2/*" || true rm -rf "/var/lib/moodle2/*" || true else exit 1 fi fi if [ ! -e "$MOODLE_APACHE_CONF_FILE" ] ; then TIT="`gettext "Moodle is not installed"`" MSG="`gettext "The course management system Moodle configuration file is not present. Is Moodle correctly installed or the configuration file has been removed?"`" ssft_display_error "$TIT" "$MSG" exit 1 fi if [ ! -d "$MOODLE_DEFAULT_DIR" ] ; then TIT="`gettext "Moodle directory is not installed"`" MSG="`gettext "The course management system Moodle default directory is not present. Is Moodle correctly installed or removed?"`" ssft_display_error "$TIT" "$MSG" exit 1 fi if [ ! -d "$MOODLE_LLIUREX_SITE" ] ; then TIT="`gettext "Moodle site is not installed"`" MSG="`gettext "The course management system Moodle site is not present. Has Moodle site been enabled?"`" ssft_display_error "$TIT" "$MSG" exit 1 fi #Deleting files rm -rf ${TMP_COOKIES_FILE} ${TMP_PARAM_FILE} } # Function: do_curl_executionhash_internal_user_password # # Description: Executes all the curl get/post. do_curl_execution(){ rsync -avx "${ROOTLLIUREXMOODLE}" "${MOODLE_DEFAULT_DIR}" cd ${MOODLE_DEFAULT_DIR} sudo -u www-data /usr/bin/php5 admin/cli/install.php --non-interactive --agree-license --allow-unstable --wwwroot="http://moodle" --dataroot="${MOODLEDATA}" --dbuser="moodle" --dbpass="${MOODLE_ADMIN_PASSWD}" --fullname="Moodle" --adminpass="${MOODLE_ADMIN_PASSWD}" --shortname="moodle" --lang=es --chmod=0750 cd $OLDPWD rsync -avx "${LLIUREXMOODLEEXTRAS}educacio" "${MOODLE_DEFAULT_DIR}theme/" || true if [ ! -d ${MOODLEDATA} ]; then mkdir -p ${MOODLEDATA} chown www-data:www-data ${MOODLEDATA} fi rsync -avx "${LLIUREXMOODLEEXTRAS}qcv" "${MOODLEDATA}lang/" || true ################## Esta funcion tiene que hacer ################## La base de datos tiene que estar ya creada. ############### #local a #echo "5" #if curl -D ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "10" #else # return 1 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php?agreelicense=1" >/dev/null 2>/dev/null; then # echo "15" #else # return 2 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php?agreelicense=1&confirmrelease=1" >/dev/null 2>/dev/null; then # echo "20" #else # return 3 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "25" #else # return 4 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "30" #else # return 5 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "35" #else # return 6 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "40" #else # return 7 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "45" #else # return 8 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "50" #else # return 9 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "55" #else # return 10 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "60" #else # return 11 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "65" #else # return 12 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "70" #else # return 13 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/index.php" >/dev/null 2>/dev/null; then # echo "75" #else # return 14 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/user/editadvanced.php?id=2" > ${TMP_PARAM_FILE} 2>/dev/null; then # a=`grep 'input name="sesskey" type="hidden"' ${TMP_PARAM_FILE} | awk '{print $4}' | cut -d "\"" -f2 |cut -d "\"" -f1` # echo "80" #else # return 15 #fi #if curl -b ${TMP_COOKIES_FILE} -d "MAX_FILE_SIZE=2097152&id=2&course=1&mform_showadvanced_last=&sesskey=${a}&_qf__user_editadvanced_form=1&username=admin&newpassword=$MOODLE_ADMIN_PASSWD&firstname=Admin&lastname=Usuario&email=$MOODLE_ADMIN_EMAIL&maildisplay=1&emailstop=0&mailformat=1&maildigest=0&autosubscribe=1&trackforums=0&htmleditor=1&screenreader=0&city=$MOODLE_ADMIN_CITY&country=ES&timezone=99&lang=qcv_utf8&description=&imagefile=&filename=&imagealt=&url=&icq=&skype=&aim=&yahoo=&msn=&idnumber=&institution=&department=&phone1=&phone2=&address=" "http://moodle/user/editadvanced.php" >/dev/null 2>/dev/null; then # echo "85" #else # return 16 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/" >/dev/null 2>/dev/null; then # echo "90" #else # return 17 #fi #if curl -b ${TMP_COOKIES_FILE} "http://moodle/admin/upgradesettings.php?return=site" >/dev/null 2>/dev/null; then # echo "95" #else # return 18 #fi #if curl -b ${TMP_COOKIES_FILE} -d "sesskey=${a}&s__fullname=Moodle%20de%20LLiureX&s__shortname=LliureX&s__summary=Moodle%20de%20LliureX&s__frontpage[]=1" "http://moodle/admin/upgradesettings.php" >/dev/null 2>/dev/null; then # echo "100" #else # return 19 #fi #return 0 } # Function: do_msg_ok # # Description: Shows a message when all the work is well done. do_msg_ok() { TIT="`gettext "Post-configuration of Moodle"`" MSG="`gettext "The post-configuration of course management system Moodle has finished correctly."`" ssft_display_message "$TIT" "$MSG" return 0 } # Function: do_final_changes # # Description: Changes som moodle configurations, auth, frontpage, theme and so on do_final_changes() { local ret=0 # There's a theme record? if [ `mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;select count(*) from mdl_config where name=\"theme\";" |grep "^[0-9]"` -eq 0 ] ; then # If no record exists to store the moodle theme then we create this record mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle; insert into mdl_config set name=\"theme\", value=\"educacio\";" || ret=$? else # If exists a record to store the moodle theme then we modify this record mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"educacio\" where name=\"theme\";" || ret=$? fi [ $ret -ne "0" ] && show_error_msg mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"ldap\" where name=\"auth\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"es_utf8\" where name=\"lang\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"\" where name=\"enrol_plugins_enabled\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"ou=Students,ou=People,dc="$CODIGO_CENTRO",dc=centro,dc=ma3,dc=lliurex,dc=net; ou=Teachers,ou=People,dc="$CODIGO_CENTRO",dc=centro,dc=ma3,dc=lliurex,dc=net\" where name=\"contexts\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"ou=Teachers,ou=People,dc="$CODIGO_CENTRO",dc=centro,dc=ma3,dc=lliurex,dc=net\" where name=\"creators\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"rfc2307\" where name=\"user_type\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"ldaps://Localhost\" where name=\"host_url\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"3\" where name=\"version\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"description\" where name=\"field_map_firstname\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"sn\" where name=\"field_map_lastname\";" || ret=$? # mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config_plugins set value=\"uid\" where name=\"field_map_email\";" || ret=$? mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;INSERT INTO mdl_config_plugins (plugin,name,value) VALUES (\"auth/ldap\",\"contexts\",\"ou=Students,ou=People,"$LDAP_BASE_DN"; ou=Teachers,ou=People,"$LDAP_BASE_DN"\"),(\"auth/ldap\",\"creators\",\"ou=Teachers,ou=People,"$LDAP_BASE_DN";\"),(\"auth/ldap\",\"user_type\",\"rfc2307\"),(\"auth/ldap\",\"host_url\",\"ldap://Localhost\"),(\"auth/ldap\",\"ldap_version\",\"3\"),(\"auth/ldap\",\"field_map_firstname\",\"cn\"),(\"auth/ldap\",\"field_map_lastname\",\"sn\"),(\"auth/ldap\",\"field_map_email\",\"uid\"),(\"auth/ldap\",\"user_attribute\",\"uid\"),(\"auth/ldap\",\"stdchangepassword\",\"0\"),(\"auth/ldap\",\"search_sub\",\"1\"),(\"auth/ldap\",\"removeuser\",\"0\"),(\"auth/ldap\",\"preventpassindb\",\"0\"),(\"auth/ldap\",\"passtype\",\"plaintext\"),(\"auth/ldap\",\"opt_deref\",\"0\"),(\"auth/ldap\",\"objectclass\",\"\"),(\"auth/ldap\",\"memberattribute\",\"uidmember\"),(\"auth/ldap\",\"ldapencoding\",\"utf-8\"),(\"auth/ldap\",\"gracelogins\",\"0\"),(\"auth/ldap\",\"graceattr\",\"\"),(\"auth/ldap\",\"forcechangepassword\",\"0\"),(\"auth/ldap\",\"field_updateremote_url\",\"0\"),(\"auth/ldap\",\"field_updateremote_address\",\"0\"),(\"auth/ldap\",\"field_updateremote_city\",\"0\"),(\"auth/ldap\",\"field_updateremote_country\",\"0\"),(\"auth/ldap\",\"field_updateremote_department\",\"0\"),(\"auth/ldap\",\"field_updateremote_description\",\"0\"),(\"auth/ldap\",\"field_updateremote_email\",\"0\"),(\"auth/ldap\",\"field_updateremote_firstname\",\"0\"),(\"auth/ldap\",\"field_updateremote_idnumber\",\"0\"),(\"auth/ldap\",\"field_updateremote_institution\",\"0\"),(\"auth/ldap\",\"field_updateremote_lang\",\"0\"),(\"auth/ldap\",\"field_updateremote_lastname\",\"0\"),(\"auth/ldap\",\"field_updateremote_phone1\",\"0\"),(\"auth/ldap\",\"field_updateremote_phone2\",\"0\"),(\"auth/ldap\",\"field_map_idnumber\",\"uidNumber\"),(\"auth/ldap\",\"field_map_institution\",\"\"),(\"auth/ldap\",\"field_map_lang\",\"\"),(\"auth/ldap\",\"field_map_phone1\",\"\"),(\"auth/ldap\",\"field_map_phone2\",\"\"),(\"auth/ldap\",\"field_map_url\",\"\"),(\"auth/ldap\",\"field_updatelocal_address\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_city\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_country\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_department\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_description\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_email\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_firstname\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_idnumber\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_institution\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_lang\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_lastname\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_phone1\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_phone2\",\"oncreate\"),(\"auth/ldap\",\"field_updatelocal_url\",\"oncreate\"),(\"auth/ldap\",\"bind_dn\",\"\"),(\"auth/ldap\",\"bind_pw\",\"\"),(\"auth/ldap\",\"memberattribute_isdn\",\"\"),(\"auth/ldap\",\"create_context\",\"\"),(\"auth/ldap\",\"expiration\",\"0\"),(\"auth/ldap\",\"expiration_warning\",\"10\"),(\"auth/ldap\",\"expireattr\",\"\"),(\"auth/ldap\",\"auth_user_create\",\"0\"),(\"auth/ldap\",\"changepasswordurl\",\"\"),(\"auth/ldap\",\"ntlmsso_enabled\",\"0\"),(\"auth/ldap\",\"ntlmsso_subnet\",\"\"),(\"auth/ldap\",\"ntlmsso_ie_fastpath\",\"0\"),(\"auth/ldap\",\"ntlmsso_type\",\"ntlm\"),(\"auth/ldap\",\"field_lock_firstname\",\"unlocked\"),(\"auth/ldap\",\"field_lock_lastname\",\"unlocked\"),(\"auth/ldap\",\"field_lock_email\",\"unlocked\"),(\"auth/ldap\",\"field_map_city\",\"\"),(\"auth/ldap\",\"field_lock_city\",\"unlocked\"),(\"auth/ldap\",\"field_map_country\",\"\"),(\"auth/ldap\",\"field_lock_country\",\"unlocked\"),(\"auth/ldap\",\"field_lock_lang\",\"unlocked\"),(\"auth/ldap\",\"field_map_description\",\"\"),(\"auth/ldap\",\"field_lock_description\",\"unlocked\"),(\"auth/ldap\",\"field_lock_url\",\"unlocked\"),(\"auth/ldap\",\"field_lock_idnumber\",\"unlocked\"),(\"auth/ldap\",\"field_lock_institution\",\"unlocked\"),(\"auth/ldap\",\"field_map_department\",\"\"),(\"auth/ldap\",\"ffield_lock_department\",\"unlocked\"),(\"auth/ldap\",\"field_lock_phone1\",\"unlocked\"),(\"auth/ldap\",\"field_lock_phone2\",\"unlocked\"),(\"auth/ldap\",\"field_map_address\",\"\"),(\"auth/ldap\",\"field_lock_address\",\"unlocked\")"; #mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;INSERT INTO mdl_config_plugins (plugin,name,value) VALUES (\"auth/ldap\",\"contexts\",\"ou=Students,ou=People,"$LDAP_BASE_DN"; ou=Teachers,ou=People,"$LDAP_BASE_DN"\"),(\"auth/ldap\",\"creators\",\"ou=Teachers,ou=People,"$LDAP_BASE_DN";\"),(\"auth/ldap\",\"user_type\",\"rfc2307\"),(\"auth/ldap\",\"host_url\",\"ldap://Localhost\"),(\"auth/ldap\",\"version\",\"3\"),(\"auth/ldap\",\"field_map_firstname\",\"cn\"),(\"auth/ldap\",\"field_map_lastname\",\"sn\"),(\"auth/ldap\",\"field_map_email\",\"uid\")"; cd ${MOODLE_DEFAULT_DIR} sudo -u www-data /usr/bin/php5 admin/cli/upgrade.php --non-interactive --allow-unstable cd $OLDPWD if [ `mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;select count(*) from mdl_config where name=\"auth_instructions\";" |grep "^[0-9]"` -eq 0 ] ; then mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;insert into mdl_config set name=\"auth_instructions\", value=\"El nom d'usuari i la contrassenya per validar-se són les mateixes que per iniciar la sessió al LliureX.

El nombre de usuario y la contraseña para validarse son las mismas que para iniciar la sessión en LliureX.
\";" || ret=$? else mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"El nom d'usuari i la contrassenya per validar-se són les mateixes que per iniciar la sessió al LliureX.

El nombre de usuario y la contraseña para validarse son las mismas que para iniciar la sessión en LliureX.
\" where name=\"auth_instructions\";" || ret=$? fi [ $ret -ne "0" ] && show_error_msg mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_config set value=\"0,1\" where name=\"frontpage\";" || ret=$? [ $ret -ne "0" ] && show_error_msg return 0 } # Function: do_change_admin_pass # # Description: Changes the admin moodle password in mysql moodle database do_change_admin_pass() { local ret=0 local md5_passwd=`md5-encode "$MOODLE_ADMIN_PASSWD"` mysql --batch -u root --password="$MYSQL_PASSWD" -e "connect moodle;use moodle;update mdl_user set password=\"$md5_passwd\", city=\"$MOODLE_ADMIN_CITY\", email=\"$MOODLE_ADMIN_EMAIL\", country=\"ES\" where username=\"$MOODLE_ADMIN_USER\";" || ret=$? if [ $ret -ne "0" ]; then TIT="`gettext "Password not changed."`" MSG="`gettext "Some error occur when trying to change Moodle admin password. Re-execute this program to change the password."`" ssft_display_error "$TIT" "$MSG" exit 1 fi return 0 } #Function: do_city_request #maria # # Description: Ask for the Admin's city. do_city_request(){ local NEW_CITY="" # Get new city if [ -z "$NEW_CITY" ]; then TIT="`gettext 'Moodle admin city'`" MSG="`gettext 'Enter the desired city for Moodle admin user:'`" if ssft_read_string "$TIT" "$MSG"; then NEW_CITY="$SSFT_RESULT" else show_user_cancel_msg fi fi while [ "$NEW_CITY" = "" ]; do TIT="`gettext 'City is required'`" MSG="`gettext 'Please type the city'`" if ssft_read_string "$TIT" "$MSG"; then NEW_CITY="$SSFT_RESULT" fi done MOODLE_ADMIN_CITY="$NEW_CITY" return 0 } #Function: do_validate_email # # Description: Check and modify if the e-mail is no correct. do_validate_email() { local mail="$1" mail_validation="$(echo $(validate-mail "$mail"|cut -d ":" -f 2))" [ "$mail_validation" = "yes" ] || return 1 return 0 } #Function: do_email_request # # Description: Ask for the Admin's e-mail. do_email_request(){ local NEW_EMAIL="" local mail_validate # Get new e-mail if [ -z "$NEW_EMAIL" ]; then TIT="`gettext 'Moodle admin e-mail'`" MSG="`gettext 'Enter the desired e-mail for Moodle admin user:'`" if ssft_read_string "$TIT" "$MSG"; then NEW_EMAIL="$SSFT_RESULT" else show_user_cancel_msg fi fi while ! do_validate_email "$NEW_EMAIL" ; do TIT="`gettext 'E-mail is required'`" MSG="`gettext 'Please type the e-mail'`" if ssft_read_string "$TIT" "$MSG"; then NEW_EMAIL="$SSFT_RESULT" else show_user_cancel_msg fi done MOODLE_ADMIN_EMAIL="$NEW_EMAIL" return 0 } # Function: do_passwd_request # # Description: Ask for the desired admin password, twice. # If both don't match, bail out. do_passwd_request() { local ADMINPASS="0" local REPLYPASS="1" while [ $ADMINPASS != $REPLYPASS ] ; do TIT="`gettext 'Moodle admin password'`" MSG="`gettext 'Enter the desired password for Moodle admin user:'`" ADMINPASS=$(zenity --entry --hide-text --text="$MSG" --title="$TIT") RESULT=$(echo $?) if [ "$RESULT" == "1" ]; then TIT="`gettext "Cancelled by user"`" MSG="`gettext "The program was cancelled by the user"`" zenity --info --text="$MSG" --title="$TIT" exit 1 fi TIT="`gettext 'Moodle admin password confirmation'`" MSG="`gettext 'Enter the desired password for Moodle admin user again:'`" REPLYPASS=$(zenity --entry --hide-text --text="$MSG" --title="$TIT") RESULT=$(echo $?) if [ "$RESULT" == "1" ]; then TIT="`gettext "Cancelled by user"`" MSG="`gettext "The program was cancelled by the user"`" zenity --info --text="$MSG" --title="$TIT" exit 1 fi TIT="`gettext 'Passwords do not match'`" MSG="`gettext 'The two passwords do not match. Please type the password again'`" if [ "$ADMINPASS" != "$REPLYPASS" ]; then zenity --error --text="$MSG" --title="$TIT" fi done MOODLE_ADMIN_PASSWD="$ADMINPASS" return 0 } # Function: do_post_conf # # Description: Perform the post configuration of moodle, # making invocation os the webpages via curl. do_post_conf() { local ret=0 MSG="`gettext "There is a previous configuration of moodle. Want to delete?:"`" TIT="`gettext "Moodle old config"`" MSG_TITLE="`gettext "Prepare Moodle"`" MSG_MOODLE_QUESTION="`gettext "Moodle seems to be postconfigured. Do you want to postconfigure moodle again?"`" rc="1" mysql_moodle create "$MOODLE_ADMIN_PASSWD" ; rc=$? if [ "$rc" = "1" ]; then ssft_display_error "$MSG_TITLE" "$MSG_DATABASE_ERROR" exit 1 fi MSG="$(gettext "Moodle postconfiguration percentage:")" TIT="$(gettext "Moodle postconfiguration")" #do_curl_execution (do_curl_execution | zenity --auto-close --auto-kill --progress --pulsate --text="$MSG" --title="$TIT" ) || ret=$? if [ $ret -ne 0 ] ; then TIT="`gettext "Problem setting Moodle"`" MSG="`gettext "There was some problem during the post-configuration of the course management system Moodle."`" ssft_display_error "$TIT" "$MSG" exit 1 fi return 0 } # Function: change_site_link # # Description: Change the moodle site directory link to the # default directory change_site_link() { rm -f "$MOODLE_LLIUREX_SITE" ln -s "$MOODLE_DEFAULT_DIR" "$MOODLE_LLIUREX_SITE" return 0 } # ---- # MAIN # ---- # Asks for the Moodle admin password do_passwd_request #Asks for the Moodle admin e-mail #maria do_email_request #Asks for the Moodle admin city #maria do_city_request # Perform some checks before starting do_sanity_check # Change the moodle site link. # The moodle site is linked to the default moodle directory, # instead of the lliurex information directory webpage. change_site_link # Perform the moodle post-configuration. do_post_conf # Change Moodle admin password do_change_admin_pass #change auth config, theme, frontpage and so on ( do_final_changes | zenity --progress --pulsate --auto-close --auto-kill) || true mkdir -p /usr/share/n4d/hooks/gesitamanager/ mkdir -p /usr/share/n4d/hooks/golem/ cp /usr/share/lliurex-moodle2/n4d/hooks/gesitamanager/gesitaimport.py /usr/share/n4d/hooks/gesitamanager/ || true cp /usr/share/lliurex-moodle2/n4d/hooks/golem/50_moodle_sync-users.py /usr/share/n4d/hooks/golem/ || true cp /usr/share/lliurex-moodle2/n4d/hooks/golem/51_moodle_create-cohorte.py /usr/share/n4d/hooks/golem/ || true # Show a message if all it's ok do_msg_ok rm -rf ${TMP_COOKIES_FILE} ${TMP_PARAM_FILE} # Correctly ending exit 0