#!/bin/bash ACTION="$1" BLOCKLY_DIR="/usr/share/blockly-arduino/blockly/" BLOCKLY_LANG_FILE="/usr/share/blockly-arduino/blockly/lang/code.js" TEMPLATE_LANG_FILE="/usr/share/blockly-arduino/template-lang/code.js" EASY_SITE_FILES="/usr/share/blockly-arduino/easy-sites/" EASY_SITE=$EASY_SITE_FILES"blockly-arduino.json" EASY_SITE_ICON=$EASY_SITE_FILES"blockly-arduino.svg" EASY_SITES_DIR="/var/lib/lliurex-www/links/" EASY_SITES_DIR_ICON="/usr/share/lliurex-www/srv/icons/" PACKAGE_LIST=$@ case $ACTION in postInstall) echo "Set default language..." session_lang=$LANG if [[ $session_lang == *"ca"* ]]; then config_lang="ca" else if [[ $session_lang == *"es"* ]];then config_lang="es" else config_lang="en" fi fi sed -e "s;%DEFAULT_LANG%;$config_lang;g" $TEMPLATE_LANG_FILE > $BLOCKLY_LANG_FILE echo "Creating link in /var/www..." ln -sf $BLOCKLY_DIR /var/www/blockly-arduino echo "Creatin easy-site..." cp $EASY_SITE $EASY_SITES_DIR chown www-data:www-data $EASY_SITES_DIR"blockly-arduino.json" || true cp $EASY_SITE_ICON $EASY_SITES_DIR_ICON echo "Enabling apache site for blockly@arduino..." a2ensite blockly-arduino.conf echo "Restarting apache service..." systemctl restart apache2.service echo "Creating dnsmasq..." MAGIC_KEY=$(cat /etc/n4d/key) hostname=$(hostname) if [ "$hostname" != "blockly-arduino" ]; then n4d-client -a https://server:9779 -k $MAGIC_KEY call DnsmasqManager.set_internal_dns_entry "['blockly-arduino']" || true fi systemctl restart dnsmasq ;; remove) for ix in $PACKAGE_LIST do case $ix in blockly-arduino) echo "Removing package..." apt-get remove -y $ix TEST=$( dpkg-query -s $ix 2> /dev/null| grep Status | cut -d " " -f 4 ) if [ "$TEST" == 'installed' ];then exit 1 fi rm -rf /usr/share/blockly-arduino echo "Disabling site..." a2dissite blockly-arduino.conf rm -f /var/www/blockly-arduino echo "Removin easy-site..." rm -f $EASY_SITES_DIR"blockly-arduino.json" rm -f $EASY_SITES_DIR_ICON"blockly-arduino.svg" echo "Restarting apache service..." systemctl restart apache2.service ;; esac done ;; esac