1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/leed_ynh.git synced 2024-09-03 19:26:32 +02:00
leed_ynh/scripts/install
Maniack Crudelis 5b0c0a53c5 Correction du script d'install
- Ajout du mot de passe utilisateur.
- Correction de l'appel curl pour la web install
- Mise en place de la synchronisation des flux par cron
2014-08-17 17:46:25 +02:00

85 lines
2.8 KiB
Bash

#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
admin=$3
user_pwd=$4
language=$5
# 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
exit 1
fi
# Vérifie que le mot de passe n'est pas vide.
if [[ -z $user_pwd ]]; then
echo "Mot de passe incorrect"
exit 1
fi
# Add settings to YunoHost
sudo yunohost app setting leed admin -v $admin
sudo yunohost app setting leed language -v $language
sudo yunohost app setting leed domain -v $domain
# 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
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/leed.conf
# Set right permissions
sudo chown -R www-data: $final_path
# 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
# Rend la page d'install publique pour curl
sudo yunohost app setting leed skipped_uris -v "/"
sudo yunohost app ssowatconf
# Reload Nginx
sudo service nginx reload
# Leed installation via curl
echo "127.0.0.1 $domain #yunoleed" | sudo tee -a /etc/hosts
sleep 1
curl -k --cookie-jar cookies.txt "https://$domain$path/install.php?installButton&install_changeLngLeed=$language&root=$domain$path&mysqlHost=localhost&mysqlLogin=$db_user&mysqlMdp=$db_pwd&mysqlBase=$db_user&mysqlPrefix=leed_&login=$admin&password=$user_pwd" > /dev/null
# Récupération du code de synchronisation
code_sync=$(wget --load-cookies cookies.txt https://$domain$path/settings.php#preferenceBloc && cat settings.php | grep -C 1 "<p><strong>Code de synchronisation :</strong>" | sed -n 3p | sed 's/^[ \t]*//')
# Mise en place du cron pour la synchronisation
sudo crontab -l -u $admin > crontab_file
echo "# Mise a jour de leed toutes les 2 heures." >> crontab_file
echo "0 */2 * * * wget -q \"https://$domain$path/action.php?action=synchronize&code=$code_sync\"" >> crontab_file
sudo crontab -u $admin crontab_file
# Retire l'autorisation d'accès de la page d'install.
sudo yunohost app setting leed skipped_uris -d
# Rend la page d'actualisation accessible pour le script cron.
sudo yunohost app setting leed skipped_uris -v "/action.php"
sudo yunohost app ssowatconf
# Clean hosts
sudo sed -i '/yunoleed/d' /etc/hosts