1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/paheko_ynh.git synced 2024-09-03 19:56:22 +02:00

add hooks to copy file config.dist.php in config.local.php with good options

This commit is contained in:
Rodolphe Robles 2020-04-04 03:34:57 +02:00
parent 9fa22de996
commit 5245009c35
8 changed files with 158 additions and 58 deletions

20
hooks/post_app_change_url Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in config.local.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

22
hooks/post_app_install Normal file
View file

@ -0,0 +1,22 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in file config.dist.php
# and copy in local.dist.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = 'uqn8jvlmVZLn988lOZiHd1z97hD36V40AnE0LLqLY1801LG3caO';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

20
hooks/post_app_upgrade Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# Change options in config.local.php
#=================================================
ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = false;" --target_file="$final_path/config.dist.php"
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '/garradin/';" --target_file="$final_path/config.dist.php"
sudo cp -a $final_path/config.dist.php $final_path/local.dist.php

View file

@ -1,5 +1,12 @@
#!/bin/bash #!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="php7.0-sqlite3"
# ============= FUTURE YUNOHOST HELPER ============= # ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings # Delete a file checksum from the app settings
# #

View file

@ -24,40 +24,45 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Backing up the main app directory..." --time --weight=1
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
--time --weight=1ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE PHP-FPM CONFIGURATION # BACKUP THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.0/fpm/conf.d/20-$app.ini" ynh_backup --src_path="/etc/php/7.0/fpm/conf.d/20-$app.ini"
# Backup directory location for the app from where the script is executed and # # Backup directory location for the app from where the script is executed and
# which will be compressed afterward # # which will be compressed afterward
backup_dir=$YNH_APP_BACKUP_DIR # backup_dir=$YNH_APP_BACKUP_DIR
# Backup sources & data # # Backup sources & data
ynh_backup "/var/www/$app" "sources" # ynh_backup "/var/www/$app" "sources"
# Copy Nginx conf # # Copy Nginx conf
sudo mkdir -p ./conf # sudo mkdir -p ./conf
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" # ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"

View file

@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -39,41 +40,44 @@ path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability # Check web path availability
ynh_webpath_available $domain $path_url ynh_webpath_available $domain $path_url
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
ynh_app_setting_set $app path_url $path_url ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set $app domain $domain ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#================================================= #=================================================
# Install dependency to convert tracks to a readable format for the browser # Install dependency to convert tracks to a readable format for the browser
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
if [ "$(lsb_release --codename --short)" != "jessie" ] if [ "$(lsb_release --codename --short)" != "jessie" ]
then then
ynh_install_app_dependencies php7.0-sqlite3 ynh_install_app_dependencies $pkg_dependencies
else else
ynh_install_app_dependencies php5-sqlite ynh_die --message="Votre version de Debian n'est pas compatible..." --time --weight=1
fi fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Configuring system user..." --time --weight=1
# Create a system user # Create a system user
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=1
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source --dest_dir="$final_path"
#================================================= #=================================================
# Files owned by user app # Files owned by user app
@ -85,13 +89,14 @@ sudo chmod 755 $final_path -R
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring php-fpm..." --time --weight=1
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_add_fpm_config ynh_add_fpm_config
@ -99,6 +104,9 @@ ynh_add_fpm_config
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then # Remove the public access then # Remove the public access
@ -108,11 +116,18 @@ fi
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
systemctl reload nginx systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last

View file

@ -12,15 +12,17 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Removing dependencies..." --time --weight=1
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
@ -28,13 +30,15 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
@ -42,6 +46,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE PHP-FPM CONFIGURATION # REMOVE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1
# Remove the dedicated php-fpm config # Remove the dedicated php-fpm config
ynh_remove_fpm_config ynh_remove_fpm_config
@ -51,6 +56,13 @@ ynh_remove_fpm_config
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --time --last

View file

@ -6,12 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
# Get the _common.sh file if it's not in the current directory source ../settings/scripts/_common.sh
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,16 +20,18 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
ynh_webpath_available $domain $path_url \ ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
@ -57,9 +55,10 @@ ynh_restore_file "$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -73,11 +72,10 @@ chown -R $app:$app $final_path
#================================================= #=================================================
if [ "$(lsb_release --codename --short)" != "jessie" ] if [ "$(lsb_release --codename --short)" != "jessie" ]
then then
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php/7.0/fpm/conf.d/20-$app.ini" ynh_restore_file --origin_path="/etc/php/7.0/fpm/conf.d/20-$app.ini"
else else
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" ynh_die --message="Votre version de Debian n'est pas compatible..."
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
fi fi
#================================================= #=================================================
@ -85,23 +83,24 @@ fi
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
if [ "$(lsb_release --codename --short)" != "jessie" ] # Define and install dependencies
then
ynh_install_app_dependencies php7.0-sqlite3 ynh_install_app_dependencies php7.0-sqlite3
else
ynh_install_app_dependencies php5-sqlite
fi
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
if [ "$(lsb_release --codename --short)" != "jessie" ] ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
then
systemctl reload php7.0-fpm ynh_systemd_action --service_name=php7.0-fpm --action=reload
else ynh_systemd_action --service_name=nginx --action=reload
systemctl reload php5-fpm
fi #=================================================
systemctl reload nginx # END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --time --last