From 40b62d4b23a1b348ba6043715cb929d758b4a883 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 Jul 2017 15:31:42 +0200 Subject: [PATCH] remove carriage return --- check_process | 78 +++++++------- conf/nginx.conf | 74 ++++++------- conf/php-fpm.conf | 142 ++++++++++++------------ manifest.json | 112 +++++++++---------- scripts/_common.sh | 224 +++++++++++++++++++------------------- scripts/backup | 162 ++++++++++++++-------------- scripts/install | 163 ++++++++++++++-------------- scripts/remove | 56 +++++----- scripts/restore | 254 +++++++++++++++++++++---------------------- scripts/upgrade | 264 ++++++++++++++++++++++----------------------- 10 files changed, 764 insertions(+), 765 deletions(-) diff --git a/check_process b/check_process index 734c24f..674bd30 100644 --- a/check_process +++ b/check_process @@ -1,40 +1,40 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file -;; Test complet - ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) - language="fr" - is_public=1 (PUBLIC|public=1|private=0) - password="pass" - port="666" (PORT) - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - incorrect_path=1 - port_already_use=1 - change_url=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: - Level 4=0 -# Level 5: - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 -;;; Options -Email= +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + admin="john" (USER) + language="fr" + is_public=1 (PUBLIC|public=1|private=0) + password="pass" + port="666" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=1 + port_already_use=1 + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto +# Level 4: + Level 4=0 +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email= Notification=none \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index a8e531e..172abcf 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,37 +1,37 @@ -location {LOCATION} { - alias {DESTDIR}/www/output; - - # Default indexes and catch-all - index index.html index.php; - try_files $uri $uri/ {PATH}/index.php?$args; - - # Prevent useless logs - location = {PATH}/favicon.ico { - log_not_found off; - access_log off; - } - location = {PATH}/robots.txt { - allow all; - log_not_found off; - access_log off; - } - - # Deny access to hidden files and directories - location ~ ^{PATH}/(.+/|)\.(?!well-known\/) { - deny all; - } - - # Execute and serve PHP files - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-{POOLNAME}.sock; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} +location {LOCATION} { + alias {DESTDIR}/www/output; + + # Default indexes and catch-all + index index.html index.php; + try_files $uri $uri/ {PATH}/index.php?$args; + + # Prevent useless logs + location = {PATH}/favicon.ico { + log_not_found off; + access_log off; + } + location = {PATH}/robots.txt { + allow all; + log_not_found off; + access_log off; + } + + # Deny access to hidden files and directories + location ~ ^{PATH}/(.+/|)\.(?!well-known\/) { + deny all; + } + + # Execute and serve PHP files + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm-{POOLNAME}.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 23eeb7e..f3feeee 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -1,71 +1,71 @@ -[{POOLNAME}] -; The address on which to accept FastCGI requests. -listen = /var/run/php5-fpm-{POOLNAME}.sock - -; Set permissions for unix socket, if one is used. -listen.owner = www-data -listen.group = www-data -listen.mode = 0600 - -; Unix user/group of processes. -user = {USER} -group = www-data - -; Choose how the process manager will control the number of child processes. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes to be created when pm is set to 'dynamic'. -pm.max_children = 6 - -; The number of child processes created on startup. -pm.start_servers = 3 - -; The desired minimum number of idle server processes. -pm.min_spare_servers = 3 - -; The desired maximum number of idle server processes. -pm.max_spare_servers = 5 - -; The number of requests each child process should execute before respawning. -pm.max_requests = 500 - -; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. -pm.status_path = /fpm-status - -; The ping URI to call the monitoring page of FPM. If this value is not set, no -; URI will be recognized as a ping page. -ping.path = /ping - -; The timeout for serving a single request after which the worker process will -; be killed. -request_terminate_timeout = 1d - -; The timeout for serving a single request after which a PHP backtrace will be -; dumped to the 'slowlog' file. A value of '0s' means 'off'. -request_slowlog_timeout = 5s - -; The log file for slow requests. -slowlog = /var/log/nginx/{POOLNAME}.slow.log - -; Set open file descriptor rlimit. -rlimit_files = 4096 - -; Set max core size rlimit. -rlimit_core = 0 - -; Chdir to this directory at the start. -chdir = {DESTDIR} - -; Redirect worker stdout and stderr into main error log. -catch_workers_output = yes - -; Do not clear environment in FPM workers. -clear_env = no - -; Additional php.ini defines, specific to this pool of workers. -php_value[upload_max_filesize] = 1G -php_value[post_max_size] = 1G -php_value[default_charset] = UTF-8 -php_value[always_populate_raw_post_data] = -1 +[{POOLNAME}] +; The address on which to accept FastCGI requests. +listen = /var/run/php5-fpm-{POOLNAME}.sock + +; Set permissions for unix socket, if one is used. +listen.owner = www-data +listen.group = www-data +listen.mode = 0600 + +; Unix user/group of processes. +user = {USER} +group = www-data + +; Choose how the process manager will control the number of child processes. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes to be created when pm is set to 'dynamic'. +pm.max_children = 6 + +; The number of child processes created on startup. +pm.start_servers = 3 + +; The desired minimum number of idle server processes. +pm.min_spare_servers = 3 + +; The desired maximum number of idle server processes. +pm.max_spare_servers = 5 + +; The number of requests each child process should execute before respawning. +pm.max_requests = 500 + +; The URI to view the FPM status page. If this value is not set, no URI will be +; recognized as a status page. +pm.status_path = /fpm-status + +; The ping URI to call the monitoring page of FPM. If this value is not set, no +; URI will be recognized as a ping page. +ping.path = /ping + +; The timeout for serving a single request after which the worker process will +; be killed. +request_terminate_timeout = 1d + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +request_slowlog_timeout = 5s + +; The log file for slow requests. +slowlog = /var/log/nginx/{POOLNAME}.slow.log + +; Set open file descriptor rlimit. +rlimit_files = 4096 + +; Set max core size rlimit. +rlimit_core = 0 + +; Chdir to this directory at the start. +chdir = {DESTDIR} + +; Redirect worker stdout and stderr into main error log. +catch_workers_output = yes + +; Do not clear environment in FPM workers. +clear_env = no + +; Additional php.ini defines, specific to this pool of workers. +php_value[upload_max_filesize] = 1G +php_value[post_max_size] = 1G +php_value[default_charset] = UTF-8 +php_value[always_populate_raw_post_data] = -1 diff --git a/manifest.json b/manifest.json index 823002f..46c6d06 100644 --- a/manifest.json +++ b/manifest.json @@ -1,56 +1,56 @@ -{ - "name": "Pelican", - "id": "pelican", - "packaging_format": 1, - "description": { - "en": "Pelican package for YunoHost application.", - "fr": "Package de l'application Pelican pour YunoHost." - }, - "url": "https://example.com", - "license": "free", - "maintainer": { - "name": "Ylies Chahi", - "email": "ylieschahi@gmail.com", - "url": "http://example.com" - }, - "requirements": { - "yunohost": ">> 2.5.6" - }, - "multi_instance": false, - "services": [ - "nginx", - "php5-fpm" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain name for Pelican", - "fr": "Choisissez un nom de domaine pour Pelican" - }, - "example": "example.com" - }, - { - "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for Pelican", - "fr": "Choisissez un chemin pour Pelican" - }, - "example": "/site", - "default": "/site" - }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, - "default": true - } - ] - } -} +{ + "name": "Pelican", + "id": "pelican", + "packaging_format": 1, + "description": { + "en": "Pelican package for YunoHost application.", + "fr": "Package de l'application Pelican pour YunoHost." + }, + "url": "https://example.com", + "license": "free", + "maintainer": { + "name": "Ylies Chahi", + "email": "ylieschahi@gmail.com", + "url": "http://example.com" + }, + "requirements": { + "yunohost": ">> 2.5.6" + }, + "multi_instance": false, + "services": [ + "nginx", + "php5-fpm" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for Pelican", + "fr": "Choisissez un nom de domaine pour Pelican" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for Pelican", + "fr": "Choisissez un chemin pour Pelican" + }, + "example": "/site", + "default": "/site" + }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public application?", + "fr": "Est-ce une application publique ?" + }, + "default": true + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh index 7515bdf..8ae77b5 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,112 +1,112 @@ -#!/bin/bash - -# ============================================================================= -# YUNOHOST 2.7 FORTHCOMING HELPERS -# ============================================================================= - -# Create a dedicated nginx config -# -# usage: ynh_add_nginx_config -ynh_add_nginx_config () { - finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalnginxconf" 1 - sudo cp ../conf/nginx.conf "$finalnginxconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${path_url:-}"; then - ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" - fi - if test -n "${domain:-}"; then - ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" - fi - if test -n "${port:-}"; then - ynh_replace_string "__PORT__" "$port" "$finalnginxconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__NAME__" "$app" "$finalnginxconf" - fi - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" - fi - ynh_store_checksum_config "$finalnginxconf" - - sudo systemctl reload nginx -} - -# Remove the dedicated nginx config -# -# usage: ynh_remove_nginx_config -ynh_remove_nginx_config () { - ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx -} - -# Create a dedicated php-fpm config -# -# usage: ynh_add_fpm_config -ynh_add_fpm_config () { - finalphpconf="/etc/php5/fpm/pool.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalphpconf" 1 - sudo cp ../conf/php-fpm.conf "$finalphpconf" - ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" - ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" - ynh_replace_string "__USER__" "$app" "$finalphpconf" - sudo chown root: "$finalphpconf" - ynh_store_file_checksum "$finalphpconf" - - if [ -e "../conf/php-fpm.ini" ] - then - finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" - ynh_compare_checksum_config "$finalphpini" 1 - sudo cp ../conf/php-fpm.ini "$finalphpini" - sudo chown root: "$finalphpini" - ynh_store_checksum_config "$finalphpini" - fi - - sudo systemctl reload php5-fpm -} - -# Remove the dedicated php-fpm config -# -# usage: ynh_remove_fpm_config -ynh_remove_fpm_config () { - ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" - ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 - sudo systemctl reload php5-fpm -} - -# Create a dedicated systemd config -# -# usage: ynh_add_systemd_config -ynh_add_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - ynh_compare_checksum_config "$finalsystemdconf" 1 - sudo cp ../conf/systemd.service "$finalsystemdconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__APP__" "$app" "$finalsystemdconf" - fi - ynh_store_checksum_config "$finalsystemdconf" - - sudo chown root: "$finalsystemdconf" - sudo systemctl enable $app - sudo systemctl daemon-reload -} - -# Remove the dedicated systemd config -# -# usage: ynh_remove_systemd_config -ynh_remove_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - if [ -e "$finalsystemdconf" ]; then - sudo systemctl stop $app - sudo systemctl disable $app - ynh_secure_remove "$finalsystemdconf" - fi -} +#!/bin/bash + +# ============================================================================= +# YUNOHOST 2.7 FORTHCOMING HELPERS +# ============================================================================= + +# Create a dedicated nginx config +# +# usage: ynh_add_nginx_config +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalnginxconf" 1 + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path_url:-}"; then + ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_replace_string "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + ynh_store_checksum_config "$finalnginxconf" + + sudo systemctl reload nginx +} + +# Remove the dedicated nginx config +# +# usage: ynh_remove_nginx_config +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx +} + +# Create a dedicated php-fpm config +# +# usage: ynh_add_fpm_config +ynh_add_fpm_config () { + finalphpconf="/etc/php5/fpm/pool.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalphpconf" 1 + sudo cp ../conf/php-fpm.conf "$finalphpconf" + ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" + ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" + ynh_replace_string "__USER__" "$app" "$finalphpconf" + sudo chown root: "$finalphpconf" + ynh_store_file_checksum "$finalphpconf" + + if [ -e "../conf/php-fpm.ini" ] + then + finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" + ynh_compare_checksum_config "$finalphpini" 1 + sudo cp ../conf/php-fpm.ini "$finalphpini" + sudo chown root: "$finalphpini" + ynh_store_checksum_config "$finalphpini" + fi + + sudo systemctl reload php5-fpm +} + +# Remove the dedicated php-fpm config +# +# usage: ynh_remove_fpm_config +ynh_remove_fpm_config () { + ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" + ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 + sudo systemctl reload php5-fpm +} + +# Create a dedicated systemd config +# +# usage: ynh_add_systemd_config +ynh_add_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + ynh_compare_checksum_config "$finalsystemdconf" 1 + sudo cp ../conf/systemd.service "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finalsystemdconf" + fi + ynh_store_checksum_config "$finalsystemdconf" + + sudo chown root: "$finalsystemdconf" + sudo systemctl enable $app + sudo systemctl daemon-reload +} + +# Remove the dedicated systemd config +# +# usage: ynh_remove_systemd_config +ynh_remove_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + if [ -e "$finalsystemdconf" ]; then + sudo systemctl stop $app + sudo systemctl disable $app + ynh_secure_remove "$finalsystemdconf" + fi +} diff --git a/scripts/backup b/scripts/backup index c324ddc..34afd23 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,81 +1,81 @@ -#!/bin/bash - -#================================================= -# GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh -fi -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# LOAD SETTINGS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) - -#================================================= -# STANDARD BACKUP STEPS -#================================================= -# BACKUP THE APP MAIN DIR -#================================================= - -ynh_backup "$final_path" "${backup_dir}$final_path" - -#================================================= -# BACKUP THE NGINX CONFIGURATION -#================================================= - -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= - -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${backup_dir}/etc/php5/fpm/pool.d/$app.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${backup_dir}/etc/php5/fpm/conf.d/20-$app.ini" - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= - -ynh_mysql_dump_db "$db_name" > db.sql -ynh_backup "db.sql" "${backup_dir}/db.sql" - -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app" - -#================================================= -# BACKUP SYSTEMD -#================================================= - -ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service" - -#================================================= -# BACKUP THE CRON FILE -#================================================= - -ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app" +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error +set -eu + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) +db_pwd=$(ynh_app_setting_get $app mysqlpwd) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" "${backup_dir}$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${backup_dir}/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${backup_dir}/etc/php5/fpm/conf.d/20-$app.ini" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + +ynh_mysql_dump_db "$db_name" > db.sql +ynh_backup "db.sql" "${backup_dir}/db.sql" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app" + +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service" + +#================================================= +# BACKUP THE CRON FILE +#================================================= + +ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app" diff --git a/scripts/install b/scripts/install index 782b90c..25b0d98 100644 --- a/scripts/install +++ b/scripts/install @@ -1,82 +1,81 @@ - -#!/bin/bash - -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat unset variables as an error -set -eu - -#================================================= -# GET MULTI-INSTANCES SPECIFIC VARIABLES -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH -is_public=$YNH_APP_ARG_IS_PUBLIC - - -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || exit 1 - -# Check destination directory -DESTDIR="/var/www/${app}" -[[ -d "$DESTDIR" ]] && ynh_die \ -"The destination directory '${DESTDIR}' already exists.\ - You should safely delete it before installing this app." - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= - -ynh_app_setting_set $app is_public $is_public - -# Set SSOwat rules -[[ $is_public -eq 1 ]] \ - && ynh_app_setting_set "$app" skipped_uris "/" - - -ynh_install_app_dependencies python-pip - -#================================================= -# INSTALL PELICAN -#================================================= - -pip install pelican markdown - -# Copy and set nginx configuration -nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" -sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf -sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf -sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf -sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf "$nginx_conf" - -# Copy and set php-fpm configuration -phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" -sed -i "s@{USER}@${user}@g" ../conf/php-fpm.conf -sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf -sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/php-fpm.conf -sudo cp ../conf/php-fpm.conf "$phpfpm_conf" - -# Reload services -sudo systemctl reload php5-fpm -sudo systemctl reload nginx -sudo systemctl reload ssh +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat unset variables as an error +set -eu + +#================================================= +# GET MULTI-INSTANCES SPECIFIC VARIABLES +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC + + +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || exit 1 + +# Check destination directory +DESTDIR="/var/www/${app}" +[[ -d "$DESTDIR" ]] && ynh_die \ +"The destination directory '${DESTDIR}' already exists.\ + You should safely delete it before installing this app." + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app is_public $is_public + +# Set SSOwat rules +[[ $is_public -eq 1 ]] \ + && ynh_app_setting_set "$app" skipped_uris "/" + + +ynh_install_app_dependencies python-pip + +#================================================= +# INSTALL PELICAN +#================================================= + +pip install pelican markdown + +# Copy and set nginx configuration +nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" +sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf +sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf +sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf +sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf "$nginx_conf" + +# Copy and set php-fpm configuration +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sed -i "s@{USER}@${user}@g" ../conf/php-fpm.conf +sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf +sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/php-fpm.conf +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" + +# Reload services +sudo systemctl reload php5-fpm +sudo systemctl reload nginx +sudo systemctl reload ssh diff --git a/scripts/remove b/scripts/remove index e0ac6f2..005c4a4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,28 +1,28 @@ -#!/bin/bash - -#================================================= -# 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) - -# Delete app directory and configurations -sudo rm -rf "/var/www/${app}" -sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf" -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" - -# Reload services -sudo systemctl restart php5-fpm || true -sudo systemctl reload nginx || true -sudo systemctl reload ssh +#!/bin/bash + +#================================================= +# 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) + +# Delete app directory and configurations +sudo rm -rf "/var/www/${app}" +sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf" +[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" + +# Reload services +sudo systemctl restart php5-fpm || true +sudo systemctl reload nginx || true +sudo systemctl reload ssh diff --git a/scripts/restore b/scripts/restore index 8fac05c..5ec47c9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,128 +1,128 @@ -#!/bin/bash - -#================================================= -# GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh -fi -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) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= - -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= - -ynh_restore_file "$final_path" - -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= - -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= - -# Create the dedicated user (if not existing) -ynh_system_user_create $app - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -sudo chown -R root: $final_path - -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= - -ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" -ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= - -# Define and install dependencies -ynh_install_app_dependencies deb1 deb2 - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -sudo yunohost service add $app --log "/var/log/$app/APP.log" - -#================================================= -# RESTORE SYSTEMD -#================================================= - -ynh_restore_file "/etc/systemd/system/$app.service" -sudo systemctl enable $app.service - -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file "/etc/cron.d/$app" - -#================================================= -# BACKUP THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file "/etc/logrotate.d/$app" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX AND PHP-FPM -#================================================= - -sudo systemctl reload php5-fpm +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error +set -eu + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +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) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_mysql_setup_db $db_name $db_name $db_pwd +ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= + +# Create the dedicated user (if not existing) +ynh_system_user_create $app + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +sudo chown -R root: $final_path + +#================================================= +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= + +ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" +ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +ynh_install_app_dependencies deb1 deb2 + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +sudo yunohost service add $app --log "/var/log/$app/APP.log" + +#================================================= +# RESTORE SYSTEMD +#================================================= + +ynh_restore_file "/etc/systemd/system/$app.service" +sudo systemctl enable $app.service + +#================================================= +# RESTORE THE CRON FILE +#================================================= + +ynh_restore_file "/etc/cron.d/$app" + +#================================================= +# BACKUP THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file "/etc/logrotate.d/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +sudo systemctl reload php5-fpm sudo systemctl reload nginx \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 249f74a..82ea0f5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,133 +1,133 @@ -#!/bin/bash - -#================================================= -# 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) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) - -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= - -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 - is_public=0 -fi - -if [ -z $db_name ]; then # If db_name doesn't exist, create it - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name -fi - -#================================================= -# 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_nginx_config - -#================================================= -# CREATE DEDICATED USER -#================================================= - -# Create a system user -ynh_system_user_create $app - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= - -# Create a dedicated php-fpm config -ynh_fpm_config - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# ... -#================================================= - -# 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 - -#================================================= -# SETUP SYSTEMD -#================================================= - -# Create a dedicated systemd config -ynh_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set right permissions for curl installation -sudo chown -R root: $final_path - -#================================================= -# 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 -#================================================= - +#!/bin/bash + +#================================================= +# 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) +port=$(ynh_app_setting_get $app port) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + +if [ -z $db_name ]; then # If db_name doesn't exist, create it + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name +fi + +#================================================= +# 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_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= + +# Create a dedicated php-fpm config +ynh_fpm_config + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# ... +#================================================= + +# 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 + +#================================================= +# SETUP SYSTEMD +#================================================= + +# Create a dedicated systemd config +ynh_systemd_config + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set right permissions for curl installation +sudo chown -R root: $final_path + +#================================================= +# 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 +#================================================= + sudo systemctl reload nginx \ No newline at end of file