source: lliurex-zero-installers/trunk/fuentes/zero-lliurex-moodle.zmds/install-moodle.zmd @ 1558

Last change on this file since 1558 was 1558, checked in by jrpelegrina, 3 years ago

Fix cname of moodle for master and independent servers

File size: 6.8 KB
Line 
1#!/bin/bash
2
3zero-center add-pulsating-color install-moodle
4
5export TEXTDOMAIN="zero-lliurex-moodle"
6MSG_INSTALLING_PROGRESS=$(gettext "Configurator Service for Moodle in LliureX")
7MSG_ADVERTISEMENT=$(gettext "Do you want install and configure Moodle for LliureX?")
8MSG_ZENITY_MOODLE_1=$(gettext "Testing Mysql....")
9MSG_MOODLE_MYSQL_PROBLEM=$(gettext "Mysql is not working properly")
10MSG_ZENITY_MOODLE_2=$(gettext "Creating a token....") 
11MSG_MOODLE_AVISO=$(gettext "Activating new token")
12MSG_ZENITY_MOODLE_3=$(gettext "Linking Apache with Moodle....")
13MSG_ZENITY_MOODLE_4=$(gettext "Configuring DNS mask for Moodle in LliureX....")
14MSG_ZENITY_MOODLE_5=$(gettext "Linking LDAP with Moodle....")
15MSG_ZENITY_MOODLE_6=$(gettext "Restarting services to apply new configurations....")
16MSG_ZENITY_MOODLE_7=$(gettext "Configuring installed languages in Moodle....")
17MSG_MOODLE_INSTALLED=$(gettext "Moodle has been installed in your system. You can check it with firefox in this URL http://moodle")
18
19HELP_PROGRESS_BAR="/tmp/help_moodle_install.txt"
20
21if zenity --question --title="$MSG_INSTALLING_PROGRESS" --width=500 --height=100 --text="$MSG_ADVERTISEMENT"; then
22        touch $HELP_PROGRESS_BAR
23else
24        zero-center remove-pulsating-color install-moodle
25        exit 1
26fi
27
28#zero-installer  install lliurex-preseed-moodle
29
30if [ ! -d "/etc/dbconfig-common" ]; then
31     mkdir -p /etc/dbconfig-common   
32fi 
33
34#init DB
35#/usr/sbin/lliurex-preseed --update || true
36
37zero-installer -l /usr/share/lliurex-zero-installers/moodle-packages
38
39##if [ ! -d "/var/lib/moodle" ]; then
40##      mkdir -p /var/lib/moodle
41##      chown www-data:www-data /var/lib/moodle || true
42##fi
43
44# Testing it MySQL is alive and the root passwd is available
45# "sudo" is mandatory here, I don't understand the correct reason...
46# if you are reading this comment, and know the answer...please contact with us
47#
48##sudo mysql_root_passwd -i
49
50##if [ $? -ne 0 ] ; then
51##      echo "Mysql is not working properly"
52##      exit 1
53##fi
54
55
56# Since the 0.61 version, which is required by lliurex-pmb the lliurex-sgbd utility uses
57# a simple mechanism to create a token in /tmp/db_is_present , a more useful mechanism that "NO"
58# at STDOUT. 
59##lliurex-sgbd --db_is_present lliurex-moodle
60##if [ -f /tmp/db_is_present ]; then
61##      lliurex-sgbd --install lliurex-moodle
62##else
63##      zenity --info --text="$MSG_AVISO"
64##      lliurex-sgbd --upgrade lliurex-moodle
65##fi
66
67
68##if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
69
70##      . /usr/share/apache2/apache2-maintscript-helper
71##      apache2_invoke ensite moodle
72
73##fi
74
75# create file moodle in /var/lib/dnsmasq/config
76##if [ ! -d /var/lib/dnsmasq/config ]; then
77##      mkdir -p /var/lib/dnsmasq/config
78##fi
79
80##INTERNA=$(n4d-vars getvalues INTERNAL_DOMAIN | cut -d"'" -f2)
81##if [ -z $INTERNA ]; then
82##      echo "Error al obtener INTERNAL_DOMAIN"
83##      echo "Se deja sin configurar dnsmasq para moodle"
84##else
85##      if [ ! -d /var/lib/dnsmasq/config ]; then
86##              mkdir -p /var/lib/dnsmasq/config
87##      fi
88##      hostname=$(hostname)
89##      echo "cname=moodle."$INTERNA",$hostname."$INTERNA > /var/lib/dnsmasq/config/moodle
90       
91##fi
92
93#create ldap users in moodle
94##if [ -n $INTERNA ]; then
95##      /usr/bin/python /usr/share/lliurex-moodle/update_moodle_sql.py
96##fi
97
98##a2ensite moodle || true
99
100##service apache2 restart || true
101
102##service dnsmasq restart || true
103
104
105#######MAIN PROGRAM##########
106
107( tail -f $HELP_PROGRESS_BAR
108) |
109zenity --progress \
110  --title="ZERO-MOODLE" \
111  --text="$MSG_INSTALLING_PROGRESS" \
112  --percentage=0 \
113  --auto-close \
114   --width=500 \
115  --auto-kill &
116 
117
118 
119if [ ! -d "/var/lib/moodle" ]; then
120        mkdir -p /var/lib/moodle
121        chown www-data:www-data /var/lib/moodle || true
122fi
123sleep 2
124echo "10" >> $HELP_PROGRESS_BAR
125echo "# $MSG_ZENITY_MOODLE_1"   >> $HELP_PROGRESS_BAR
126# Testing it MySQL is alive and the root passwd is available
127# "sudo" is mandatory here, I don't understand the correct reason...
128# if you are reading this comment, and know the answer...please contact with us
129#
130sudo mysql_root_passwd -i
131
132if [ $? -ne 0 ] ; then
133        echo "$MSG_MYSQL_PROBLEM"
134        zenity --info --text="$MSG_MOODLE_MYSQL_PROBLEM" &
135        rm $HELP_PROGRESS_BAR
136        zero-center set-non-configured install-moodle   
137        zero-center remove-pulsating-color install-moodle
138        exit 1
139fi
140echo "20" >> $HELP_PROGRESS_BAR
141echo "# $MSG_ZENITY_MOODLE_2"  >> $HELP_PROGRESS_BAR
142# Since the 0.61 version, which is required by lliurex-pmb the lliurex-sgbd utility uses
143# a simple mechanism to create a token in /tmp/db_is_present , a more useful mechanism that "NO"
144# at STDOUT. 
145lliurex-sgbd --db_is_present lliurex-moodle
146if [ ! -f /tmp/db_is_present ]; then
147        lliurex-sgbd --install lliurex-moodle
148else
149        #zenity --info --text="$MSG_MOODLE_AVISO" &
150        lliurex-sgbd --upgrade lliurex-moodle
151fi
152
153echo "25" >> $HELP_PROGRESS_BAR
154echo "# $MSG_ZENITY_MOODLE_7"  >> $HELP_PROGRESS_BAR
155#Copy lang files in var/lib/moodle
156if [ -d "/var/lib/moodle" ]; then
157        if [ -d "/usr/share/lliurex-moodle/lang" ]; then
158                cp -r /usr/share/lliurex-moodle/lang /var/lib/moodle/
159                chown -R www-data:www-data /var/lib/moodle/lang || true
160        fi
161fi             
162
163#Configuring Apache
164echo "30" >> $HELP_PROGRESS_BAR
165echo "# $MSG_ZENITY_MOODLE_3" >> $HELP_PROGRESS_BAR
166#if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
167#       . /usr/share/apache2/apache2-maintscript-helper
168#       apache2_invoke ensite moodle
169#fi
170#maintainer script substitution to userland script
171a2ensite moodle
172
173echo "50" >> $HELP_PROGRESS_BAR
174echo "# $MSG_ZENITY_MOODLE_4" >> $HELP_PROGRESS_BAR
175# create file moodle in /var/lib/dnsmasq/config
176# if [ ! -d /var/lib/dnsmasq/config ]; then
177#       mkdir -p /var/lib/dnsmasq/config
178# fi
179# INTERNA=$(n4d-vars getvalues INTERNAL_DOMAIN | cut -d"'" -f2)
180# if [ -z $INTERNA ]; then
181#       echo "Error getting INTERNAL_DOMAIN"
182#       echo "It's left to set dnsmasq for moodle"
183# else
184        # if [ ! -d /var/lib/dnsmasq/config ]; then
185        #       mkdir -p /var/lib/dnsmasq/config
186        # fi
187        # hostname=$(hostname)
188        #echo "cname=moodle."$INTERNA",$hostname."$INTERNA > /var/lib/dnsmasq/config/moodle
189MAGIC_KEY=$(cat /etc/n4d/key)
190n4d-client -h localhost -k $MAGIC_KEY -m set_internal_dns_entry -c Dnsmasq -a moodle
191       
192#fi
193echo "70"  >> $HELP_PROGRESS_BAR
194echo "# $MSG_ZENITY_MOODLE_5"  >> $HELP_PROGRESS_BAR
195#create ldap users in moodle
196if [ -n $INTERNA ]; then
197        /usr/bin/python /usr/share/lliurex-moodle/update_moodle_sql.py
198        /usr/bin/python /usr/share/lliurex-moodle/sync_ldap_users.py
199fi
200echo "85"  >> $HELP_PROGRESS_BAR
201echo "# $MSG_ZENITY_MOODLE_6"  >> $HELP_PROGRESS_BAR
202
203a2ensite moodle || true
204
205service apache2 restart || true
206
207service dnsmasq restart || true
208
209#change permissions in /var/lib/moodle
210
211if [ -d "/var/lib/moodle" ]; then
212                chown -R www-data:www-data /var/lib/moodle || true
213
214fi     
215
216echo "100"  >> $HELP_PROGRESS_BAR
217
218
219zenity --info --title="ZERO-MOODLE" --text="$MSG_MOODLE_INSTALLED" &
220
221#su $USER firefox http://moodle/ || true
222rm $HELP_PROGRESS_BAR
223zero-center set-configured install-moodle   
224zero-center remove-pulsating-color install-moodle
225
226exit 0
Note: See TracBrowser for help on using the repository browser.