#!/bin/bash zero-center add-pulsating-color zero-lliurex-jocomunico export TEXTDOMAIN="zero-lliurex-jocomunico" JOCOMUNICO_BASE_DIR="/var/lib/jocomunico" MSG_INSTALLING_PROGRESS=$(gettext "Configuration Service for joComunico in LliureX") MSG_ADVERTISEMENT=$(gettext "Do you want install and configure joComunico for LliureX?") MSG_JOCOMUNICO_INSTALL_PROBLEM=$(gettext "JoComunico has NOT been installed in your system. Please check the logs.") MSG_ZENITY_JOCOMUNICO_1=$(gettext "Testing Mysql....") MSG_JOCOMUNICO_MYSQL_PROBLEM=$(gettext "Mysql is not working properly") MSG_ZENITY_JOCOMUNICO_2=$(gettext "Creating a token....") MSG_ZENITY_JOCOMUNICO_3=$(gettext "Linking Apache with JoComunico....") MSG_ZENITY_JOCOMUNICO_4=$(gettext "Configuring DNS mask for joComunico in LliureX....") MSG_ZENITY_JOCOMUNICO_5=$(gettext "Linking LDAP with JoComunico....") MSG_ZENITY_JOCOMUNICO_6=$(gettext "Restarting services to apply new configurations....") MSG_JOCOMUNICO_INSTALLED=$(gettext "JoComunico has been installed in your system. You can check it with Chromium Browser in this URL http://jocomunico") HELP_PROGRESS_BAR="/tmp/help_jocomunico_install.txt" # Defining functions: function setvars(){ # Getting .my.cnf data awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' $1 } function configureDataBase(){ echo "Configuring Jocomunico Database info" DB_CONF_FILE="${JOCOMUNICO_BASE_DIR}/application/config/database.php"; DATABASE=jocomunicolliureX; DB_TMP=/tmp/db_tmp.php; # call to setvars setvars /root/.my.cnf | grep "\[mysql\]" > /tmp/mysqldatainfo # source from mysqldatainfo . /tmp/mysqldatainfo sed "s/'password' => 'root'/'password' => '$password'/;s/'database' => 'jocomunicoapp'/'database' => '$DATABASE'/;s/'username' => 'root'/'username' => '$user'/" $DB_CONF_FILE > $DB_TMP # When finished, let's set right files rm /tmp/mysqldatainfo cp $DB_TMP $DB_CONF_FILE rm $DB_TMP } 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 zero-lliurex-jocomunico exit 1 fi if [ ! -d "/etc/dbconfig-common" ]; then mkdir -p /etc/dbconfig-common fi #init DB zero-installer -l /usr/share/zero-lliurex-installers/zero-lliurex-jocomunico-packages if [ $? -ne 0 ] then echo "$MSG_JOCOMUNICO_INSTALL_PROBLEM" zenity --info --text="$MSG_JOCOMUNICO_INSTALL_PROBLEM" & rm $HELP_PROGRESS_BAR zero-center set-non-configured zero-lliurex-jocomunico zero-center remove-pulsating-color zero-lliurex-jocomunico exit 1 fi #######MAIN PROGRAM########## ( tail -f $HELP_PROGRESS_BAR ) | zenity --progress \ --title="ZERO-JOCOMUNICO" \ --text="$MSG_INSTALLING_PROGRESS" \ --percentage=0 \ --auto-close \ --width=500 \ --auto-kill & if [ ! -d "${JOCOMUNICO_BASE_DIR}" ]; then mkdir -p $JOCOMUNICO_BASE_DIR chown www-data:www-data $JOCOMUNICO_BASE_DIR || true fi sleep 2 echo "10" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_JOCOMUNICO_1" >> $HELP_PROGRESS_BAR # Testing if 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_JOCOMUNICO_MYSQL_PROBLEM" & rm $HELP_PROGRESS_BAR zero-center set-non-configured zero-lliurex-jocomunico zero-center remove-pulsating-color zero-lliurex-jocomunico exit 1 fi echo "20" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_JOCOMUNICO_2" >> $HELP_PROGRESS_BAR # Creates a token in /tmp/db_is_present if database exists lliurex-sgbd --db_is_present jocomunicolliureX if [ ! -f /tmp/db_is_present ]; then lliurex-sgbd --install jocomunicolliureX lliurex-sgbd --db_is_present jocomunicolliureX else lliurex-sgbd --upgrade jocomunicolliureX fi # Setting up database configureDataBase # mp3 dirs permissions chown root:www-data $JOCOMUNICO_BASE_DIR/mp3 chmod 2775 $JOCOMUNICO_BASE_DIR/mp3 # Creating link for /var/www [ -s /var/www/jocomunico ] || ln -s $JOCOMUNICO_BASE_DIR /var/www/jocomunico #Configuring Apache and modules echo "30" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_JOCOMUNICO_3" >> $HELP_PROGRESS_BAR a2enmod rewrite a2enmod headers a2ensite jocomunico echo "50" >> $HELP_PROGRESS_BAR echo "# $MSG_ZENITY_JOCOMUNICO_4" >> $HELP_PROGRESS_BAR MAGIC_KEY=$(cat /etc/n4d/key) n4d-client -h localhost -k $MAGIC_KEY -m set_internal_dns_entry -c Dnsmasq -a jocomunico echo "70" >> $HELP_PROGRESS_BAR # TO-DO ## MIRAR COM HO FEM AL POSTINST DE LA VERSIÓ ANTERIOR!!! # echo "# $MSG_ZENITY_JOCOMUNICO_5" >> $HELP_PROGRESS_BAR #create ldap users in jocomunico #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_JOCOMUNICO_6" >> $HELP_PROGRESS_BAR a2ensite jocomunico || true service apache2 restart || true service dnsmasq restart || true #change permissions in $JOCOMUNICO_BASE_DIR if [ -d "${JOCOMUNICO_BASE_DIR}" ]; then chown -R www-data:www-data $JOCOMUNICO_BASE_DIR || true fi echo "100" >> $HELP_PROGRESS_BAR zenity --info --title="ZERO-JOCOMUNICO" --text="$MSG_JOCOMUNICO_INSTALLED" & rm $HELP_PROGRESS_BAR zero-center set-configured zero-lliurex-jocomunico zero-center remove-pulsating-color zero-lliurex-jocomunico exit 0