#!/bin/bash set -e 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=/opt/jocomunico/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 } case $1 in configure) # mp3 dirs permissions chown root:www-data /opt/jocomunico/mp3 chmod 2775 /opt/jocomunico/mp3 # Create html if it does not exists OLDERDOCUMENTROOT=0; if [ ! -d /var/www/html ]; then mkdir /var/www/html OLDERDOCUMENTROOT=1; fi # Creating links for /var/www [ -s /var/www/html/jocomunico ] || ln -s /opt/jocomunico /var/www/html/jocomunico if [ $OLDERDOCUMENTROOT -eq 1 ]; then [ -s /var/www/jocomunico ] || ln -s /var/www/html/jocomunico /var/www/jocomunico fi # Enable modules? a2enmod-lliurex rewrite a2enmod-lliurex headers a2ensite-lliurex jocomunico # if is not enables // WIP # Add jocomunico to hosts [[ `cat /etc/hosts | grep jocomunico | wc -l` >0 ]] || echo "127.0.0.1 jocomunico" >> /etc/hosts # Reloading apache systemctl restart apache2-lliurex # Setting up database lliurex-sgbd --db_is_present jocomunicolliureX if [ ! -f /tmp/db_is_present ]; then lliurex-sgbd --install jocomunicolliureX lliurex-sgbd --db_is_present jocomunicolliureX else #zenity --info --text="$MSG_MOODLE_AVISO" & lliurex-sgbd --upgrade jocomunicolliureX fi # Setting up database configureDataBase ;; abort-upgrade|abort-remove|abort-deconfigure) echo "postinst called with argument \`$1'" >&2 exit 1 ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac #DEBHELPER# exit 0