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

206 lines
6.7 KiB
Text
Raw Normal View History

2014-06-17 23:42:54 +02:00
#!/bin/bash
2016-05-20 00:00:38 +02:00
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
2014-06-17 23:42:54 +02:00
# Retrieve arguments
2016-05-20 00:00:38 +02:00
if [ $ynh_version = "2.4" ]
then
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
user_pwd=$YNH_APP_ARG_PASSWORD
language=$YNH_APP_ARG_LANGUAGE
market=$YNH_APP_ARG_MARKET
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
2016-06-04 23:09:25 +02:00
source /usr/share/yunohost/helpers
2016-05-20 00:00:38 +02:00
else
domain=$1
path=$2
admin=$3
user_pwd=$4
language=$5
market=$6
is_public=$7
app=leed
fi
2016-06-04 23:56:27 +02:00
# Checks variables are not empty
test -z "$domain" && (echo "domain not set" && touch /force_stop)
test -z "$path" && (echo "path not set" && touch /force_stop)
test -z "$admin" && (echo "admin not set" && touch /force_stop)
test -z "$user_pwd" && (echo "user_pwd not set" && touch /force_stop)
test -z "$language" && (echo "language not set" && touch /force_stop)
test -z "$market" && (echo "market not set" && touch /force_stop)
test -z "$is_public" && (echo "is_public not set" && touch /force_stop)
2016-05-20 00:00:38 +02:00
# Delete files and db if exit with an error
EXIT_PROPERLY () {
2016-06-04 23:09:25 +02:00
trap ERR
2016-05-20 00:00:38 +02:00
echo -e "\e[91m \e[1m" # Shell in light red bold
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
echo -e "\e[22m" # Remove bold
# Clean hosts
sudo sed -i '/#leed/d' /etc/hosts
if [ $ynh_version = "2.2" ]; then
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.
fi
exit 1
}
TRAP_ON () { # Activate signal capture
trap EXIT_PROPERLY ERR # Capturing exit signals on error
}
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
# Mais pas la fonction TRAP_OFF...
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
trap '' ERR # Ignoring exit signals
}
TRAP_ON
2014-06-17 23:42:54 +02:00
2015-11-22 14:37:01 +01:00
# Vérifie la validité de l'user admin
sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" || (echo "Wrong admin" && touch /force_stop 2> /dev/null)
2014-06-17 23:42:54 +02:00
2015-11-22 14:37:01 +01:00
# Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
2014-06-17 23:42:54 +02:00
# Vérifie que le mot de passe n'est pas vide.
if [[ -z $user_pwd ]]; then
echo "Mot de passe incorrect"
touch /force_stop 2> /dev/null
fi
2015-11-22 14:37:01 +01:00
# Vérifie que le dossier de destination n'est pas déjà utilisé.
final_path=/var/www/$app
if [ -e "$final_path" ]
then
echo "This path already contains a folder"
touch /force_stop 2> /dev/null
2015-11-22 14:37:01 +01:00
fi
2015-11-22 14:37:01 +01:00
# Vérifie la présence du / en début de path
if [ $(echo $path | cut -c1) != "/" ]; then
path="/$path"
fi
2014-06-17 23:42:54 +02:00
2015-11-22 14:37:01 +01:00
# Enregistre les infos dans la config YunoHost
sudo yunohost app setting $app admin -v $admin
sudo yunohost app setting $app language -v $language
sudo yunohost app setting $app domain -v $domain
# Génère un mot de passe aléatoire.
2016-05-20 00:00:38 +02:00
db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
2015-11-22 14:37:01 +01:00
# Utilise '$app' comme nom d'utilisateur et de base de donnée
db_user=$app
# Initialise la base de donnée et stocke le mot de passe mysql.
2016-05-20 00:00:38 +02:00
if [ $ynh_version = "2.4" ]; then
ynh_mysql_create_db $db_user $db_user $db_pwd
else
sudo yunohost app initdb $db_user -p $db_pwd
fi
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app mysqlpwd -v $db_pwd
# Crée le repertoire de destination et stocke son emplacement.
sudo mkdir "$final_path"
sudo yunohost app setting $app final_path -v $final_path
# Décompresse la source
tar -x -f ../sources/leed.tar.gz
# Copie les fichiers sources
sudo cp -a leed/. "$final_path"
# Copie les fichiers additionnels ou modifiés.
# sudo cp -a ../sources/ajouts/. "$final_path"
# Et copie le fichier de config nginx
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Modifie les variables dans le fichier de configuration nginx
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
# Créer le fichier de configuration du pool php-fpm et le configure.
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
sudo cp ../conf/php-fpm.ini $finalphpini
sudo chown root: $finalphpini
sudo service php5-fpm reload
2014-06-17 23:42:54 +02:00
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
# Rend la page d'install publique pour curl
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app unprotected_uris -v "/" #L'usage de unprotected_uris a la place de skipped_uris permet de passer le header d'auth http
sudo yunohost app ssowatconf
# Reload Nginx
sudo service nginx reload
2014-06-17 23:42:54 +02:00
# Leed installation via curl
2015-11-22 14:37:01 +01:00
echo "127.0.0.1 $domain #leed" | sudo tee -a /etc/hosts
2014-06-17 23:42:54 +02:00
sleep 1
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-10-20 02:10:52 +02:00
# Activate Leed Market if necessary
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app market -v "$market"
2014-10-20 02:10:52 +02:00
if [ "$market" = "Yes" ];
then
sudo rm -R $final_path/plugins
sudo git clone https://github.com/ldleman/Leed-market.git $final_path/plugins
fi
2015-11-22 14:37:01 +01:00
# Configure les droits d'accès au fichiers
# -rw-r--r-- sur les fichiers
sudo find $final_path -type f | xargs sudo chmod 644
2015-11-22 14:37:01 +01:00
# drwxr-xr-x sur les dossiers
sudo find $final_path -type d | xargs sudo chmod 755
2015-11-22 14:37:01 +01:00
# Les fichiers appartiennent à root
sudo chown -R root: $final_path
2015-11-22 14:37:01 +01:00
# www-data doit avoir les droits d'écriture dans plugins et cache
sudo mkdir $final_path/cache
sudo chown -R www-data $final_path/cache $final_path/plugins
2015-11-22 14:37:01 +01:00
# Récupération du code de synchronisation
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)
# 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
2015-11-22 14:37:01 +01:00
sudo cp ../conf/cron_leed /etc/cron.d/$app
# Make app private if necessary
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app is_public -v "$is_public"
if [ "$is_public" = "No" ];
then
# Retire l'autorisation d'accès de la page d'install.
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app unprotected_uris -d
# Rend la page d'actualisation accessible pour le script cron.
2015-11-22 14:37:01 +01:00
sudo yunohost app setting $app skipped_uris -v "/action.php"
sudo yunohost app ssowatconf
fi
# Clean hosts
2015-11-22 14:37:01 +01:00
sudo sed -i '/#leed/d' /etc/hosts
# Recharge la configuration php5-fpm
# sudo service php5-fpm reload