#!/bin/bash

#
# #############################################################################
# ## Alladdin, the all-add-in web server                                     ##
# #############################################################################
#
# @author Laurent GAERTNER <garthh@bagsbug.net>
# @version $Revision$
# @modifiedby $Author$
# @lastmodified $Date$
#
# #############################################################################
# ## blog/online: set blog online                                            ##
# #############################################################################
#
# LICENSE:
# Alladdin is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Alladdin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. /etc/alladdin/alladdin.conf

## Vérification des paramètres associés
## Obligatoire : numéro de compte dans la base de données (acid)

if [ -z $1 ]
then
	echo "usage: alladdin online blog [account id]"
	exit 0
fi

## Sortie si ce n'est pas l'utilisateur root

if [ $LOGNAME != $execUser ]
then
	echo "Seul l'utilisateur $execUser peut invoquer cette commande"
	exit 0
fi

## Rechercher le nom du compte

requete="SELECT account_name FROM accounts WHERE acid=$1;"
accountName=$(mysql -u $sqlUser -p$sqlPass -h $sqlHost -P$sqlPort $sqlDB -e "$requete" -s -N)

## Activation de la page d'accueil en html

rm -rf $cloneDir/sites/$accountName-21-blog

echo "Alias /$accountName/-blog- $wwwDir/blog/$accountName" > $cloneDir/sites/$accountName-21-blog

## Mise à jour de la table des états

requete="UPDATE states SET account_state='online' WHERE acid=$1 AND package='blog'"
mysql -u $sqlUser -p$sqlPass -h $sqlHost -P$sqlPort $sqlDB -e "$requete"

exit 0
