#!/bin/bash zero-center add-pulsating-color install-moodle export TEXTDOMAIN="zero-lliurex-moodle" MSG_INSTALLING_PROGRESS=$(gettext "Configurator Service for Moodle in LliureX") MSG_ADVERTISEMENT=$(gettext "Do you want install and configure Moodle for LliureX?") MSG_ZENITY_MOODLE_1=$(gettext "Testing Mysql....") MSG_MOODLE_MYSQL_PROBLEM=$(gettext "Mysql is not working properly") MSG_ZENITY_MOODLE_2=$(gettext "Creating a token....") MSG_MOODLE_AVISO=$(gettext "Activating new token") MSG_ZENITY_MOODLE_3=$(gettext "Linking Apache with Moodle....") MSG_ZENITY_MOODLE_4=$(gettext "Configuring DNS mask for Moodle in LliureX....") MSG_ZENITY_MOODLE_5=$(gettext "Linking LDAP with Moodle....") MSG_ZENITY_MOODLE_6=$(gettext "Restarting services to apply new configurations....") MSG_ZENITY_MOODLE_7=$(gettext "Configuring installed languages in Moodle....") MSG_MOODLE_INSTALLED=$(gettext "Moodle has been installed in your system. You can check it with firefox in this URL http://moodle") MSG_MOODLE_INSTALL_PROBLEM=$(gettext "Moodle has NOT been installed in your system. Please check the logs.") HELP_PROGRESS_BAR="/tmp/help_moodle_install.txt" if zenity --question --title="$MSG_INSTALLING_PROGRESS" --width=500 --height=100 --text="$MSG_ADVERTISEMENT"; then touch $HELP_PROGRESS_BAR else zero-center remove-pulsating-color install-moodle exit 1 fi #zero-installer install lliurex-preseed-moodle if [ ! -d "/etc/dbconfig-common" ]; then mkdir -p /etc/dbconfig-common fi #init DB #/usr/sbin/lliurex-preseed --update || true zero-installer -l /usr/share/lliurex-zero-installers/moodle-packages if [ $? -ne 0 ] then echo "$MSG_MOODLE_INSTALL_PROBLEM" zenity --info --text="$MSG_MOODLE_INSTALL_PROBLEM" & rm $HELP_PROGRESS_BAR zero-center set-non-configured install-moodle zero-center remove-pulsating-color install-moodle exit 1 fi ##if [ ! -d "/var/lib/moodle" ]; then ## mkdir -p /var/lib/moodle ## chown www-data:www-data /var/lib/moodle || true ##fi # Testing it MySQL is alive and the root passwd is available # "sudo" is mandatory here, I don't understand the correct reason... # if you are reading this comment, and know the answer...please contact with us # ##sudo mysql_root_passwd -i ##if [ $? -ne 0 ] ; then ## echo "Mysql is not working properly" ## exit 1 ##fi # Since the 0.61 version, which is required by lliurex-pmb the lliurex-sgbd utility uses # a simple mechanism to create a token in /tmp/db_is_present , a more useful mechanism that "NO" # at STDOUT. ##lliurex-sgbd --db_is_present lliurex-moodle ##if [ -f /tmp/db_is_present ]; then ## lliurex-sgbd --install lliurex-moodle ##else ## zenity --info --text="$MSG_AVISO" ## lliurex-sgbd --upgrade lliurex-moodle ##fi ##if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then ## . /usr/share/apache2/apache2-maintscript-helper ## apache2_invoke ensite moodle ##fi # create file moodle in /var/lib/dnsmasq/config ##if [ ! -d /var/lib/dnsmasq/config ]; then ## mkdir -p /var/lib/dnsmasq/config ##fi ##INTERNA=$(n4d-vars getvalues INTERNAL_DOMAIN | cut -d"'" -f2) ##if [ -z $INTERNA ]; then ## echo "Error al obtener INTERNAL_DOMAIN" ## echo "Se deja sin configurar dnsmasq para moodle" ##else ## if [ ! -d /var/lib/dnsmasq/config ]; then ## mkdir -p /var/lib/dnsmasq/config ## fi ## hostname=$(hostname) ## echo "cname=moodle."$INTERNA",$hostname."$INTERNA > /var/lib/dnsmasq/config/moodle ##fi #create ldap users in moodle ##if [ -n $INTERNA ]; then ## /usr/bin/python /usr/share/lliurex-moodle/update_moodle_sql.py ##fi ##a2ensite moodle || true ##service apache2 restart || true ##service dnsmasq restart || true #######MAIN PROGRAM########## ( tail -f $HELP_PROGRESS_BAR ) | zenity --progress \ --title="ZERO-MOODLE" \ --text="$MSG_INSTALLING_PROGRESS" \ --percentage=0 \ --auto-close \ --width=500 \ --auto-kill & if [ ! -d "/var/lib/moodle" ]; then mkdir -p /var/lib/moodle chown www-data:www-data /var/lib/moodle || true fi sleep 2 echo "10" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_1" >> $HELP_PROGRESS_BAR # Testing it MySQL is alive and the root passwd is available # "sudo" is mandatory here, I don't understand the correct reason... # if you are reading this comment, and know the answer...please contact with us # sudo mysql_root_passwd -i if [ $? -ne 0 ] ; then echo "$MSG_MYSQL_PROBLEM" zenity --info --text="$MSG_MOODLE_MYSQL_PROBLEM" & rm $HELP_PROGRESS_BAR zero-center set-non-configured install-moodle zero-center remove-pulsating-color install-moodle exit 1 fi echo "20" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_2" >> $HELP_PROGRESS_BAR # Since the 0.61 version, which is required by lliurex-pmb the lliurex-sgbd utility uses # a simple mechanism to create a token in /tmp/db_is_present , a more useful mechanism that "NO" # at STDOUT. lliurex-sgbd --db_is_present lliurex-moodle if [ ! -f /tmp/db_is_present ]; then lliurex-sgbd --install lliurex-moodle else #zenity --info --text="$MSG_MOODLE_AVISO" & lliurex-sgbd --upgrade lliurex-moodle fi echo "25" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_7" >> $HELP_PROGRESS_BAR #Copy lang files in var/lib/moodle if [ -d "/var/lib/moodle" ]; then if [ -d "/usr/share/lliurex-moodle/lang" ]; then cp -r /usr/share/lliurex-moodle/lang /var/lib/moodle/ chown -R www-data:www-data /var/lib/moodle/lang || true fi fi #Configuring Apache echo "30" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_3" >> $HELP_PROGRESS_BAR #if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then # . /usr/share/apache2/apache2-maintscript-helper # apache2_invoke ensite moodle #fi #maintainer script substitution to userland script a2ensite moodle echo "50" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_4" >> $HELP_PROGRESS_BAR # create file moodle in /var/lib/dnsmasq/config # if [ ! -d /var/lib/dnsmasq/config ]; then # mkdir -p /var/lib/dnsmasq/config # fi # INTERNA=$(n4d-vars getvalues INTERNAL_DOMAIN | cut -d"'" -f2) # if [ -z $INTERNA ]; then # echo "Error getting INTERNAL_DOMAIN" # echo "It's left to set dnsmasq for moodle" # else # if [ ! -d /var/lib/dnsmasq/config ]; then # mkdir -p /var/lib/dnsmasq/config # fi # hostname=$(hostname) #echo "cname=moodle."$INTERNA",$hostname."$INTERNA > /var/lib/dnsmasq/config/moodle MAGIC_KEY=$(cat /etc/n4d/key) n4d-client -h localhost -k $MAGIC_KEY -m set_internal_dns_entry -c Dnsmasq -a moodle #fi echo "70" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_5" >> $HELP_PROGRESS_BAR #create ldap users in moodle if [ -n $INTERNA ]; then /usr/bin/python /usr/share/lliurex-moodle/update_moodle_sql.py /usr/bin/python /usr/share/lliurex-moodle/sync_ldap_users.py fi echo "85" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_MOODLE_6" >> $HELP_PROGRESS_BAR a2ensite moodle || true service apache2 restart || true service dnsmasq restart || true #change permissions in /var/lib/moodle if [ -d "/var/lib/moodle" ]; then chown -R www-data:www-data /var/lib/moodle || true fi echo "100" >> $HELP_PROGRESS_BAR zenity --info --title="ZERO-MOODLE" --text="$MSG_MOODLE_INSTALLED" & #su $USER firefox http://moodle/ || true rm $HELP_PROGRESS_BAR zero-center set-configured install-moodle zero-center remove-pulsating-color install-moodle exit 0