[enh] Some corrections

This commit is contained in:
Maniack Crudelis 2017-08-28 23:55:51 +02:00
parent b4c6969284
commit a625ad79da
10 changed files with 42 additions and 134 deletions

View file

@ -20,7 +20,7 @@
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=1
port_already_use=0
change_url=0
;;; Levels
Level 1=auto

View file

@ -1,6 +1,6 @@
SOURCE_URL=url of app's source
SOURCE_SUM=sha256 checksum
SOURCE_SUM_PRG=sha256
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,9 +1,9 @@
# Common values to change to increase file upload limit
; Common values to change to increase file upload limit
; upload_max_filesize = 50M
; post_max_size = 50M
; mail.add_x_header = Off
# Other common parameters
; Other common parameters
; max_execution_time = 600
; max_input_time = 300
; memory_limit = 256M

View file

@ -6,6 +6,7 @@
"en": "Example package for YunoHost application.",
"fr": "Exemple de package dapplication pour YunoHost."
},
"version": "1.0",
"url": "https://example.com",
"license": "free",
"maintainer": {
@ -14,7 +15,7 @@
"url": "http://example.com"
},
"requirements": {
"yunohost": ">= 2.6.4"
"yunohost": ">= 2.7.2"
},
"multi_instance": true,
"services": [

View file

@ -1,112 +1,2 @@
#!/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"
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_file_checksum "$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"
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_backup_if_checksum_is_different "$finalphpini"
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_file_checksum "$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_backup_if_checksum_is_different "$finalsystemdconf"
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_file_checksum "$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
}

View file

@ -30,7 +30,6 @@ 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
@ -38,27 +37,26 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path" "${backup_dir}$final_path"
ynh_backup "$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"
ynh_backup "/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"
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/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
@ -66,16 +64,16 @@ ynh_backup "db.sql" "${backup_dir}/db.sql"
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app"
ynh_backup "/etc/cron.d/$app"

View file

@ -42,6 +42,9 @@ app=$YNH_APP_INSTANCE_NAME
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
@ -50,9 +53,6 @@ ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
@ -118,7 +118,7 @@ ynh_system_user_create $app
#=================================================
# Create a dedicated php-fpm config
ynh_fpm_config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP

View file

@ -18,6 +18,7 @@ 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)
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# STANDARD REMOVE
@ -57,7 +58,7 @@ ynh_mysql_remove_db $db_name $db_name
#=================================================
# Remove the app directory securely
ynh_secure_remove "/var/www/$app"
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
@ -87,7 +88,7 @@ ynh_remove_logrotate
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port"
QUIET yunohost firewall disallow TCP $port
yunohost firewall disallow TCP $port 2>&1
fi
#=================================================

View file

@ -36,7 +36,7 @@ db_name=$(ynh_app_setting_get $app db_name)
# CHECK IF THE APP CAN BE RESTORED
#=================================================
yunohost app checkurl "${domain}${path_url}" -a "$app" \
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "

View file

@ -27,19 +27,37 @@ db_name=$(ynh_app_setting_get $app db_name)
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value
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
if [ -z $db_name ]; then # If db_name doesn't exist, create it
# 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 final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_restore_upgradebackup # restore it if the upgrade fails
}
ynh_abort_if_errors # Exit if an error occurs during the execution of the script
#=================================================
# CHECK THE PATH
#=================================================
@ -75,7 +93,7 @@ ynh_system_user_create $app
#=================================================
# Create a dedicated php-fpm config
ynh_fpm_config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE