From 8abc01681fd34b8cfb3088f19399b6d7cecb69d6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Wed, 7 Mar 2018 23:33:32 +0100 Subject: [PATCH] Rewrite, bug 'Primary script unknown' to fix.. --- check_process | 4 +- conf/nginx.conf | 7 -- manifest.json | 17 ++++- scripts/_common.sh | 3 + scripts/install | 26 +++---- scripts/remove | 92 +++++++++++++++++++++--- scripts/upgrade | 172 ++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 285 insertions(+), 36 deletions(-) create mode 100644 scripts/_common.sh diff --git a/check_process b/check_process index 382d484..04a6e28 100644 --- a/check_process +++ b/check_process @@ -6,8 +6,8 @@ domain="domain.tld" (DOMAIN) path="/path" (PATH) admin="john" (USER) - is_public=1 (PUBLIC|public=Yes|private=No) - adminPass="miaw!" + is_public=1 (PUBLIC|public=1|private=0) + password="miaw!" ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/conf/nginx.conf b/conf/nginx.conf index 0989587..c8761ec 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -17,13 +17,6 @@ location __PATH__ { fastcgi_split_path_info ^(.+?\.php)(/.*)$; fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; - # If you don't use a dedicated fpm config for your app, - # use a general fpm pool. - # This is to be used INSTEAD of line above - # Don't forget to adjust scripts install/upgrade/remove/backup accordingly - # - #fastcgi_pass unix:/var/run/php5-fpm.sock; - fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; diff --git a/manifest.json b/manifest.json index d404a53..fada395 100644 --- a/manifest.json +++ b/manifest.json @@ -1,18 +1,29 @@ { "name": "Galette", "id": "galette", + "packaging_format": 1, + "url": "https://www.galette.eu", + "license": "GPL-3.0-or-later", + "version": "0.8.2.3-1", + "requirements": { + "yunohost": ">= 2.7.9" + }, + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], "description": { "en": "Membership management web application for non profit organizations", "fr": "Outil de gestion d'adhérents et de cotisation en ligne pour associations" }, - "licence": "free", "maintainer": { "name": "Jean-Baptiste Holcroft", "email": "jean-baptiste@holcroft.fr" }, - "multi_instance": "false", + "multi_instance": false, "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain", diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..7a693aa --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/scripts/install b/scripts/install index 956f624..d9ea170 100755 --- a/scripts/install +++ b/scripts/install @@ -23,7 +23,7 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC @@ -70,6 +70,9 @@ ynh_mysql_setup_db "$db_name" "$db_name" "$db_pwd" 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" +mv "$final_path"/galette/* "$final_path"/ +ynh_secure_remove "$final_path"/tests +chown -R root:root "$final_path" #================================================= # NGINX CONFIGURATION @@ -85,7 +88,6 @@ ynh_add_nginx_config # Create a system user ynh_system_user_create "$app" - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -99,8 +101,8 @@ ynh_add_fpm_config # MODIFY A CONFIG FILE #================================================= -configpath="$final_path"/config/ -cp ../config.inc.php "$configpath" +configpath="$final_path"/config/config.inc.php +cp ../conf/config.inc.php "$configpath" ynh_replace_string "__NAME_DB__" "$db_name" "$configpath" ynh_replace_string "__PWD_DB__" "$db_pwd" "$configpath" ynh_replace_string "__USER_DB__" "$db_name" "$configpath" @@ -110,7 +112,7 @@ ynh_replace_string "__USER_DB__" "$db_name" "$configpath" #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/CONFIG_FILE" +ynh_store_file_checksum "$configpath" #================================================= # GENERIC FINALIZATION @@ -118,16 +120,16 @@ ynh_store_file_checksum "$final_path/CONFIG_FILE" # SECURE FILES AND DIRECTORIES #================================================= -# Set permissions +# TODO: improve permissions -chown -R root:www-data $final_path -chmod -R o-rwx $final_path -chmod u+rx $final_path/config -chmod g+rwx $final_path/config +chown -R root:www-data "$final_path" +chmod -R o-rwx "$final_path" +chmod u+rx "$final_path/config" +chmod g+rwx "$final_path/config" for folder in attachments cache exports files imports logs photos templates_c tempimages do - chmod u+rx $final_path/data/$folder - chmod g+rwx $final_path/data/$folder + chmod u+rx "$final_path/data/$folder" + chmod g+rwx "$final_path/data/$folder" done #================================================= diff --git a/scripts/remove b/scripts/remove index 3386a89..ec378f5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,16 +1,86 @@ #!/bin/bash -app=galette -db_user=galette -db_name=galette -root_pwd=$(cat /etc/yunohost/mysql) -domain=$(yunohost app setting galette domain) +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" -rm -rf /var/www/$app -rm -f /etc/nginx/conf.d/$domain.d/$app.conf +source _common.sh +source /usr/share/yunohost/helpers -# Restart services -service nginx reload -yunohost app ssowatconf + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get "$app" domain) +port=$(ynh_app_setting_get "$app" port) +db_name=$(ynh_app_setting_get "$app" db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +# ynh_remove_app_dependencies + +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db "$db_user" "$db_name" + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +# ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= + +# Remove the log files +ynh_secure_remove "/var/log/$app/" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete "$app" diff --git a/scripts/upgrade b/scripts/upgrade index 9078c6f..a8d0f3f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,5 +7,175 @@ # http://galette.eu/documentation/fr/installation/update.html # -# adminPass --> password +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get "$app" domain) +path_url=$(ynh_app_setting_get "$app" path) +admin=$(ynh_app_setting_get "$app" admin) +is_public=$(ynh_app_setting_get "$app" is_public) +final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_app_setting_get "$app" db_name) +db_pwd=$(ynh_app_setting_get "$app" mysqlpwd) +password=$(ynh_app_setting_get "$app" password) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set "$app" is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set "$app" is_public 0 + is_public=0 +fi + # mysqlpassword --> mysqlpwd + +# If db_name doesn't exist, create it +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid "$app") + ynh_app_setting_set "$app" db_name "$db_name" +fi + +# If db_name doesn't exist, create it +if [ -z "$db_pwd" ]; then + db_pwd=$(ynh_app_setting_get "$app" mysqlpassword) + ynh_app_setting_set "$app" mysqlpwd "$db_pwd" +fi + +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/var/www/$app + ynh_app_setting_set "$app" final_path "$final_path" +fi + + + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# 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 UPGRADE +#================================================= +# ... +#================================================= + +configpath="$final_path"/config/ +cp ../config.inc.php "$configpath" +ynh_replace_string "__NAME_DB__" "$db_name" "$configpath" +ynh_replace_string "__PWD_DB__" "$db_pwd" "$configpath" +ynh_replace_string "__USER_DB__" "$db_name" "$configpath" + +# Verify the checksum and backup the file if it's different +ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE" +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/CONFIG_FILE" + +#================================================= +# SETUP LOGROTATE +#================================================= + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +#================================================= +# SETUP SYSTEMD +#================================================= + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# TODO: improve permissions + +chown -R root:www-data "$final_path" +chmod -R o-rwx "$final_path" +chmod u+rx "$final_path/config" +chmod g+rwx "$final_path/config" +for folder in attachments cache exports files imports logs photos templates_c tempimages +do + chmod u+rx "$final_path/data/$folder" + chmod g+rwx "$final_path/data/$folder" +done + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx