diff --git a/manifest.json b/manifest.json index 7be127b..c31bad3 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "WordPress MultiSite", "id": "wordpressms", "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Create a beautiful blog or website easily", "fr": "Logiciel de création de blog ou de site Web" @@ -65,7 +68,7 @@ "default": "No" }, { - "name": "public_site", + "name": "is_public", "ask": { "en": "Is it a public WordPress site ?", "fr": "Est-ce un site public ?" diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..d0d714e --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,77 @@ +{ + "name": "WordPress MultiSite", + "id": "wordpressms", + "packaging_format": 1, + "description": { + "en": "Create a beautiful blog or website easily", + "fr": "Logiciel de création de blog ou de site Web" + }, + "version": "4.4", + "url": "https://wordpress.org/", + "licence": "free", + "maintainer": { + "name": "Maniack Crudelis", + "email": "maniackc_dev@crudelis.fr" + }, + "multi_instance": "true", + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for WordPress", + "fr": "Choisissez un domaine pour WordPress" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for WordPress", + "fr": "Choisissez un chemin pour WordPress" + }, + "example": "/blog", + "default": "/blog" + }, + { + "name": "admin", + "ask": { + "en": "Choose the WordPress administrator (must be an existing YunoHost user)", + "fr": "Administrateur du site (doit être un utilisateur YunoHost existant)" + }, + "example": "homer" + }, + { + "name": "language", + "ask": { + "en": "Choose the language of the WordPress site", + "fr": "Choissisez la langue du WordPress" + }, + "choices": ["en_EN", "fr_FR"], + "default": "en_EN" + }, + { + "name": "multisite", + "ask": { + "en": "Enable multisite option ?", + "fr": "Activer l'option multisite ?" + }, + "choices": ["Yes", "No"], + "default": "No" + }, + { + "name": "is_public", + "ask": { + "en": "Is it a public WordPress site ?", + "fr": "Est-ce un site public ?" + }, + "choices": ["Yes", "No"] + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index 78a0afc..43f5c40 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=wordpressms +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=wordpressms +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/install b/scripts/install index d99097d..0e4dc99 100644 --- a/scripts/install +++ b/scripts/install @@ -1,19 +1,59 @@ #!/bin/bash -# Renseigne les variables à partir des arguments. -domain=$1 -path=$2 -admin_wordpress=$3 -language=$4 -multisite=$5 -is_public=$6 -app=wordpressms +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +# Retrieve arguments +if [ $ynh_version = "2.4" ] +then + domain=$YNH_APP_ARG_DOMAIN + path=$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 + + # Source app helpers + . /usr/share/yunohost/helpers +else + domain=$1 + path=$2 + admin_wordpress=$3 + language=$4 + multisite=$5 + is_public=$6 + app=wordpressms +fi + + +# Delete files and db if exit with an error +EXIT_PROPERLY () { + trap '' ERR + 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!!" + + 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 + # Vérifie la validité de l'user admin sudo yunohost user list --json | grep -q "\"username\": \"$admin_wordpress\"" if [[ ! $? -eq 0 ]]; then echo "Wrong admin" - exit 1 + touch /force_stop fi # Vérifie la présence du / en début de path @@ -24,7 +64,7 @@ fi # Vérifie la disponibilité du path et du domaine. sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then - exit 1 + touch /force_stop fi # Vérifie que le dossier de destination n'est pas déjà utilisé. @@ -32,7 +72,7 @@ final_path=/var/www/$app if [ -e "$final_path" ] then echo "This path already contains a folder" - exit 1 + touch /force_stop fi @@ -46,11 +86,15 @@ sudo yunohost app setting $app multisite -v $multisite # Génère un mot de passe aléatoire. -db_pwd=$(cat /dev/urandom | head -n20 | tr -c -d 'A-Za-z0-9' | head -c20) +db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20) # 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. -sudo yunohost app initdb $db_user -p $db_pwd +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 sudo yunohost app setting $app mysqlpwd -v $db_pwd diff --git a/scripts/remove b/scripts/remove index 686613d..9989f5d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,27 +1,56 @@ #!/bin/bash -app=wordpressms - # Récupère les infos de l'application. -root_pwd=$(sudo cat /etc/yunohost/mysql) +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + app=wordpressms + MYSQL_ROOT_PWD_FILE="/etc/yunohost/mysql" +fi domain=$(sudo yunohost app setting $app domain) +# Suppression de la base de donnée et de l'utilisateur associé. # Utilise '$app' comme nom d'utilisateur et de base de donnée db_user=$app -mysql -u root -p$root_pwd -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" +if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then + echo "Delete db" + if [ $ynh_version = "2.4" ]; then + ynh_mysql_drop_db $db_user + ynh_mysql_drop_user $db_user + else + mysql -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;" + fi +fi # Suppression du dossier de l'application -sudo rm -rf /var/www/$app +if [ -e "/var/www/$app" ]; then # Delete final_path + echo "Delete app dir" + sudo rm -r "/var/www/$app" +fi # Suppression de la configuration nginx -sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config + echo "Delete nginx config" + sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo service nginx reload +fi # Suppression de la configuration du pool php-fpm -sudo rm -f /etc/php5/fpm/pool.d/$app.conf -sudo rm -f /etc/php5/fpm/conf.d/20-$app.ini - -# Recharge la configuration Nginx et php5-fpm -sudo service nginx reload +if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config + echo "Delete fpm config" + sudo rm "/etc/php5/fpm/pool.d/$app.conf" +fi +if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config + echo "Delete php config" + sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" +fi sudo service php5-fpm reload + # Régénère la configuration de SSOwat sudo yunohost app ssowatconf + +echo -e "\e[0m" # Restore normal color diff --git a/scripts/restore b/scripts/restore index 4cd2174..1d97650 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=wordpressms +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=wordpressms +fi final_path=$(sudo yunohost app setting $app final_path) domain=$(sudo yunohost app setting $app domain) diff --git a/scripts/upgrade b/scripts/upgrade index 0370aac..4c6ae29 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,11 +1,14 @@ #!/bin/bash # Récupère les infos de l'application. -app=app_name +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=wordpressms +fi domain=$(sudo yunohost app setting $app domain) path=$(sudo yunohost app setting $app path) -admin_wordpress=$(sudo yunohost app setting $app admin) -language=$(sudo yunohost app setting $app language) is_public=$(sudo yunohost app setting $app is_public) multisite=$(sudo yunohost app setting $app multisite) final_path=$(sudo yunohost app setting $app final_path)