#!/bin/bash ACTION="$1" EASY_SITE_FILES="/usr/share/lliurex-moodle/easy-site/" EASY_SITE=$EASY_SITE_FILES"moodle.json" EASY_SITE_ICON=$EASY_SITE_FILES"moodle.svg" EASY_SITES_DIR="/var/lib/lliurex-www/links/" EASY_SITES_DIR_ICON="/usr/share/lliurex-www/srv/icons/" case $ACTION in preInstall) if [ ! -d "/etc/dbconfig-common" ]; then mkdir -p /etc/dbconfig-common fi ;; postInstall) echo "Creating folder..." if [ ! -d "/var/lib/moodle" ]; then mkdir -p /var/lib/moodle chown www-data:www-data /var/lib/moodle || true fi sleep 2 echo "Testing mysql..." sudo mysql_root_passwd -i if [ $? -ne 0 ] ; then echo "Mysql is not working..." exit 1 fi echo "Checking if moodle db exists..." lliurex-sgbd --db_is_present lliurex-moodle if [ ! -f /tmp/db_is_present ]; then echo "Creating moodle db..." lliurex-sgbd --install lliurex-moodle else #zenity --info --text="$MSG_MOODLE_AVISO" & echo "Updating moodle db..." lliurex-sgbd --upgrade lliurex-moodle fi echo "Copying lang files..." 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 echo "Configuring Apache..." a2ensite moodle echo "Creating hostname..." MAGIC_KEY=$(cat /etc/n4d/key) n4d-client -h localhost -k $MAGIC_KEY -m set_internal_dns_entry -c Dnsmasq -a moodle echo "Creating Ldadp users..." INTERNA=$(n4d-vars getvalues INTERNAL_DOMAIN | cut -d"'" -f2) if [ -n $INTERNA ]; then /usr/bin/python3 /usr/share/lliurex-moodle/update_moodle_sql.py /usr/bin/python3 /usr/share/lliurex-moodle/sync_ldap_users.py fi echo "Restarting services..." a2ensite moodle || true service apache2 restart || true service dnsmasq restart || true echo "Changing permissions in ..." if [ -d "/var/lib/moodle" ]; then chown -R www-data:www-data /var/lib/moodle || true fi echo "Creating easy-site..." cp $EASY_SITE $EASY_SITES_DIR chown www-data:www-data $EASY_SITES_DIR"moodle.json" || true cp $EASY_SITE_ICON $EASY_SITES_DIR_ICON ;; remove) apt-get remove -y lliurex-moodle TEST=$( dpkg-query -s lliurex-moodle 2> /dev/null| grep Status | cut -d " " -f 4 ) if [ "$TEST" == 'installed' ];then exit 1 fi echo "Removing easy-site..." rm -f $EASY_SITES_DIR"moodle.json" rm -f $EASY_SITES_DIR_ICON"moodle.svg" ;; esac exit 0