2014-06-17 23:42:54 +02:00
#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
admin=$3
2014-08-17 17:46:25 +02:00
user_pwd=$4
language=$5
2014-08-20 13:27:58 +02:00
is_public=$6
2014-06-17 23:42:54 +02:00
# Check if admin exists
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong admin"
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a leed
if [[ ! $? -eq 0 ]]; then
2014-06-18 00:27:40 +02:00
exit 1
2014-06-17 23:42:54 +02:00
fi
2014-08-17 17:46:25 +02:00
# Vérifie que le mot de passe n'est pas vide.
if [[ -z $user_pwd ]]; then
echo "Mot de passe incorrect"
exit 1
fi
2014-06-18 00:19:09 +02:00
# Add settings to YunoHost
sudo yunohost app setting leed admin -v $admin
sudo yunohost app setting leed language -v $language
2014-06-18 00:30:47 +02:00
sudo yunohost app setting leed domain -v $domain
2014-06-18 00:19:09 +02:00
2014-06-17 23:42:54 +02:00
# Generate random password
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
# Use 'leed' as database name and user
db_user=leed
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting leed mysqlpwd -v $db_pwd
# Copy files to right place
final_path=/var/www/leed
2014-06-17 23:59:58 +02:00
sudo mkdir -p $final_path
2014-06-17 23:42:54 +02:00
sudo cp -a ../sources/* $final_path
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/leed.conf
2014-06-18 00:27:40 +02:00
2014-08-21 23:34:29 +02:00
# Set right permissions for curl install
sudo chown -R www-data: $final_path
2014-06-17 23:42:54 +02:00
# Change variables in Leed configuration
sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/leed.conf
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/leed.conf
2014-08-17 17:46:25 +02:00
# Rend la page d'install publique pour curl
2014-08-23 19:54:19 +02:00
sudo yunohost app setting leed unprotected_uris -v "/" #L'usage de unprotected_uris a la place de skipped_uris permet de passer le header d'auth http
2014-08-17 17:46:25 +02:00
sudo yunohost app ssowatconf
# Reload Nginx
sudo service nginx reload
2014-06-17 23:42:54 +02:00
# Leed installation via curl
echo "127.0.0.1 $domain #yunoleed" | sudo tee -a /etc/hosts
sleep 1
2014-08-23 19:54:19 +02:00
curl -k --data "install_changeLngLeed=$language&root=$domain$path&mysqlHost=localhost&mysqlLogin=$db_user&mysqlMdp=$db_pwd&mysqlBase=$db_user&mysqlPrefix=leed_&login=$admin&password=$user_pwd" https://$domain$path/install.php?installButton > /dev/null
2014-08-21 23:30:09 +02:00
# Files owned by root, www-data can just read
2014-08-21 23:38:23 +02:00
sudo mkdir $final_path/cache
2014-08-21 23:30:09 +02:00
sudo find $final_path -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755
sudo chown -R root: $final_path
2014-08-23 19:54:19 +02:00
www-data can write on plugins and cache
2014-08-21 23:30:09 +02:00
sudo chown -R www-data $final_path/cache $final_path/plugins
2014-08-17 17:46:25 +02:00
# Récupération du code de synchronisation
2014-08-23 19:54:19 +02:00
code_sync=$(mysql -h localhost -u $db_user -p$db_pwd -s $db_user -e 'SELECT value FROM leed_configuration WHERE `key`="synchronisationCode"' | sed -n 1p)
2014-08-17 17:46:25 +02:00
# Mise en place du cron pour la synchronisation
2014-09-15 10:45:12 +02:00
sed -i "s@__ADMIN__@$admin@g" ../conf/cron_leed
sed -i "s@__DOMAIN__@$domain@g" ../conf/cron_leed
sed -i "s@__PATH__@$path@g" ../conf/cron_leed
sed -i "s@__CODESYNC__@$code_sync@g" ../conf/cron_leed
sudo cp ../conf/cron_leed /etc/cron.d/leed
2014-08-17 17:46:25 +02:00
2014-08-20 13:27:58 +02:00
# Make app private if necessary
sudo yunohost app setting leed is_public -v "$is_public"
if [ "$is_public" = "No" ];
then
# Retire l'autorisation d'accès de la page d'install.
2014-08-21 23:05:50 +02:00
sudo yunohost app setting leed unprotected_uris -d
2014-08-20 13:27:58 +02:00
# Rend la page d'actualisation accessible pour le script cron.
sudo yunohost app setting leed skipped_uris -v "/action.php"
sudo yunohost app ssowatconf
fi
2014-08-17 17:46:25 +02:00
# Clean hosts
sudo sed -i '/yunoleed/d' /etc/hosts