#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE FAILURE OF THE SCRIPT #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin_wordpress=$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 #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) # Check web path availability ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. if [ "$path_url" == "/" ] && [ $multisite -eq 1 ]; then ynh_die "Multisite option of wordpress doesn't work at root of domain." fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app admin $admin_wordpress ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app language $language ynh_app_setting_set $app multisite $multisite #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= ynh_install_app_dependencies php5-cli #================================================= # CREATE A SQL BDD #================================================= db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= # Create a system user ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE WP-CONFIG #================================================= sudo cp ../conf/wp-config.php $final_path/wp-config.php # Change variables in Wordpress configuration ynh_replace_string "__DB_USER__" "$db_name" $final_path/wp-config.php ynh_replace_string "__DB_PWD__" "$db_pwd" $final_path/wp-config.php ynh_replace_string "__DOMAIN__" "$domain" $final_path/wp-config.php ynh_replace_string "__PATH__" "$path_url" $final_path/wp-config.php 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 ynh_replace_string "KEY$i" "$j" $final_path/wp-config.php done #================================================= # SETTING UP WITH CURL #================================================= # Set right permissions for curl install sudo chown -R $app: $final_path # Rend la page d'install publique pour curl ynh_app_setting_set $app unprotected_uris "/" sudo yunohost app ssowatconf # Régénère la configuration de SSOwat # Reload Nginx sudo systemctl reload nginx # Wordpress installation ynh_local_curl "/wp-admin/install.php?step=2" "&weblog_title=YunoBlog" "user_name=$admin_wordpress" "admin_password=$db_pwd" "admin_password2=$db_pwd" "admin_email=$admin_wordpress@$domain" "language=$language" "Submit=Install+WordPress" WARNING echo -n "Please wait during Wordpress installation" for i in `seq 1 300` do # La boucle attend la fin de l'installation de wordpress Ou 5 minutes. if ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "show tables" | grep -q "wp_options"; then break # Si la table wp_options est trouvée, l'installation de wordpress est terminée. Quitte la boucle. fi WARNING echo -n "." sleep 1 done WARNING echo "" #================================================= # INSTALL WORDPRESS' PLUGINS #================================================= sudo wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O $final_path/wp-cli.phar php $final_path/wp-cli.phar --allow-root plugin install simple-ldap-login --path=$final_path php $final_path/wp-cli.phar --allow-root plugin install http-authentication --path=$final_path #================================================= # LOAD SQL CONFIG #================================================= # Replace variables in sql scripts ynh_replace_string "__DOMAIN_PATH__" "$domain$path_url" ../conf/sql/*.sql ynh_replace_string "__LANGUAGE__" "$language" ../conf/sql/*.sql ynh_replace_string "__DATE__" "$(date +%s)" ../conf/sql/*.sql # Charge les commandes sql communes à tous les scripts. # mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/common.sql ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/sql/common.sql #================================================= # CONFIGURE MULTISITE #================================================= if [ $multisite -eq 1 ] then ynh_replace_string "#--MULTISITE--" "" /etc/nginx/conf.d/$domain.d/$app.conf # Autorise le multisite wordpress ynh_replace_string "//--MULTISITE1--define" "define " $final_path/wp-config.php # Active le multisite via wp-cli. ALL_QUIET php $final_path/wp-cli.phar core multisite-convert --allow-root --path=$final_path --base=$path_url/ # Active le multisite wordpress ynh_replace_string "//--MULTISITE2--define" "define" $final_path/wp-config.php # Charge les commandes sql pour activer les plugins if [ $is_public -eq 0 ] then ynh_replace_string "#--PRIVATE--" "" ../conf/sql/multisite.sql else ynh_replace_string "#--PUBLIC--" "" ../conf/sql/multisite.sql fi ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/sql/multisite.sql else if [ $is_public -eq 0 ] then ynh_replace_string "#--PRIVATE--" "" /etc/nginx/conf.d/$domain.d/$app.conf ynh_replace_string "#--PRIVATE--" "" ../conf/sql/single.sql else ynh_replace_string "//--PUBLIC--define" "define" $final_path/wp-config.php ynh_replace_string "#--PRIVATE--" "#" /etc/nginx/conf.d/$domain.d/$app.conf ynh_replace_string "#--PUBLIC--" "" ../conf/sql/single.sql fi # Charge les commandes sql pour activer les plugins ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/sql/single.sql fi # Décommente les add_filter, qui auraient provoqué une erreur avec wp-cli ynh_replace_string "//add_filter" "add_filter" $final_path/wp-config.php #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/wp-config.php" #================================================= # GENERIC FINALISATION #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Les fichiers appartiennent à l'user wordpress, pour permettre les mises à jour. sudo chown -R $app: $final_path # Sauf le fichier de config wp-config.php qui appartient à root sudo chown root: $final_path/wp-config.php #================================================= # SETUP SSOWAT #================================================= if [ $is_public -eq 0 ]; then # Retire l'accès public ynh_app_setting_delete $app unprotected_uris fi #================================================= # RELOAD NGINX #================================================= sudo systemctl reload nginx #================================================= # REMOVE WP-CLI.PHAR #================================================= ynh_secure_remove $final_path/wp-cli.phar