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

Last change on this file since 2110 was 2110, checked in by Juanma, 3 years ago

WIP on notifications and installation results

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