mirror of
https://github.com/YunoHost-Apps/spip_ynh.git
synced 2024-09-03 20:25:59 +02:00
118 lines
No EOL
3.7 KiB
Bash
118 lines
No EOL
3.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
|
|
|
|
CLEAN_SETUP () {
|
|
# Nettoyage des résidus d'installation non pris en charge par le script remove.
|
|
# Clean hosts
|
|
sudo sed -i '/#SPIP/d' /etc/hosts
|
|
}
|
|
TRAP_ON # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path=$YNH_APP_ARG_PATH
|
|
admin_spip=$YNH_APP_ARG_ADMIN
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
#multisite=$YNH_APP_ARG_MULTISITE
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Source app helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
CHECK_USER "$admin_spip"
|
|
|
|
CHECK_PATH
|
|
|
|
CHECK_DOMAINPATH
|
|
|
|
CHECK_FINALPATH
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
ynh_app_setting_set $app path $path
|
|
ynh_app_setting_set $app admin $admin_spip
|
|
ynh_app_setting_set $app is_public $is_public
|
|
ynh_app_setting_set $app language $language
|
|
#ynh_app_setting_set $app multisite $multisite
|
|
|
|
GENERATE_DB $app # Créer une base de données et un utilisateur dédié au nom de l'app.
|
|
|
|
# Crée le repertoire de destination et stocke son emplacement.
|
|
sudo mkdir "$final_path"
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
SETUP_SOURCE "spip-3.1.zip"
|
|
|
|
# Set permissions to spip directory
|
|
sudo chown -R www-data: $final_path
|
|
|
|
echo -e "127.0.0.1 $domain #SPIP" | sudo tee -a /etc/hosts
|
|
|
|
# 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@__PATHTOCHANGE__@$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
|
|
|
|
POOL_FPM
|
|
|
|
sudo cp ../conf/connect.php $final_path/config/connect.php
|
|
sudo cp ../conf/mes_options.php $final_path/config/mes_options.php
|
|
|
|
# Changer les variables du ficher de configuration de SPIP
|
|
sudo sed -i "s/__DB_USER__/$db_user/g" $final_path/config/connect.php
|
|
sudo sed -i "s/__DB_PWD__/$db_pwd/g" $final_path/config/connect.php
|
|
|
|
db_md5=$(echo $db_pwd | md5sum | awk '{print $1}')
|
|
db_sha=$(echo $db_pwd | openssl dgst -sha1 -hmac "key" | awk -F'= ' {'print $2'})
|
|
|
|
# Changer les informations de la tables spip_auteurs
|
|
sudo sed -i "s@__ADMIN_SPIP__@$admin_spip@g" ../conf/sql/spip.sql
|
|
sudo sed -i "s@__DB_USER__@$db_user@g" ../conf/sql/spip.sql
|
|
sudo sed -i "s@__DB_PWD__@$db_md5@g" ../conf/sql/spip.sql
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" ../conf/sql/spip.sql
|
|
sudo sed -i "s@__DB_SHA__@$db_sha@g" ../conf/sql/spip.sql
|
|
|
|
for i in 1 2 3 4 5 6 7 8
|
|
do
|
|
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
if [ "$j" = "" ];
|
|
then
|
|
# For obscure reasons, the loop is too fast at execution
|
|
sleep 1
|
|
j=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
|
|
fi
|
|
sudo sed -i "s/__ALEA_ACTUEL__/$j/g" ../conf/sql/spip.sql
|
|
sudo sed -i "s/__ALEA_FUTUR__/$j/g" ../conf/sql/spip.sql
|
|
done
|
|
|
|
# Charger la structure des tables dans la base.
|
|
mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/spip.sql
|
|
|
|
# Donne un accès public pour curl
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
# Régénère la configuration de SSOwat
|
|
sudo yunohost app ssowatconf
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
sudo service php5-fpm restart
|
|
sudo service nginx reload
|
|
|
|
if [ "$is_public" = "No" ];
|
|
then
|
|
# Retire l'accès public
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
sudo yunohost app ssowatconf
|
|
fi
|
|
|
|
# Nettoyer hosts
|
|
sudo sed -i '/#SPIP/d' /etc/hosts |